/*
COPYRIGHT STATUS:
Dec 1st 2001, Fermi National Accelerator Laboratory (FNAL) documents and
software are sponsored by the U.S. Department of Energy under Contract No.
DE-AC02-76CH03000. Therefore, the U.S. Government retains a world-wide
non-exclusive, royalty-free license to publish or reproduce these documents
and software for U.S. Government purposes. All documents and software
available from this server are protected under the U.S. and Foreign
Copyright Laws, and FNAL reserves all rights.
Distribution of the software available from this server is free of
charge subject to the user following the terms of the Fermitools
Software Legal Information.
Redistribution and/or modification of the software shall be accompanied
by the Fermitools Software Legal Information (including the copyright
notice).
The user is asked to feed back problems, benefits, and/or suggestions
about the software to the Fermilab Software Providers.
Neither the name of Fermilab, the URA, nor the names of the contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
DISCLAIMER OF LIABILITY (BSD):
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FERMILAB,
OR THE URA, OR THE U.S. DEPARTMENT of ENERGY, OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Liabilities of the Government:
This software is provided by URA, independent from its Prime Contract
with the U.S. Department of Energy. URA is acting independently from
the Government and in its own private capacity and is not acting on
behalf of the U.S. Government, nor as its contractor nor its agent.
Correspondingly, it is understood and agreed that the U.S. Government
has no connection to this software and in no manner whatsoever shall
be liable for nor assume any responsibility or obligation for any claim,
cost, or damages arising out of or resulting from the use of the software
available from this server.
Export Control:
All documents and software available from this server are subject to U.S.
export control laws. Anyone downloading information from this server is
obligated to secure any necessary Government licenses before exporting
documents or software obtained from this server.
*/
// generated by GLUE/wsdl2java on Mon Jun 17 15:27:13 CDT 2002
package org.dcache.srm.client;
import eu.emi.security.authn.x509.X509Credential;
import org.apache.axis.SimpleTargetedChain;
import org.apache.axis.client.Call;
import org.apache.axis.client.Stub;
import org.apache.axis.configuration.SimpleProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.rpc.ServiceException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import org.dcache.ssl.CanlContextFactory;
import static com.google.common.net.InetAddresses.isInetAddress;
public class SRMClientV1 implements diskCacheV111.srm.ISRM {
private static final Logger logger =
LoggerFactory.getLogger(SRMClientV1.class);
private static final String SFN_STRING="?SFN=";
private static final String WEB_SERVICE_PATH="srm/managerv1";
private static final String GSS_EXPECTED_NAME="host";
private int retries;
private long retrytimeout;
private final org.dcache.srm.client.axis.ISRM_PortType axis_isrm;
private X509Credential user_cred;
private String service_url;
private String host;
static {
Call.setTransportForProtocol("http", HttpClientTransport.class);
Call.setTransportForProtocol("https", HttpClientTransport.class);
}
public static String unwrapHttpRedirection(String http_url) {
if(http_url == null || !http_url.startsWith("http://")) {
return http_url;
}
HttpURLConnection http_connection = null;
InputStream in = null;
try {
URL http_URL = new URL(http_url);
URLConnection connection = http_URL.openConnection();
connection.setDoInput(true);
connection.setDoOutput(false);
if(connection instanceof HttpURLConnection) {
http_connection = (HttpURLConnection) connection;
http_connection.setInstanceFollowRedirects(true);
in = http_connection.getInputStream(); //this force the reading of the header
URL new_url = http_connection.getURL();
return new_url.toString();
}
}
catch(IOException ioe) {
}
finally {
try {
if(in != null) {
in.close();
}
if(http_connection != null) {
http_connection.disconnect();
}
}
catch(IOException ioe) {
}
}
return http_url;
}
//this is the client that will use the axis version of the
// client underneath
public SRMClientV1(URI srmurl,
X509Credential user_cred,
long retrytimeout,
int numberofretries,
boolean do_delegation,
boolean full_delegation,
Transport transport) throws
IOException,InterruptedException,ServiceException{
this(srmurl,
user_cred,
retrytimeout,
numberofretries,
do_delegation,
full_delegation,
GSS_EXPECTED_NAME,
WEB_SERVICE_PATH,
transport);
}
public SRMClientV1(URI srmurl,
X509Credential user_cred,
long retrytimeout,
int numberofretries,
boolean do_delegation,
boolean full_delegation,
String gss_expected_name,
String webservice_path,
Transport transport) throws
IOException,InterruptedException,ServiceException{
this.retrytimeout = retrytimeout;
this.retries = numberofretries;
this.user_cred = user_cred;
if(user_cred == null) {
throw new NullPointerException("user credential is null");
}
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new IOException("credentials have expired");
}
host = srmurl.getHost();
host = InetAddress.getByName(host).getCanonicalHostName();
if (isInetAddress(host) && host.indexOf(':') != -1) {
// IPv6 without DNS record
host = "[" + host + "]";
}
int port = srmurl.getPort();
if( port == 80) {
/* FIXME: assigning the transport based on the port number is
* broken. This code is here to preserve existing behaviour.
* However, it should be removed when we can confirm no one
* is relying on this behaviour. */
transport = Transport.TCP;
}
String path = srmurl.getPath();
if(path==null) {
path="/";
}
service_url = TransportUtil.uriSchemaFor(transport) +"://"+host+":"+port;
int indx=path.indexOf(SFN_STRING);
if(indx >0) {
String service_postfix = path.substring(0,indx);
if(!service_postfix.startsWith("/")){
service_url += "/";
}
service_url += service_postfix;
}
else {
service_url += "/"+webservice_path;
}
logger.debug("SRMClientV1 calling org.globus.axis.util.Util.registerTransport() ");
SimpleProvider provider = new SimpleProvider();
GsiHttpClientSender sender = new GsiHttpClientSender();
sender.setSslContextFactory(CanlContextFactory.createDefault());
sender.init();
provider.deployTransport(HttpClientTransport.DEFAULT_TRANSPORT_NAME, new SimpleTargetedChain(sender));
org.dcache.srm.client.axis.SRMServerV1Locator sl = new org.dcache.srm.client.axis.SRMServerV1Locator(provider);
URL url = new URL(service_url);
logger.debug("connecting to srm at {}",service_url);
axis_isrm = sl.getISRM(url);
if(axis_isrm instanceof Stub) {
Stub axis_isrm_as_stub = (Stub)axis_isrm;
axis_isrm_as_stub._setProperty(HttpClientTransport.TRANSPORT_HTTP_CREDENTIALS, user_cred);
axis_isrm_as_stub._setProperty(HttpClientTransport.TRANSPORT_HTTP_DELEGATION,
TransportUtil.delegationModeFor(transport, do_delegation, full_delegation));
axis_isrm_as_stub._setProperty(Call.SESSION_MAINTAIN_PROPERTY, true);
}
else {
throw new IOException("can't set properties to the axis_isrm");
}
}
@Override
public diskCacheV111.srm.RequestStatus put( String[] sources,
String[] dests,
long[] sizes,
boolean[] wantPerm,
String[] protocols ) {
logger.debug(" put, contacting service {} ", service_url);
int i = 0;
while(true) {
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new RuntimeException("credentials have expired");
}
try {
try {
org.dcache.srm.client.axis.RequestStatus rs =
axis_isrm.put(sources, dests,
sizes, wantPerm, protocols);
return ConvertUtil.axisRS2RS(rs);
}
catch(java.rmi.RemoteException re) {
throw new RuntimeException(re);
}
}
catch(RuntimeException e) {
logger.error("put: try # {} failed with error {}",i,e.getMessage());
throw e;
}
}
}
@Override
public diskCacheV111.srm.RequestStatus get( String[] surls,String[] protocols ) {
int i = 0;
while(true) {
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new RuntimeException("credentials have expired");
}
try {
try
{
org.dcache.srm.client.axis.RequestStatus rs = axis_isrm.get(surls,protocols);
return ConvertUtil.axisRS2RS(rs);
}catch(java.rmi.RemoteException re) {
logger.debug(re.toString());
throw new RuntimeException (re.toString());
}
}
catch(RuntimeException e) {
logger.error("get : try # "+i+" failed with error "+e.getMessage());
throw e;
}
}
}
@Override
public diskCacheV111.srm.RequestStatus copy( String[] srcSURLS,
String[] destSURLS,
boolean[] wantPerm ) {
logger.debug(" copy, contacting service {} ",service_url);
int i = 0;
while(true) {
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new RuntimeException("credentials have expired");
}
try {
try
{
org.dcache.srm.client.axis.RequestStatus rs = axis_isrm.copy(srcSURLS,destSURLS,wantPerm);
return ConvertUtil.axisRS2RS(rs);
}catch(java.rmi.RemoteException re) {
throw new RuntimeException (re.toString());
}
}
catch(RuntimeException e) {
logger.error("copy: try # {} failed with error {} ",i,e.getMessage());
throw e;
}
}
}
@Override
public diskCacheV111.srm.RequestStatus getRequestStatus( int requestId ) {
int i = 0;
while(true)
{
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new RuntimeException("credentials have expired");
}
try {
try
{
org.dcache.srm.client.axis.RequestStatus rs = axis_isrm.getRequestStatus(requestId);
return ConvertUtil.axisRS2RS(rs);
}catch(java.rmi.RemoteException re) {
throw new RuntimeException (re.toString());
}
}
catch(RuntimeException e) {
logger.error("getRequestStatus: try # {} failed with error ",i,e.getMessage());
if(i <retries) {
i++;
logger.error("getRequestStatus: try again");
}
else {
throw e;
}
}
try {
long timeout = retrytimeout*i;
logger.debug("sleeping for {} milliseconds before retrying",timeout);
Thread.sleep(timeout);
}
catch(InterruptedException ie) {
}
}
}
@Override
public boolean ping() {
logger.debug(" ping, contacting service {} ",service_url);
int i = 0;
while(true) {
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new RuntimeException("credentials have expired");
}
try {
try
{
return axis_isrm.ping();
}catch(java.rmi.RemoteException re) {
throw new RuntimeException (re.toString());
}
}
catch(RuntimeException e) {
logger.error("ping: try # {} failed with error {}",i,e.getMessage());
if(i <retries) {
i++;
logger.error("ping: try again");
}
else {
throw e;
}
}
try {
long timeout = retrytimeout*i;
logger.debug("sleeping for {} milliseconds before retrying",timeout);
Thread.sleep(timeout);
}
catch(InterruptedException ie) {
}
}
}
@Override
public diskCacheV111.srm.RequestStatus mkPermanent( String[] SURLS ) {
throw new UnsupportedOperationException("Not Implemented");
}
@Override
public diskCacheV111.srm.RequestStatus pin( String[] TURLS ) {
throw new UnsupportedOperationException("Not Implemented");
}
@Override
public diskCacheV111.srm.RequestStatus unPin( String[] TURLS ,int requestID) {
throw new UnsupportedOperationException("Not Implemented");
}
@Override
public diskCacheV111.srm.RequestStatus getEstGetTime( String[] SURLS ,String[] protocols) {
throw new UnsupportedOperationException("Not Implemented");
}
@Override
public diskCacheV111.srm.RequestStatus getEstPutTime( String[] src_names,
String[] dest_names,
long[] sizes,
boolean[] wantPermanent,
String[] protocols) {
throw new UnsupportedOperationException("Not Implemented");
}
@Override
public diskCacheV111.srm.FileMetaData[] getFileMetaData( String[] SURLS ) {
if (axis_isrm == null) {
throw new NullPointerException ("both isrms are null!!!!");
}
logger.debug(" getFileMetaData, contacting service {}", service_url);
int i = 0;
while(true) {
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new RuntimeException("credentials have expired");
}
try {
try
{
org.dcache.srm.client.axis.FileMetaData[] fmd = axis_isrm.getFileMetaData(SURLS);
return ConvertUtil.axisFMDs2FMDs(fmd);
}catch(java.rmi.RemoteException re) {
throw new RuntimeException (re.toString());
}
}
catch(RuntimeException e) {
logger.error("copy: try # {} failed with error {}",i,e.getMessage());
if(i <retries) {
i++;
logger.error("copy: try again");
}
else {
throw e;
}
}
try {
long timeout = retrytimeout*i;
logger.debug("sleeping for {} milliseconds before retrying", timeout);
Thread.sleep(timeout);
}
catch(InterruptedException ie) {
}
}
}
@Override
public diskCacheV111.srm.RequestStatus setFileStatus( int requestId,
int fileId,
String state ) {
int i = 0;
while(true)
{
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new RuntimeException("credentials have expired");
}
try {
try
{
org.dcache.srm.client.axis.RequestStatus rs = axis_isrm.setFileStatus(requestId,fileId,state);
return ConvertUtil.axisRS2RS(rs);
}catch(java.rmi.RemoteException re) {
throw new RuntimeException (re.toString());
}
}
catch(RuntimeException e) {
logger.error("getRequestStatus: try # {} failed with error ",i,e.getMessage());
/*
* we do not retry in case of setFileStatus for reasons of performance
* and because the setFileStatus fails too often for Castor implementation
*
*/
throw e;
}
}
}
@Override
public void advisoryDelete( String[] SURLS) {
logger.debug(" advisoryDelete, contacting service {}",service_url);
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new RuntimeException("credentials have expired");
}
try
{
axis_isrm.advisoryDelete(SURLS);
}catch(java.rmi.RemoteException re) {
String message = re.getMessage();
if(message != null) {
throw new RuntimeException(message);
}
throw new RuntimeException (re);
}
}
@Override
public String[] getProtocols() {
logger.debug(" getProtocols, contacting service "+service_url);
int i = 0;
while(true) {
if (user_cred.getCertificate().getNotAfter().before(new Date())) {
throw new RuntimeException("credentials have expired");
}
try {
try
{
return axis_isrm.getProtocols();
}catch(java.rmi.RemoteException re) {
throw new RuntimeException (re.toString());
}
}
catch(RuntimeException e) {
logger.error("getProtocols: try # {} failed with error ",i,e.getMessage());
if(i <retries) {
i++;
logger.error("getProtocols: try again");
}
else {
throw e;
}
}
try {
long timeout = retrytimeout*i;
logger.debug("sleeping for {} milliseconds before retrying",timeout);
Thread.sleep(timeout);
}
catch(InterruptedException ie) {
}
}
}
}