Author: kurtstam
Date: 2010-03-22 17:41:15 -0400 (Mon, 22 Mar 2010)
New Revision: 584
Added:
trunk/runtime/uddi/src/test/
trunk/runtime/uddi/src/test/java/
trunk/runtime/uddi/src/test/java/org/
trunk/runtime/uddi/src/test/java/org/jboss/
trunk/runtime/uddi/src/test/java/org/jboss/soa/
trunk/runtime/uddi/src/test/java/org/jboss/soa/bpel/
trunk/runtime/uddi/src/test/java/org/jboss/soa/bpel/uddi/
trunk/runtime/uddi/src/test/java/org/jboss/soa/bpel/uddi/UDDIRegistrationTest.java
trunk/runtime/uddi300/src/test/
Modified:
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/engine/ode/JAXWSBindingContext.java
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/engine/ode/UDDIRegistration.java
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/EndpointManager.java
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WSDLReference.java
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceClient.java
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceProviderFactory.java
trunk/runtime/uddi/
trunk/runtime/uddi/pom.xml
trunk/runtime/uddi/src/main/java/org/jboss/soa/bpel/uddi/UDDIRegistrationImpl.java
trunk/runtime/uddi300/
trunk/runtime/uddi300/pom.xml
trunk/runtime/uddi300/src/main/java/org/jboss/soa/bpel/uddi300/UDDI300RegistrationImpl.java
Log:
RIFTSAW-158, Deploytime lookup of partnerChannel WSDL Endpoints
Modified:
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/engine/ode/JAXWSBindingContext.java
===================================================================
---
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/engine/ode/JAXWSBindingContext.java 2010-03-22
17:59:37 UTC (rev 583)
+++
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/engine/ode/JAXWSBindingContext.java 2010-03-22
21:41:15 UTC (rev 584)
@@ -21,9 +21,10 @@
import org.apache.commons.logging.LogFactory;
import org.apache.ode.bpel.iapi.*;
import org.jboss.soa.bpel.runtime.engine.PartnerChannel;
+import org.jboss.soa.bpel.runtime.integration.ServerConfigFactory;
import org.jboss.soa.bpel.runtime.ws.*;
-import org.jboss.soa.bpel.runtime.*;
+
import javax.wsdl.Definition;
import javax.wsdl.PortType;
import javax.wsdl.factory.WSDLFactory;
@@ -43,13 +44,37 @@
public class JAXWSBindingContext implements BindingContext
{
protected final Log log = LogFactory.getLog(getClass());
+//we should consider having our own OdeConfigProperties class if we need more properties
+ public final static String BPEL_UDDI_LOOKUP = "uddi.lookup";
+ public final static String BPEL_WEBSERVICE_SECURE = "webservice.secure";
+ public final static String BPEL_WEBSERVICE_BASEURL = "webservice.baseurl";
private BPELEngineImpl engine;
private EndpointManager endpointManager;
+ private UDDIRegistration uddiRegistration = null;
public JAXWSBindingContext(BPELEngineImpl server) {
this.engine = server;
this.endpointManager = new EndpointManager(this.engine);
+ if (isUDDILookup()) {
+ try {
+ String webServiceHost = ServerConfigFactory.getServerConfig().getWebServiceHost();
+ int webServicePort = ServerConfigFactory.getServerConfig().getWebServicePort();
+ URL url = new URL("http://" + webServiceHost + ":" +
webServicePort);
+ if (isWebserviceSecure()) {
+ int secureWebServicePort =
ServerConfigFactory.getServerConfig().getWebServicePort();
+ url = new URL("https://" + webServiceHost + ":" +
secureWebServicePort);
+ }
+ //give the user the option to override
+ if (server.getOdeConfig().getProperty(BPEL_WEBSERVICE_BASEURL)==null) {
+ server.getOdeConfig().getProperties().setProperty(BPEL_WEBSERVICE_BASEURL,
url.toExternalForm());
+ }
+ uddiRegistration =
UDDIClientFactory.newInstance(server.getOdeConfig().getProperties());
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ log.error("Continuing without UDDI integration.");
+ }
+ }
}
public org.apache.ode.bpel.iapi.EndpointReference getEndpoint(QName serviceName, String
portName) {
@@ -101,7 +126,7 @@
{
File targetWSDLFile = findWSDLFile(processId, myRoleEndpoint);
Definition wsdlDefinition = getWSDLDefinition(processId,
myRoleEndpoint.serviceName);
- return new WSDLReference(wsdlDefinition, targetWSDLFile);
+ return new WSDLReference(wsdlDefinition, targetWSDLFile.toURI());
}
private File findWSDLFile(QName processId, Endpoint myRoleEndpoint)
@@ -169,9 +194,25 @@
public PartnerRoleChannel createPartnerRoleChannel(QName processId, PortType portType,
Endpoint initialPartnerEndpoint) {
// NOTE: This implementation assumes that the initial value of the
- // partner role determines the binding.
- WSDLReference wsdlReference = createWSDLReference(processId,
initialPartnerEndpoint);
-
+ // partner role determines the binding.
+ Definition wsdlDefinition = null;
+ URL wsdlUrl = null;
+ if (isUDDILookup()) {
+ WSDLReference wsdlReference = uddiRegistration.lookupWSDL(
+ initialPartnerEndpoint.serviceName,
+ initialPartnerEndpoint.portName);
+ if (wsdlReference!=null) {
+ wsdlDefinition = wsdlReference.getDefinition();
+ wsdlUrl = wsdlReference.getWsdlURL();
+ }
+ }
+ if (isUDDILookup()==false || wsdlUrl==null) {
+ WSDLReference wsdlReference = createWSDLReference(processId,
initialPartnerEndpoint);
+ wsdlDefinition = wsdlReference.getDefinition();
+ wsdlUrl = wsdlReference.getWsdlURL();
+ }
+
+
// TODO: TEAM_ODE:
// 1) try to obtain EPR from wsdl, associated with service and port name - see
createExternalService
// code below for possible use of ProcessConf to get external service WSDL
@@ -188,7 +229,7 @@
try
{
- PartnerChannel channel = endpointManager.createClient(endpointMD, wsdlReference);
+ PartnerChannel channel = endpointManager.createClient(endpointMD, wsdlDefinition,
wsdlUrl);
return new PartnerRoleChannelImpl(channel);
}
@@ -214,5 +255,13 @@
// TODO Auto-generated method stub
return 0;
}
+
+ public boolean isUDDILookup() {
+ return Boolean.valueOf(engine.getOdeConfig().getProperty(BPEL_UDDI_LOOKUP,
"false"));
+ }
+
+ public boolean isWebserviceSecure() {
+ return Boolean.valueOf(engine.getOdeConfig().getProperty(BPEL_WEBSERVICE_SECURE,
"false"));
+ }
}
Modified:
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/engine/ode/UDDIRegistration.java
===================================================================
---
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/engine/ode/UDDIRegistration.java 2010-03-22
17:59:37 UTC (rev 583)
+++
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/engine/ode/UDDIRegistration.java 2010-03-22
21:41:15 UTC (rev 584)
@@ -43,9 +43,14 @@
public void registerEPR(EndpointMetaData metaData, WSDLReference wsdlRef);
/**
* UnRegisters the binding from the UDDI Registry.
- * @param EPR
- * @param metaData
- * @param wsdlRef
+ * @param QName of the service
+ * @param port name
*/
public void unRegisterEPR(QName service, String port);
+ /**
+ *
+ * @param service
+ * @param port
+ */
+ public WSDLReference lookupWSDL(QName serviceQName, String portName);
}
Modified:
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/EndpointManager.java
===================================================================
---
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/EndpointManager.java 2010-03-22
17:59:37 UTC (rev 583)
+++
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/EndpointManager.java 2010-03-22
21:41:15 UTC (rev 584)
@@ -43,6 +43,7 @@
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
+import javax.wsdl.Definition;
import javax.xml.namespace.QName;
import java.io.File;
import java.io.IOException;
@@ -96,7 +97,7 @@
// create deployment structure (maybe replaced by shrinkwrap)
File warArchive = new DeploymentBuilder(serverConfig)
.setEndpoint(metaData.getEndpointId())
- .setWSDL(wsdlRef.getWsdlFile())
+ .setWSDL(new File(wsdlRef.getWsdlURL().toURI()))
.build();
//Deployment deployment = createInMemoryDeployment(endpointId);
@@ -289,13 +290,13 @@
}
public WebServiceClient createClient(
- EndpointMetaData metaData,WSDLReference wsdlRef)
+ EndpointMetaData metaData,Definition wsdlDefinition, URL wsdlUrl)
throws EndpointManagementException
{
try
{
WebServiceClient client =
- new WebServiceClient(metaData, wsdlRef, executionEnvironment);
+ new WebServiceClient(metaData, wsdlDefinition, wsdlUrl, executionEnvironment);
return client;
Modified:
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WSDLReference.java
===================================================================
---
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WSDLReference.java 2010-03-22
17:59:37 UTC (rev 583)
+++
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WSDLReference.java 2010-03-22
21:41:15 UTC (rev 584)
@@ -22,7 +22,7 @@
package org.jboss.soa.bpel.runtime.ws;
import javax.wsdl.Definition;
-import java.io.File;
+import java.net.URI;
import java.net.URL;
import java.net.MalformedURLException;
@@ -33,16 +33,18 @@
* @see org.jboss.soa.bpel.runtime.ws.EndpointManager
*
* @author Heiko.Braun <heiko.braun(a)jboss.com>
+ * @author Kurt.Stam <kurt.stam(a)jboss.com>
+ *
*/
public final class WSDLReference
{
private Definition definition;
- private File wsdlFile;
+ private URI wsdlURI;
- public WSDLReference(Definition definition, File wsdlFile)
+ public WSDLReference(Definition definition, URI wsdlURI)
{
this.definition = definition;
- this.wsdlFile = wsdlFile;
+ this.wsdlURI = wsdlURI;
}
public Definition getDefinition()
@@ -50,16 +52,11 @@
return definition;
}
- public File getWsdlFile()
+ public URL getWsdlURL()
{
- return wsdlFile;
- }
-
- public URL getWsdlFileURL()
- {
try
{
- return getWsdlFile().toURL();
+ return wsdlURI.toURL();
}
catch (MalformedURLException e)
{
Modified:
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceClient.java
===================================================================
---
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceClient.java 2010-03-22
17:59:37 UTC (rev 583)
+++
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceClient.java 2010-03-22
21:41:15 UTC (rev 584)
@@ -75,12 +75,12 @@
private ExecutionEnvironment executionEnvironment;
- public WebServiceClient(EndpointMetaData metaData, WSDLReference wsdlRef,
ExecutionEnvironment env)
+ public WebServiceClient(EndpointMetaData metaData, Definition wsdlDefintion, URL
wsdlUrl , ExecutionEnvironment env)
{
this.executionEnvironment = env;
this.metaData = metaData;
- this.wsdlDefintion = wsdlRef.getDefinition();
- this.wsdlUrl = wsdlRef.getWsdlFileURL();
+ this.wsdlDefintion = wsdlDefintion;
+ this.wsdlUrl = wsdlUrl;
this.id = metaData.getEndpointId();
this.serviceName = metaData.getServiceName();
Modified:
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceProviderFactory.java
===================================================================
---
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceProviderFactory.java 2010-03-22
17:59:37 UTC (rev 583)
+++
trunk/runtime/engine/src/main/java/org/jboss/soa/bpel/runtime/ws/WebServiceProviderFactory.java 2010-03-22
21:41:15 UTC (rev 584)
@@ -84,7 +84,7 @@
// AbstractWebServiceEndpoint.wsdlLocation property
CtField wsdlLocationField = new CtField(stringType, "wsdlLocation", impl);
wsdlLocationField.setModifiers(Modifier.PUBLIC);
- impl.addField(wsdlLocationField,
"\""+wsdlRef.getWsdlFileURL().toExternalForm()+"\"");
+ impl.addField(wsdlLocationField,
"\""+wsdlRef.getWsdlURL().toExternalForm()+"\"");
// AbstractWebServiceEndpoint.portName property
CtField portNameField = new CtField(stringType, "portName", impl);
@@ -126,7 +126,7 @@
);
providerAnnotation.addMemberValue(
"wsdlLocation",
- new StringMemberValue(wsdlRef.getWsdlFileURL().toExternalForm(), constantPool)
+ new StringMemberValue(wsdlRef.getWsdlURL().toExternalForm(), constantPool)
);
attr.addAnnotation(providerAnnotation);
Property changes on: trunk/runtime/uddi
___________________________________________________________________
Name: svn:ignore
- target
+ target
.settings
.classpath
.project
Modified: trunk/runtime/uddi/pom.xml
===================================================================
--- trunk/runtime/uddi/pom.xml 2010-03-22 17:59:37 UTC (rev 583)
+++ trunk/runtime/uddi/pom.xml 2010-03-22 21:41:15 UTC (rev 584)
@@ -35,6 +35,12 @@
<version>${riftsaw.engine.version}</version>
</dependency>
+ <dependency>
+ <groupId>wsdl4j</groupId>
+ <artifactId>wsdl4j</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
Modified:
trunk/runtime/uddi/src/main/java/org/jboss/soa/bpel/uddi/UDDIRegistrationImpl.java
===================================================================
---
trunk/runtime/uddi/src/main/java/org/jboss/soa/bpel/uddi/UDDIRegistrationImpl.java 2010-03-22
17:59:37 UTC (rev 583)
+++
trunk/runtime/uddi/src/main/java/org/jboss/soa/bpel/uddi/UDDIRegistrationImpl.java 2010-03-22
21:41:15 UTC (rev 584)
@@ -21,10 +21,21 @@
*/
package org.jboss.soa.bpel.uddi;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.rmi.RemoteException;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
import org.apache.commons.configuration.ConfigurationException;
@@ -37,6 +48,7 @@
import org.apache.juddi.v3.client.config.UDDIClerkManager;
import org.apache.juddi.v3.client.config.UDDIClientContainer;
import org.apache.juddi.v3.client.transport.TransportException;
+import org.jboss.soa.bpel.runtime.engine.ode.JAXWSBindingContext;
import org.jboss.soa.bpel.runtime.engine.ode.UDDIRegistration;
import org.jboss.soa.bpel.runtime.ws.EndpointMetaData;
import org.jboss.soa.bpel.runtime.ws.WSDLReference;
@@ -46,7 +58,12 @@
import org.uddi.api_v3.BusinessService;
import org.uddi.api_v3.CategoryBag;
import org.uddi.api_v3.Description;
+import org.uddi.api_v3.FindQualifiers;
+import org.uddi.api_v3.FindService;
+import org.uddi.api_v3.GetAuthToken;
import org.uddi.api_v3.Name;
+import org.uddi.api_v3.ServiceInfo;
+import org.uddi.api_v3.ServiceList;
import org.uddi.api_v3.TModelInstanceDetails;
import org.uddi.api_v3.TModelInstanceInfo;
import org.uddi.v3_service.DispositionReportFaultMessage;
@@ -65,6 +82,7 @@
private final static String DEFAULT_BPEL_UDDI_CLERK_MANAGER = "esb.manager";
private final static String DEFAULT_BPEL_UDDI_CLERK = "BPELClerk";
private Properties properties = new Properties();
+ UDDIClerk bpelClerk = null;
public static final String DEFAULT_SERVICE_KEY_FORMAT =
"uddi:${keyDomain}:bpel-services-";
public static final String DEFAULT_BINDING_KEY_FORMAT =
"uddi:${keyDomain}:bindings-";
@@ -116,6 +134,22 @@
private String getClerkName() {
return (properties.getProperty(BPEL_UDDI_CLERK, DEFAULT_BPEL_UDDI_CLERK));
}
+
+ private String getWebserviceBaseUrl() {
+ return (properties.getProperty(JAXWSBindingContext.BPEL_WEBSERVICE_BASEURL,
"http://localhost:8080"));
+ }
+
+ private UDDIClerk getBPELClerk() throws ConfigurationException {
+ if (bpelClerk==null) {
+ UDDIClerkManager clerkManager =
UDDIClientContainer.getUDDIClerkManager(getClerkManagerName());
+ Map<String,UDDIClerk> clerks = clerkManager.getClientConfig().getUDDIClerks();
+ UDDIClerk bpelClerk = clerks.get(getClerkName());
+ if (bpelClerk==null) {
+ throw new ConfigurationException("Could not find UDDI Clerk named "+
getClerkName());
+ }
+ }
+ return bpelClerk;
+ }
/**
* Registers a BPEL ServiceEndpointReference (EPR) into a UDDI registry using the jUDDI
client code.
@@ -287,7 +321,13 @@
AccessPoint accessPoint = new AccessPoint();
accessPoint.setUseType(AccessPointType.WSDL_DEPLOYMENT.toString());
- accessPoint.setValue(wsdlRef.getWsdlFileURL().toString());
+ URL accessUrl = wsdlRef.getWsdlURL();
+ try {
+ accessUrl = rewriteWSDLURL(wsdlRef.getWsdlURL());
+ } catch (MalformedURLException e) {
+ log.error(e.getMessage(),e);
+ }
+ accessPoint.setValue(accessUrl.toExternalForm());
bindingTemplate.setAccessPoint(accessPoint);
//default tModelKeys on the binding
@@ -314,6 +354,143 @@
return bindingTemplate;
}
+ /**
+ * Looks up the WSDL for the requested service and portName. The BPELClerk
+ * is used to lookup the service in the UDDI Registry by ServiceName. For
+ * each Service, it will loop over the BindingTemplates. If a BindingTemplate
+ * is found containing an AccessPointType of "wsdlDeployment" then this
+ * URL is used to obtain the WSDL. If successful the WSDLReference is returned,
+ * if not successful the next bindingTemplate is tried. A null result will be
+ * returned if none of the attempts are successful.
+ */
+ public WSDLReference lookupWSDL(QName serviceQName, String portName) {
+
+ try {
+ UDDIClerk bpelClerk = getBPELClerk();
+ FindService findService = new FindService();
+ findService.setAuthInfo(getAuthToken(bpelClerk));
+ Name serviceName = new Name();
+
+ String lang = "en";
+ if (properties.containsKey(LANG)) lang = properties.getProperty(LANG);
+ serviceName.setLang(lang);
+ serviceName.setValue(serviceQName.getLocalPart());
+ findService.getName().add(serviceName);
+
+ FindQualifiers findQualifiers = new FindQualifiers();
+ findQualifiers.getFindQualifier().add("exactMatch");
+ findService.setFindQualifiers(findQualifiers);
+
+ ServiceList serviceList =
bpelClerk.getUDDINode().getTransport().getUDDIInquiryService().findService(findService);
+ //Loop over all services found.
+ if (serviceList.getServiceInfos()!=null) {
+ List<ServiceInfo> serviceInfos =
serviceList.getServiceInfos().getServiceInfo();
+ for (ServiceInfo serviceInfo : serviceInfos) {
+ String serviceKey = serviceInfo.getServiceKey();
+ log.info("Found service " + serviceQName.getLocalPart()
+ + " with serviceKey '" + serviceInfo.getServiceKey() +
"'");
+ BusinessService service = bpelClerk.findService(serviceKey,
bpelClerk.getUDDINode().getApiNode());
+ BindingTemplates bindingservices = service.getBindingTemplates();
+ //Loop over all bindingTemplates found
+ for (BindingTemplate bindingTemplate : bindingservices.getBindingTemplate()) {
+ AccessPoint accessPoint = bindingTemplate.getAccessPoint();
+ if (AccessPointType.WSDL_DEPLOYMENT.toString().equals(accessPoint.getUseType())) {
+ URL url = null;
+ try {
+ url = new URL(accessPoint.getValue());
+ log.info("wsdlUrl for service " + serviceQName.getLocalPart() +
" is " + url);
+ WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
+ Definition def = wsdlReader.readWSDL(url.toExternalForm());
+ if (log.isDebugEnabled()) {
+ log.debug(getWSDL(url));
+ }
+ //Checking if this WSDL contains the right port name.
+ Port port = def.getService(serviceQName).getPort(portName);
+ if (port!=null) {
+ //Current policy: "FirstSuccess" :)
+ return new WSDLReference(def, url.toURI());
+ } else {
+ log.info("PortName " + portName + " could not be found in
WSDL");
+ }
+ } catch (Exception e) {
+ log.warn("Unable to obtain WSDL from " + url + ". " +
e.getMessage(),e);
+ }
+ } else {
+ log.debug("This accessPoint is of type " + accessPoint.getUseType() +
" only "
+ + AccessPointType.WSDL_DEPLOYMENT + " is supported at the
moment.");
+ }
+ }
+ }
+ } else {
+ log.info("No Service by the name " + serviceQName.getLocalPart() + "
was found in the registry.");
+ }
+
+ } catch (Exception e) {
+ log.error(e.getMessage(),e);
+ }
+ log.info("No WSDL could be obtained using the UDDI Registry Lookup.");
+ return null;
+ }
+ /**
+ * Obtains an authToken for this clerk.
+ *
+ * @param clerk
+ * @return
+ * @throws TransportException
+ * @throws DispositionReportFaultMessage
+ * @throws RemoteException
+ */
+ private String getAuthToken(UDDIClerk clerk) throws TransportException,
DispositionReportFaultMessage, RemoteException {
+
+ String endpointURL = clerk.getUDDINode().getApiNode().getSecurityUrl();
+ GetAuthToken getAuthToken = new GetAuthToken();
+ getAuthToken.setUserID(clerk.getPublisher());
+ getAuthToken.setCred(clerk.getPassword());
+ String authToken =
clerk.getUDDINode().getTransport().getUDDISecurityService(endpointURL).getAuthToken(getAuthToken).getAuthInfo();
+
+ return authToken;
+ }
+ /**
+ * Reads the WSDL from an endpoint URL and returns it in a formatted String.
+ *
+ * @param url - url of a WSDL Endpoint.
+ * @return - Formatted WSDL
+ * @throws IOException when there are IO issues reading the WSDL content from the url.
+ */
+ private String getWSDL(URL url) throws IOException {
+
+ BufferedInputStream inputStream = (BufferedInputStream) url.getContent();
+ BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
+ StringBuffer buffer = new StringBuffer();
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ buffer.append(inputLine).append("\r\n");
+ }
+ in.close();
+ return buffer.toString();
+ }
+ /**
+ * file:/Users/kstam/apps/jboss-5.1.0.GA/riftesb-4.7/
+ * server/default/tmp/5c4o1j-2geosb-g71xfu32-1-g71xxyiq-bt/
+ * BPEL_BluePrint1-1.jar/InventoryService.wsdl
+ *
+ * to
+ *
+ *
http://localhost:8080/BPEL_BluePrint1_InventoryService?wsdl
+ *
+ * @param urlIn
+ * @return
+ * @throws MalformedURLException
+ */
+ public URL rewriteWSDLURL(URL urlIn) throws MalformedURLException {
+
+ String[] path=urlIn.toExternalForm().split("/");
+ String wsdlElement = path[path.length-1].replace(".wsdl", "?wsdl");
//InventoryService.wsdl
+ String serviceName =
path[path.length-2].substring(0,path[path.length-2].lastIndexOf("-"));
+ String urlString = getWebserviceBaseUrl() + "/" + serviceName + "_"
+ wsdlElement;
+ URL outUrl = new URL(urlString);
+ return outUrl;
+ }
}
Added: trunk/runtime/uddi/src/test/java/org/jboss/soa/bpel/uddi/UDDIRegistrationTest.java
===================================================================
--- trunk/runtime/uddi/src/test/java/org/jboss/soa/bpel/uddi/UDDIRegistrationTest.java
(rev 0)
+++
trunk/runtime/uddi/src/test/java/org/jboss/soa/bpel/uddi/UDDIRegistrationTest.java 2010-03-22
21:41:15 UTC (rev 584)
@@ -0,0 +1,23 @@
+package org.jboss.soa.bpel.uddi;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.jboss.soa.bpel.uddi.UDDIRegistrationImpl;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+
+public class UDDIRegistrationTest extends TestCase {
+
+ public void testUrlRewrite() throws MalformedURLException {
+ String inUrl =
"file:/Users/kstam/apps/jboss-5.1.0.GA/riftesb-4.7/server/default/tmp/5c4o1j-2geosb-g71xfu32-1-g71xxyiq-bt/BPEL_BluePrint1-1.jar/InventoryService.wsdl";
+ String expectedUrl =
"http://localhost:8080/BPEL_BluePrint1_InventoryService?wsdl";
+ UDDIRegistrationImpl registration = new UDDIRegistrationImpl(new Properties());
+ String actualUrl = registration.rewriteWSDLURL(new URL(inUrl)).toExternalForm();
+ Assert.assertEquals(expectedUrl, actualUrl.toString());
+ }
+
+}
Property changes on: trunk/runtime/uddi300
___________________________________________________________________
Name: svn:ignore
- target
+ target
.settings
.classpath
.project
Modified: trunk/runtime/uddi300/pom.xml
===================================================================
--- trunk/runtime/uddi300/pom.xml 2010-03-22 17:59:37 UTC (rev 583)
+++ trunk/runtime/uddi300/pom.xml 2010-03-22 21:41:15 UTC (rev 584)
@@ -35,6 +35,12 @@
<version>${riftsaw.engine.version}</version>
</dependency>
+ <dependency>
+ <groupId>wsdl4j</groupId>
+ <artifactId>wsdl4j</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
Modified:
trunk/runtime/uddi300/src/main/java/org/jboss/soa/bpel/uddi300/UDDI300RegistrationImpl.java
===================================================================
---
trunk/runtime/uddi300/src/main/java/org/jboss/soa/bpel/uddi300/UDDI300RegistrationImpl.java 2010-03-22
17:59:37 UTC (rev 583)
+++
trunk/runtime/uddi300/src/main/java/org/jboss/soa/bpel/uddi300/UDDI300RegistrationImpl.java 2010-03-22
21:41:15 UTC (rev 584)
@@ -21,10 +21,21 @@
*/
package org.jboss.soa.bpel.uddi300;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.rmi.RemoteException;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
import org.apache.commons.configuration.ConfigurationException;
@@ -36,6 +47,7 @@
import org.apache.juddi.v3.client.config.UDDIClerk;
import org.apache.juddi.v3.client.config.UDDIClerkManager;
import org.apache.juddi.v3.client.transport.TransportException;
+import org.jboss.soa.bpel.runtime.engine.ode.JAXWSBindingContext;
import org.jboss.soa.bpel.runtime.engine.ode.UDDIRegistration;
import org.jboss.soa.bpel.runtime.ws.EndpointMetaData;
import org.jboss.soa.bpel.runtime.ws.WSDLReference;
@@ -45,7 +57,12 @@
import org.uddi.api_v3.BusinessService;
import org.uddi.api_v3.CategoryBag;
import org.uddi.api_v3.Description;
+import org.uddi.api_v3.FindQualifiers;
+import org.uddi.api_v3.FindService;
+import org.uddi.api_v3.GetAuthToken;
import org.uddi.api_v3.Name;
+import org.uddi.api_v3.ServiceInfo;
+import org.uddi.api_v3.ServiceList;
import org.uddi.api_v3.TModelInstanceDetails;
import org.uddi.api_v3.TModelInstanceInfo;
import org.uddi.v3_service.DispositionReportFaultMessage;
@@ -58,8 +75,8 @@
public class UDDI300RegistrationImpl extends AnnotationProcessor implements
UDDIRegistration {
protected static final Log log = LogFactory.getLog(UDDI300RegistrationImpl.class);
- @SuppressWarnings("unused")
private Properties properties = new Properties();
+ private UDDIClerk bpelClerk = null;
private final static String BPEL_UDDI_CLERK = "bpel.uddi.clerk";
private final static String DEFAULT_BPEL_UDDI_CLERK = "BPELClerk";
public static final String DEFAULT_SERVICE_KEY_FORMAT =
"uddi:${keyDomain}:bpel-services-";
@@ -82,6 +99,21 @@
private String getClerkName() {
return (properties.getProperty(BPEL_UDDI_CLERK, DEFAULT_BPEL_UDDI_CLERK));
}
+
+ private String getWebserviceBaseUrl() {
+ return (properties.getProperty(JAXWSBindingContext.BPEL_WEBSERVICE_BASEURL,
"http://localhost:8080"));
+ }
+
+ private UDDIClerk getBPELClerk() throws ConfigurationException {
+ if (bpelClerk==null) {
+ Map<String,UDDIClerk> clerks =
UDDIClerkManager.getClientConfig().getUDDIClerks();
+ bpelClerk = clerks.get(getClerkName());
+ if (bpelClerk==null) {
+ throw new ConfigurationException("Could not find UDDI Clerk named "+
getClerkName());
+ }
+ }
+ return bpelClerk;
+ }
/**
* Registers a BPEL ServiceEndpointReference (EPR) into a UDDI registry using the jUDDI
client code.
* If the serviceKey does not already exist we register the service along with the EPR.
@@ -95,21 +127,16 @@
try {
selfRegister = UDDIClerkManager.getClientConfig().isRegisterOnStartup();
if (selfRegister) {
- Map<String,UDDIClerk> clerks =
UDDIClerkManager.getClientConfig().getUDDIClerks();
- UDDIClerk bpelClerk = clerks.get(getClerkName());
- if (bpelClerk!=null) {
- try {
- BusinessService service = createBusinessService(bpelClerk, metaData, wsdlRef);
- bpelClerk.register(service, bpelClerk.getUDDINode().getApiNode());
- } catch (Exception e) {
- log.error("Unable to register service " + metaData.getServiceName()
- + " ." + e.getMessage(),e);
- } catch (Throwable t) {
- log.error("Unable to register service " + metaData.getServiceName()
- + " ." + t.getMessage(),t);
- }
- } else {
- throw new ConfigurationException("Could not find UDDI Clerk named "+
getClerkName());
+ UDDIClerk bpelClerk = getBPELClerk();
+ try {
+ BusinessService service = createBusinessService(bpelClerk, metaData, wsdlRef);
+ bpelClerk.register(service, bpelClerk.getUDDINode().getApiNode());
+ } catch (Exception e) {
+ log.error("Unable to register service " + metaData.getServiceName()
+ + " ." + e.getMessage(),e);
+ } catch (Throwable t) {
+ log.error("Unable to register service " + metaData.getServiceName()
+ + " ." + t.getMessage(),t);
}
}
} catch (ConfigurationException ce) {
@@ -250,7 +277,13 @@
AccessPoint accessPoint = new AccessPoint();
accessPoint.setUseType(AccessPointType.WSDL_DEPLOYMENT.toString());
- accessPoint.setValue(wsdlRef.getWsdlFileURL().toString());
+ URL accessUrl = wsdlRef.getWsdlURL();
+ try {
+ accessUrl = rewriteWSDLURL(wsdlRef.getWsdlURL());
+ } catch (MalformedURLException e) {
+ log.error(e.getMessage(),e);
+ }
+ accessPoint.setValue(accessUrl.toExternalForm());
bindingTemplate.setAccessPoint(accessPoint);
//default tModelKeys on the binding
@@ -276,7 +309,142 @@
return bindingTemplate;
}
+ /**
+ * Looks up the WSDL for the requested service and portName. The BPELClerk
+ * is used to lookup the service in the UDDI Registry by ServiceName. For
+ * each Service, it will loop over the BindingTemplates. If a BindingTemplate
+ * is found containing an AccessPointType of "wsdlDeployment" then this
+ * URL is used to obtain the WSDL. If successful the WSDLReference is returned,
+ * if not successful the next bindingTemplate is tried. A null result will be
+ * returned if none of the attempts are successful.
+ */
+ public WSDLReference lookupWSDL(QName serviceQName, String portName) {
+
+ try {
+ UDDIClerk bpelClerk = getBPELClerk();
+ FindService findService = new FindService();
+ findService.setAuthInfo(getAuthToken(bpelClerk));
+ Name serviceName = new Name();
+
+ String lang = "en";
+ if (properties.containsKey(LANG)) lang = properties.getProperty(LANG);
+ serviceName.setLang(lang);
+ serviceName.setValue(serviceQName.getLocalPart());
+ findService.getName().add(serviceName);
+
+ FindQualifiers findQualifiers = new FindQualifiers();
+ findQualifiers.getFindQualifier().add("exactMatch");
+ findService.setFindQualifiers(findQualifiers);
+
+ ServiceList serviceList =
bpelClerk.getUDDINode().getTransport().getUDDIInquiryService().findService(findService);
+ //Loop over all services found.
+ if (serviceList.getServiceInfos()!=null) {
+ List<ServiceInfo> serviceInfos =
serviceList.getServiceInfos().getServiceInfo();
+ for (ServiceInfo serviceInfo : serviceInfos) {
+ String serviceKey = serviceInfo.getServiceKey();
+ log.info("Found service " + serviceQName.getLocalPart()
+ + " with serviceKey '" + serviceInfo.getServiceKey() +
"'");
+ BusinessService service = bpelClerk.findService(serviceKey,
bpelClerk.getUDDINode().getApiNode());
+ BindingTemplates bindingservices = service.getBindingTemplates();
+ //Loop over all bindingTemplates found
+ for (BindingTemplate bindingTemplate : bindingservices.getBindingTemplate()) {
+ AccessPoint accessPoint = bindingTemplate.getAccessPoint();
+ if (AccessPointType.WSDL_DEPLOYMENT.toString().equals(accessPoint.getUseType())) {
+ URL url = null;
+ try {
+ url = new URL(accessPoint.getValue());
+ log.info("wsdlUrl for service " + serviceQName.getLocalPart() +
" is " + url);
+ WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
+ Definition def = wsdlReader.readWSDL(url.toExternalForm());
+ if (log.isDebugEnabled()) {
+ log.debug(getWSDL(url));
+ }
+ //Checking if this WSDL contains the right port name.
+ Port port = def.getService(serviceQName).getPort(portName);
+ if (port!=null) {
+ //Current policy: "FirstSuccess" :)
+ return new WSDLReference(def, url.toURI());
+ } else {
+ log.info("PortName " + portName + " could not be found in
WSDL");
+ }
+ } catch (Exception e) {
+ log.warn("Unable to obtain WSDL from " + url + ". " +
e.getMessage(),e);
+ }
+ } else {
+ log.debug("This accessPoint is of type " + accessPoint.getUseType() +
" only "
+ + AccessPointType.WSDL_DEPLOYMENT + " is supported at the
moment.");
+ }
+ }
+ }
+ } else {
+ log.info("No Service by the name " + serviceQName.getLocalPart() + "
was found in the registry.");
+ }
+
+ } catch (Exception e) {
+ log.error(e.getMessage(),e);
+ }
+ log.info("No WSDL could be obtained using the UDDI Registry Lookup.");
+ return null;
+ }
+ /**
+ * Obtains an authToken for this clerk.
+ *
+ * @param clerk
+ * @return
+ * @throws TransportException
+ * @throws DispositionReportFaultMessage
+ * @throws RemoteException
+ */
+ private String getAuthToken(UDDIClerk clerk) throws TransportException,
DispositionReportFaultMessage, RemoteException {
+
+ String endpointURL = clerk.getUDDINode().getApiNode().getSecurityUrl();
+ GetAuthToken getAuthToken = new GetAuthToken();
+ getAuthToken.setUserID(clerk.getPublisher());
+ getAuthToken.setCred(clerk.getPassword());
+ String authToken =
clerk.getUDDINode().getTransport().getUDDISecurityService(endpointURL).getAuthToken(getAuthToken).getAuthInfo();
+
+ return authToken;
+ }
+ /**
+ * Reads the WSDL from an endpoint URL and returns it in a formatted String.
+ *
+ * @param url - url of a WSDL Endpoint.
+ * @return - Formatted WSDL
+ * @throws IOException when there are IO issues reading the WSDL content from the url.
+ */
+ private String getWSDL(URL url) throws IOException {
+
+ BufferedInputStream inputStream = (BufferedInputStream) url.getContent();
+ BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
+ StringBuffer buffer = new StringBuffer();
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ buffer.append(inputLine).append("\r\n");
+ }
+ in.close();
+ return buffer.toString();
+ }
-
-
+ /**
+ * file:/Users/kstam/apps/jboss-5.1.0.GA/riftesb-4.7/
+ * server/default/tmp/5c4o1j-2geosb-g71xfu32-1-g71xxyiq-bt/
+ * BPEL_BluePrint1-1.jar/InventoryService.wsdl
+ *
+ * to
+ *
+ *
http://localhost:8080/BPEL_BluePrint1_InventoryService?wsdl
+ *
+ * @param urlIn
+ * @return
+ * @throws MalformedURLException
+ */
+ public URL rewriteWSDLURL(URL urlIn) throws MalformedURLException {
+
+ String[] path=urlIn.toExternalForm().split("/");
+ String wsdlElement = path[path.length-1].replace(".wsdl", "?wsdl");
//InventoryService.wsdl
+ String serviceName =
path[path.length-2].substring(0,path[path.length-2].lastIndexOf("-"));
+ String urlString = getWebserviceBaseUrl() + "/" + serviceName + "_"
+ wsdlElement;
+ URL outUrl = new URL(urlString);
+ return outUrl;
+ }
}