All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.fedora.client.APIMStubFactory Maven / Gradle / Ivy

Go to download

The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.

The newest version!
/*
 * -----------------------------------------------------------------------------
 *
 * 

License and Copyright: The contents of this file are subject to the * Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of * the License at * http://www.fedora-commons.org/licenses.

* *

Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific language governing rights and limitations under the License.

* *

The entire file consists of original code.

*

Copyright © 2008 Fedora Commons, Inc.
*

Copyright © 2002-2007 The Rector and Visitors of the University of * Virginia and Cornell University
* All rights reserved.

* * ----------------------------------------------------------------------------- */ package fedora.client; import java.net.URL; import java.net.MalformedURLException; import javax.xml.rpc.ServiceException; import fedora.server.management.FedoraAPIM; import fedora.server.management.FedoraAPIMServiceLocator; /** * *

Title: APIMStubFactory.java

*

Description:

* * * @author [email protected] * @version $Id: APIMStubFactory.java 5245 2006-11-28 11:35:02Z eddie $ */ public abstract class APIMStubFactory { public static int SOCKET_TIMEOUT_SECONDS = 120; /** * Method to rewrite the default API-M base URL (specified in the service * locator class FedoraAPIMServiceLocator). In this case we allow the protocol, * host, and port parts of the service URL to be replaced. A SOAP stub * will be returned with the desired service endpoint URL. * @param protocol * @param host * @param port * @param username * @param password * @return FedoraAPIM SOAP stub * @throws MalformedURLException * @throws ServiceException */ public static FedoraAPIM getStub(String protocol, String host, int port, String username, String password) throws MalformedURLException, ServiceException { FedoraAPIMServiceLocator locator=new FedoraAPIMServiceLocator(username, password, SOCKET_TIMEOUT_SECONDS); //SDP - HTTPS support added URL ourl = null; URL nurl = null; if (protocol.equalsIgnoreCase("http")) { ourl=new URL(locator.getFedoraAPIMPortSOAPHTTPAddress()); nurl=rewriteServiceURL(ourl, protocol, host, port, null); if (Administrator.INSTANCE==null) { // if running without Administrator, don't wrap it with the statusbar stuff return locator.getFedoraAPIMPortSOAPHTTP(nurl); } else { return new APIMStubWrapper(locator.getFedoraAPIMPortSOAPHTTP(nurl)); } } else if (protocol.equalsIgnoreCase("https")){ ourl=new URL(locator.getFedoraAPIMPortSOAPHTTPSAddress()); nurl=rewriteServiceURL(ourl, protocol, host, port, null); if (Administrator.INSTANCE==null) { // if running without Administrator, don't wrap it with the statusbar stuff return locator.getFedoraAPIMPortSOAPHTTPS(nurl); } else { return new APIMStubWrapper(locator.getFedoraAPIMPortSOAPHTTPS(nurl)); } } else { throw new javax.xml.rpc.ServiceException("The protocol" + " " + protocol + " is not supported by this service."); } } /** * Method to rewrite the default API-M base URL (specified in the service * locator class FedoraAPIMServiceLocator). In this case we allow the protocol, * host, port, and PATH parts of the service URL to be replaced. A SOAP stub * will be returned with the desired service endpoint URL. * @param protocol * @param host * @param port * @param path * @param username * @param password * @return FedoraAPIM SOAP stub * @throws MalformedURLException * @throws ServiceException */ public static FedoraAPIM getStubAltPath(String protocol, String host, int port, String path, String username, String password) throws MalformedURLException, ServiceException { FedoraAPIMServiceLocator locator=new FedoraAPIMServiceLocator(username, password, SOCKET_TIMEOUT_SECONDS); //SDP - HTTPS support added URL ourl = null; URL nurl = null; if (protocol.equalsIgnoreCase("http")) { ourl=new URL(locator.getFedoraAPIMPortSOAPHTTPAddress()); nurl=rewriteServiceURL(ourl, protocol, host, port, path); if (Administrator.INSTANCE==null) { // if running without Administrator, don't wrap it with the statusbar stuff return locator.getFedoraAPIMPortSOAPHTTP(nurl); } else { return new APIMStubWrapper(locator.getFedoraAPIMPortSOAPHTTP(nurl)); } } else if (protocol.equalsIgnoreCase("https")){ ourl=new URL(locator.getFedoraAPIMPortSOAPHTTPSAddress()); nurl=rewriteServiceURL(ourl, protocol, host, port, path); if (Administrator.INSTANCE==null) { // if running without Administrator, don't wrap it with the statusbar stuff return locator.getFedoraAPIMPortSOAPHTTPS(nurl); } else { return new APIMStubWrapper(locator.getFedoraAPIMPortSOAPHTTPS(nurl)); } } else { throw new javax.xml.rpc.ServiceException("The protocol" + " " + protocol + " is not supported by this service."); } } private static URL rewriteServiceURL(URL ourl, String protocol, String host, int port, String path) throws MalformedURLException, ServiceException { StringBuffer nurl=new StringBuffer(); if (protocol.equalsIgnoreCase("http")) { nurl.append("http://"); } else if (protocol.equalsIgnoreCase("https")){ nurl.append("https://"); } else { throw new javax.xml.rpc.ServiceException("The protocol" + " " + protocol + " is not supported by this service."); } nurl.append(host); nurl.append(':'); nurl.append(port); // Use the path, query, and fragment from the original URL // Otherwise, if an alternate path is provided, use it to complete the service URL if (path==null || path.equals("")) { nurl.append(ourl.getPath()); if ((ourl.getQuery()!=null) && (!ourl.getQuery().equals("")) ) { nurl.append('?'); nurl.append(ourl.getQuery()); } if ((ourl.getRef()!=null) && (!ourl.getRef().equals("")) ) { nurl.append('#'); nurl.append(ourl.getRef()); } } else { path=path.trim(); if (!path.startsWith("/")){ path="/" + path; } nurl.append(path); } return new URL(nurl.toString()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy