You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by al...@apache.org on 2013/05/11 03:00:09 UTC
svn commit: r1481244 - in /juddi/trunk/juddi-client: ./
src/main/java/org/apache/juddi/v3/client/mapping/
src/test/java/org/apache/juddi/v3/client/mapping/
Author: alexoree
Date: Sat May 11 01:00:09 2013
New Revision: 1481244
URL: http://svn.apache.org/r1481244
Log:
Adding support for authenticated WSDL2UDDI imports, additional API documentation
additional client dependency on apache http commons
Modified:
juddi/trunk/juddi-client/pom.xml
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/ReadWSDL.java
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDL2UDDI.java
juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDLLocatorImpl.java
juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/ReadWSDLTest.java
Modified: juddi/trunk/juddi-client/pom.xml
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/pom.xml?rev=1481244&r1=1481243&r2=1481244&view=diff
==============================================================================
--- juddi/trunk/juddi-client/pom.xml (original)
+++ juddi/trunk/juddi-client/pom.xml Sat May 11 01:00:09 2013
@@ -51,5 +51,10 @@
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.2.5</version>
+ </dependency>
</dependencies>
</project>
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/ReadWSDL.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/ReadWSDL.java?rev=1481244&r1=1481243&r2=1481244&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/ReadWSDL.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/ReadWSDL.java Sat May 11 01:00:09 2013
@@ -31,14 +31,16 @@ import org.apache.juddi.v3.client.ClassU
import com.ibm.wsdl.factory.WSDLFactoryImpl;
/**
+ * A WSDL parser/reader
* @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
+ * Modified for support http based credentials by Alex O'Ree
*/
public class ReadWSDL {
private final Log log = LogFactory.getLog(this.getClass());
public Definition readWSDL(String fileName) throws WSDLException {
-
+
Definition wsdlDefinition = null;
WSDLFactory factory = WSDLFactoryImpl.newInstance();
WSDLReader reader = factory.newWSDLReader();
@@ -53,8 +55,18 @@ public class ReadWSDL {
return wsdlDefinition;
}
- public Definition readWSDL(URL wsdlUrl) throws WSDLException {
-
+ /**
+ * Reads a WSDL file, assumes that credentials are required. This is useful for when the WSDL document itself
+ * is protected by HTTP based authentication mechanisms
+ * @param wsdlUrl
+ * @param username
+ * @param password
+ * @param domain
+ * @return a Definition object representing the WSDL
+ * @throws WSDLException
+ */
+ public Definition readWSDL(URL wsdlUrl, String username, String password, String domain) throws WSDLException {
+
Definition wsdlDefinition = null;
WSDLFactory factory = WSDLFactoryImpl.newInstance();
WSDLReader reader = factory.newWSDLReader();
@@ -67,6 +79,16 @@ public class ReadWSDL {
}
return wsdlDefinition;
}
+ /**
+ * Reads a WSDL file, assumes that credentials are not required. This is a convenience wrapper for
+ * readWSDL(URL wsdlUrl, null, null, null)
+ * @param wsdlUrl
+ * @return a Definition object representing the WSDL
+ * @throws WSDLException
+ */
+ public Definition readWSDL(URL wsdlUrl) throws WSDLException {
+ return readWSDL(wsdlUrl, null, null, null);
+ }
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDL2UDDI.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDL2UDDI.java?rev=1481244&r1=1481243&r2=1481244&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDL2UDDI.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDL2UDDI.java Sat May 11 01:00:09 2013
@@ -80,7 +80,7 @@ import org.w3c.dom.Element;
* </ul>
*
* @author Kurt T Stam
- *
+ * @Since 3.1.5
*/
public class WSDL2UDDI {
@@ -484,12 +484,12 @@ public class WSDL2UDDI {
<p>The tModel MUST contain an overviewDoc with an overviewURL containing the location
of the WSDL document that describes the wsdl:portType.</p>
- * @param wsdlURL
+ * @param wsdlURL This is used to set the Overview URL
* @param portType Map
* @return set of WSDL PortType tModels
* @throws WSDLException
*/
- protected Set<TModel> createWSDLPortTypeTModels(String wsdlURL, Map<QName,PortType> portTypes) throws WSDLException
+ public Set<TModel> createWSDLPortTypeTModels(String wsdlURL, Map<QName,PortType> portTypes) throws WSDLException
{
Set<TModel> tModels = new HashSet<TModel>();
// Create a tModel for each portType
@@ -627,7 +627,7 @@ public class WSDL2UDDI {
return service;
}
- protected BusinessServices createBusinessServices(Definition wsdlDefinition) {
+ public BusinessServices createBusinessServices(Definition wsdlDefinition) {
BusinessServices businessServices = new BusinessServices();
for (Object serviceName : wsdlDefinition.getAllServices().keySet()) {
QName serviceQName = (QName) serviceName;
Modified: juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDLLocatorImpl.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDLLocatorImpl.java?rev=1481244&r1=1481243&r2=1481244&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDLLocatorImpl.java (original)
+++ juddi/trunk/juddi-client/src/main/java/org/apache/juddi/v3/client/mapping/WSDLLocatorImpl.java Sat May 11 01:00:09 2013
@@ -19,6 +19,7 @@ package org.apache.juddi.v3.client.mappi
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
import java.net.URI;
import java.net.URL;
@@ -26,117 +27,205 @@ import javax.wsdl.xml.WSDLLocator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.DefaultHttpClient;
import org.xml.sax.InputSource;
/**
- * Implementation of the interface {@link WSDLLocatorImpl}.
- *
- * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
+ * Implementation of the interface {@link WSDLLocatorImpl}.
*
+ * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a> Modified for
+ * support http based credentials by Alex O'Ree
*/
public class WSDLLocatorImpl implements WSDLLocator {
- private final Log log = LogFactory.getLog(this.getClass());
- private InputStream inputStream = null;
- private URI baseURI;
- private String latestImportURI;
- /**
- * Constructor taking the URI to the WSDL. This class implements the {@link WSDLLocatorImpl}
- * Interface.
- *
- * @param baseURI - URI of the WSDL
- */
- public WSDLLocatorImpl(URI baseURI) {
- this.baseURI = baseURI;
- }
- /**
- * @see WSDLLocatorImpl.getBaseInputSource
- */
- public InputSource getBaseInputSource() {
- InputSource inputSource = null;
- try {
- inputStream = baseURI.toURL().openStream();
- inputSource =new InputSource(inputStream);
- } catch (IOException e) {
- log.error(e.getMessage(),e);
- }
- return inputSource;
- }
- /**
- * Internal method to normalize the importUrl. The importLocation can be relative to
- * the parentLocation.
- *
- * @param parentLocation
- * @param importLocation
- * @return
- */
- protected URL constructImportUrl(String parentLocation, String importLocation) {
- URL importUrl = null;
- try {
- URI importLocationURI = new URI(importLocation);
- if (importLocationURI.getScheme()!=null || parentLocation==null) {
- importUrl = importLocationURI.toURL();
- } else {
- String parentDir = parentLocation.substring(0, parentLocation.lastIndexOf("/"));
- URI uri = new URI(parentDir + "/" + importLocation);
- importUrl = uri.normalize().toURL();
- }
- } catch (Exception e) {
- log.error(e.getMessage(),e);
- }
- if (importUrl != null)
- log.debug("importUrl: " + importUrl.toExternalForm());
- else
- log.error("importUrl is null!");
- return importUrl;
- }
-
- /**
- * @see WSDLLocatorImpl.getImportInputSource
- */
- public InputSource getImportInputSource(String parentLocation, String importLocation)
- {
- InputSource inputSource = null;
- try {
- URL importUrl = constructImportUrl(parentLocation, importLocation);
- InputStream inputStream = importUrl.openStream();
- inputSource = new InputSource(inputStream);
- latestImportURI = importUrl.toExternalForm();
- } catch (Exception e) {
- log.error(e.getMessage(),e);
- }
- return inputSource;
- }
- /**
- * @see WSDLLocatorImpl.getBaseURI
- */
- public String getBaseURI() {
- String baseURIStr = null;
- try {
- baseURIStr = baseURI.toURL().toExternalForm();
- } catch (IOException e) {
- log.error(e.getMessage(),e);
- }
- return baseURIStr;
- }
- /**
- * @see WSDLLocatorImpl.getLatestImportURI
- */
- public String getLatestImportURI() {
- return latestImportURI;
- }
- /**
- * @see WSDLLocatorImpl.close
- */
- public void close() {
- if (inputStream!=null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- log.error(e.getMessage(),e);
- }
- }
- }
-
+ private final Log log = LogFactory.getLog(this.getClass());
+ private InputStream inputStream = null;
+ private URI baseURI;
+ private String latestImportURI;
+ private String username = null, password = null, domain = null;
+
+ /**
+ * Constructor taking the URI to the WSDL. This class implements the
+ * {@link WSDLLocatorImpl} Interface.
+ *
+ * @param baseURI - URI of the WSDL
+ */
+ public WSDLLocatorImpl(URI baseURI) {
+ this.baseURI = baseURI;
+ }
+
+ /**
+ * Constructor taking the URI to the WSDL. This class implements the
+ * {@link WSDLLocatorImpl} Interface and includes support for HTTP
+ * Authentication
+ *
+ * @param baseURI
+ * @param username
+ * @param password
+ * @param domain
+ */
+ public WSDLLocatorImpl(URI baseURI, String username, String password, String domain) {
+ this.baseURI = baseURI;
+ this.username = username;
+ this.password = password;
+ this.domain = domain;
+ }
+
+ /**
+ * @see WSDLLocatorImpl.getBaseInputSource
+ */
+ public InputSource getBaseInputSource() {
+ return getImportFromUrl(baseURI.toString());
+ }
+
+ /**
+ * Internal method to normalize the importUrl. The importLocation can be
+ * relative to the parentLocation.
+ *
+ * @param parentLocation
+ * @param importLocation
+ * @return
+ */
+ protected URL constructImportUrl(String parentLocation, String importLocation) {
+ URL importUrl = null;
+ try {
+ URI importLocationURI = new URI(importLocation);
+ if (importLocationURI.getScheme() != null || parentLocation == null) {
+ importUrl = importLocationURI.toURL();
+ } else {
+ String parentDir = parentLocation.substring(0, parentLocation.lastIndexOf("/"));
+ URI uri = new URI(parentDir + "/" + importLocation);
+ importUrl = uri.normalize().toURL();
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ if (importUrl != null) {
+ log.debug("importUrl: " + importUrl.toExternalForm());
+ } else {
+ log.error("importUrl is null!");
+ }
+ return importUrl;
+ }
+
+ private InputSource getImportFromUrl(String url) {
+ InputSource inputSource = null;
+ DefaultHttpClient httpclient = new DefaultHttpClient();
+ try {
+ URL url2 = new URL(url);
+ if (!url.toLowerCase().startsWith("http")) {
+ return getImportFromFile(url);
+ }
+
+ if (username != null && username.length() > 0
+ && password != null && password.length() > 0) {
+ int port = 80;
+ if (url.toLowerCase().startsWith("https://")) {
+ port = 443;
+ }
+
+ if (url2.getPort() > 0) {
+ port = url2.getPort();
+ }
+
+ httpclient.getCredentialsProvider().setCredentials(
+ new AuthScope(url2.getHost(), port),
+ new UsernamePasswordCredentials(username, password));
+ }
+ HttpGet httpGet = new HttpGet(url);
+ try {
+
+ HttpResponse response1 = httpclient.execute(httpGet);
+ //System.out.println(response1.getStatusLine());
+ // HttpEntity entity1 = response1.getEntity();
+ // do something useful with the response body
+ // and ensure it is fully consumed
+ ResponseHandler<String> responseHandler = new BasicResponseHandler();
+ String handleResponse = responseHandler.handleResponse(response1);
+ StringReader sr = new StringReader(handleResponse);
+ inputSource = new InputSource(sr);
+
+
+ } finally {
+ httpGet.releaseConnection();
+
+ }
+
+ // InputStream inputStream = importUrl.openStream();
+ //inputSource = new InputSource(inputStream);
+ latestImportURI = url;
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ } finally {
+ httpclient.getConnectionManager().shutdown();
+ }
+ return inputSource;
+ }
+
+ /**
+ * @see WSDLLocatorImpl.getImportInputSource
+ */
+ public InputSource getImportInputSource(String parentLocation, String importLocation) {
+ InputSource inputSource = null;
+ try {
+ URL importUrl = constructImportUrl(parentLocation, importLocation);
+ return getImportFromUrl(importUrl.toExternalForm());
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return inputSource;
+ }
+
+ /**
+ * @see WSDLLocatorImpl.getBaseURI
+ */
+ public String getBaseURI() {
+ String baseURIStr = null;
+ try {
+ baseURIStr = baseURI.toURL().toExternalForm();
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+ return baseURIStr;
+ }
+
+ /**
+ * @see WSDLLocatorImpl.getLatestImportURI
+ */
+ public String getLatestImportURI() {
+ return latestImportURI;
+ }
+
+ /**
+ * @see WSDLLocatorImpl.close
+ */
+ public void close() {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ private InputSource getImportFromFile(String url) {
+ InputSource inputSource = null;
+ try {
+ URL importUrl = new URL(url);
+ inputStream = importUrl.openStream();
+ inputSource = new InputSource(inputStream);
+ latestImportURI = importUrl.toExternalForm();
+ } catch (Exception e) {
+ log.error(e.getMessage(), e);
+ }
+ return inputSource;
+ }
}
-
Modified: juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/ReadWSDLTest.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/ReadWSDLTest.java?rev=1481244&r1=1481243&r2=1481244&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/ReadWSDLTest.java (original)
+++ juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/ReadWSDLTest.java Sat May 11 01:00:09 2013
@@ -14,7 +14,9 @@
*/
package org.apache.juddi.v3.client.mapping;
+import java.net.MalformedURLException;
import java.net.URISyntaxException;
+import java.net.URL;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
@@ -27,20 +29,27 @@ import org.junit.Test;
*/
public class ReadWSDLTest {
- @Test
- public void readFromFile() throws WSDLException, URISyntaxException {
-
- ReadWSDL readWSDL = new ReadWSDL();
- Definition definition = readWSDL.readWSDL("wsdl/HelloWorld.wsdl");
- Assert.assertNotNull(definition);
- }
-
- @Test
- public void readFromJar() throws WSDLException, URISyntaxException {
-
- ReadWSDL readWSDL = new ReadWSDL();
- Definition definition = readWSDL.readWSDL("uddi_v3_service.wsdl");
- Assert.assertNotNull(definition);
- }
-
+ @Test
+ public void readFromFile() throws WSDLException, URISyntaxException {
+
+ ReadWSDL readWSDL = new ReadWSDL();
+ Definition definition = readWSDL.readWSDL("wsdl/HelloWorld.wsdl");
+ Assert.assertNotNull(definition);
+ }
+
+ @Test
+ public void readFromURL() throws WSDLException, URISyntaxException, MalformedURLException {
+
+ ReadWSDL readWSDL = new ReadWSDL();
+ Definition definition = readWSDL.readWSDL(new URL("http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php?wsdl"));
+ Assert.assertNotNull(definition);
+ }
+
+ @Test
+ public void readFromJar() throws WSDLException, URISyntaxException {
+
+ ReadWSDL readWSDL = new ReadWSDL();
+ Definition definition = readWSDL.readWSDL("uddi_v3_service.wsdl");
+ Assert.assertNotNull(definition);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@juddi.apache.org
For additional commands, e-mail: commits-help@juddi.apache.org