You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by pa...@apache.org on 2011/10/12 06:09:20 UTC
svn commit: r1182191 - in /incubator/airavata/trunk/modules/gfac-axis2: ./
src/main/java/org/apache/airavata/services/gfac/axis2/reciever/
src/main/java/org/apache/airavata/services/gfac/axis2/util/
Author: patanachai
Date: Wed Oct 12 04:09:19 2011
New Revision: 1182191
URL: http://svn.apache.org/viewvc?rev=1182191&view=rev
Log:
Remove XSUL from GFac Axis2
Removed:
incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XMLUtil.java
incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XmlFormatter.java
Modified:
incubator/airavata/trunk/modules/gfac-axis2/pom.xml
incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java
incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSConstants.java
incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSDLUtil.java
Modified: incubator/airavata/trunk/modules/gfac-axis2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/pom.xml?rev=1182191&r1=1182190&r2=1182191&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/pom.xml (original)
+++ incubator/airavata/trunk/modules/gfac-axis2/pom.xml Wed Oct 12 04:09:19 2011
@@ -1,15 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--Licensed to the Apache Software Foundation (ASF) under one or more contributor
- license agreements. See the NOTICE file distributed with this work for additional
- information regarding copyright ownership. The ASF licenses this file to
- you under 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.apache.org/licenses/LICENSE-2.0 Unless required
- by applicable law or agreed to in writing, software distributed under the
- License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
- OF ANY ~ KIND, either express or implied. See the License for the specific
- language governing permissions and limitations under the License. -->
+<!--Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under
+ 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.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to
+ in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
+ ANY ~ KIND, either express or implied. See the License for the specific language governing permissions and limitations under
+ the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -26,22 +23,8 @@
<name>GFac-Axis2-Interface</name>
<description>Axis2 Interface to the GFac-Core</description>
-
<dependencies>
- <dependency>
- <groupId>org.apache.axis2</groupId>
- <artifactId>axis2</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.ws.commons.axiom</groupId>
- <artifactId>axiom-api</artifactId>
- <version>${axiom.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.ws.commons.axiom</groupId>
- <artifactId>axiom-impl</artifactId>
- <version>${axiom.version}</version>
- </dependency>
+ <!-- AIRAVATA MODULES DEPENDECIES -->
<dependency>
<groupId>airavata</groupId>
<artifactId>airavata-registry-api</artifactId>
@@ -57,34 +40,33 @@
<artifactId>gfac-core</artifactId>
<version>${airavata.version}</version>
</dependency>
+
+ <!-- AXIS 2 -->
+ <dependency>
+ <groupId>org.apache.axis2</groupId>
+ <artifactId>axis2-kernel</artifactId>
+ <version>${axis2.version}</version>
+ </dependency>
+
+ <!-- JCR -->
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
</dependency>
+
+ <!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+
+ <!-- For Concrete WSDL Generation -->
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
- <dependency>
- <groupId>xsul5-ogce</groupId>
- <artifactId>xsul5-2007-02-27</artifactId>
- <version>1</version>
- </dependency>
- <dependency>
- <groupId>xpp5</groupId>
- <artifactId>xpp5</artifactId>
- <version>1.2.6</version>
- </dependency>
- <dependency>
- <groupId>xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- </dependency>
-
+
</dependencies>
<build>
<plugins>
Modified: incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java?rev=1182191&r1=1182190&r2=1182191&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java (original)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/reciever/GFacMessageReciever.java Wed Oct 12 04:09:19 2011
@@ -21,7 +21,6 @@ package org.apache.airavata.services.gfa
*
*/
-import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.net.URI;
import java.util.Iterator;
@@ -67,10 +66,6 @@ import org.apache.axis2.util.MessageCont
import org.apache.axis2.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.xmlpull.v1.builder.XmlDocument;
-import org.xmlpull.v1.builder.XmlInfosetBuilder;
-
-import xsul.wsdl.WsdlDefinitions;
public class GFacMessageReciever implements MessageReceiver {
@@ -82,34 +77,34 @@ public class GFacMessageReciever impleme
GFacServiceOperations operation = GFacServiceOperations.valueFrom(axisRequestMsgCtx.getOperationContext()
.getOperationName());
switch (operation) {
- case GETABSTRACTWSDL:
- try {
- log.debug("invoking getAbstractWSDL operation");
- processgetAbstractWSDLOperation(axisRequestMsgCtx);
- log.debug("getAbstractWSDL operation invoked");
- } catch (Exception e) {
- throw new AxisFault("Error retrieving the WSDL", e);
- }
+ case GETABSTRACTWSDL:
+ try {
+ log.debug("invoking getAbstractWSDL operation");
+ processgetAbstractWSDLOperation(axisRequestMsgCtx);
+ log.debug("getAbstractWSDL operation invoked");
+ } catch (Exception e) {
+ throw new AxisFault("Error retrieving the WSDL", e);
+ }
- break;
- case INVOKE:
- try {
- log.debug("invoking Invoke operation");
- processInvokeOperation(axisRequestMsgCtx);
- log.info("Invoke operation invoked !!");
- } catch (Exception e) {
- throw new AxisFault("Error Invoking the service", e);
- }
- break;
- case GETWSDL:
- try {
- log.debug("invoking getAbstractWSDL operation");
- processgetWSDLOperation(axisRequestMsgCtx);
- log.info("getWSDL operation invoked !!");
- } catch (Exception e) {
- throw new AxisFault("Error retrieving the WSDL", e);
- }
- break;
+ break;
+ case INVOKE:
+ try {
+ log.debug("invoking Invoke operation");
+ processInvokeOperation(axisRequestMsgCtx);
+ log.info("Invoke operation invoked !!");
+ } catch (Exception e) {
+ throw new AxisFault("Error Invoking the service", e);
+ }
+ break;
+ case GETWSDL:
+ try {
+ log.debug("invoking getAbstractWSDL operation");
+ processgetWSDLOperation(axisRequestMsgCtx);
+ log.info("getWSDL operation invoked !!");
+ } catch (Exception e) {
+ throw new AxisFault("Error retrieving the WSDL", e);
+ }
+ break;
}
}
@@ -156,7 +151,7 @@ public class GFacMessageReciever impleme
/*
* Add notifiable object
*/
- WorkflowTrackingNotification workflowNotification = new WorkflowTrackingNotification(brokerURL,topic);
+ WorkflowTrackingNotification workflowNotification = new WorkflowTrackingNotification(brokerURL, topic);
LoggingNotification loggingNotification = new LoggingNotification();
DefaultInvocationContext invocationContext = new DefaultInvocationContext();
invocationContext.setExecutionContext(new DefaultExecutionContext());
@@ -164,13 +159,13 @@ public class GFacMessageReciever impleme
invocationContext.getExecutionContext().setRegistryService(getRegistry(context));
invocationContext.getExecutionContext().addNotifiable(workflowNotification);
invocationContext.getExecutionContext().addNotifiable(loggingNotification);
-
+
/*
* Add workflow context
*/
WorkflowContextImpl workflowContext = new WorkflowContextImpl();
workflowContext.setValue(WorkflowContextImpl.WORKFLOW_ID, URI.create(topic).toString());
- invocationContext.addMessageContext(WorkflowContextImpl.WORKFLOW_CONTEXT_NAME, workflowContext);
+ invocationContext.addMessageContext(WorkflowContextImpl.WORKFLOW_CONTEXT_NAME, workflowContext);
/*
* read from registry and set the correct parameters
@@ -220,8 +215,8 @@ public class GFacMessageReciever impleme
outputElement = fac.createOMElement("invokeResponse", omNs);
ParameterContextImpl paramContext = (ParameterContextImpl) invocationContext
- .<AbstractParameter>getMessageContext("output");
- for (Iterator<String> iterator = paramContext.getNames(); iterator.hasNext(); ) {
+ .<AbstractParameter> getMessageContext("output");
+ for (Iterator<String> iterator = paramContext.getNames(); iterator.hasNext();) {
String name = iterator.next();
OMElement ele = fac.createOMElement(name, omNs);
ele.addAttribute("type", paramContext.getValue(name).getType().toString(), omNs);
@@ -238,128 +233,27 @@ public class GFacMessageReciever impleme
private void processgetWSDLOperation(MessageContext messageContext) throws Exception {
MessageContext response = null;
- EndpointReference gfacUrl = messageContext.getConfigurationContext().getListenerManager()
- .getEPRforService(WSConstants.GFAC_SERVICE_NAME, WSConstants.GFAC_INVOKE_METHOD, WSConstants.GFAC_TRANSPORT);
+ EndpointReference gfacUrl = messageContext
+ .getConfigurationContext()
+ .getListenerManager()
+ .getEPRforService(WSConstants.GFAC_SERVICE_NAME, WSConstants.GFAC_INVOKE_METHOD,
+ WSConstants.GFAC_TRANSPORT);
String serviceName = getOriginalServiceName(messageContext);
String serviceEpr = gfacUrl.getAddress().split(WSConstants.GFAC_SERVICE_NAME)[0] + serviceName;
ConfigurationContext context = messageContext.getConfigurationContext();
- // TODO this logic has to change based on the logic we are storing data
- // into repository
+
try {
OMElement wsdlElement = getWSDL(context, serviceName);
- XmlInfosetBuilder xmlInfosetBuilder = xsul.XmlConstants.BUILDER;
- XmlDocument document = xmlInfosetBuilder.parseInputStream(new ByteArrayInputStream(wsdlElement.toString()
- .getBytes()));
- WsdlDefinitions definitions = new WsdlDefinitions(document.getDocumentElement());
- xsul5.wsdl.WsdlDefinitions definition5 = WSDLUtil.wsdlDefinitions3ToWsdlDefintions5(definitions);
- definition5 = xsul5.wsdl.WsdlUtil.createCWSDL(definition5, new URI(serviceEpr));
- definitions = WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(definition5);
- // WSDLReader wsdlReader =
- // WSDLFactory.newInstance().newWSDLReader();
- // ByteArrayInputStream byteArrayInputStream = new
- // ByteArrayInputStream(wsdlElement.toString().getBytes());
- // InputSource source = new InputSource(byteArrayInputStream);
- // Definition wsdlDefinition = wsdlReader.readWSDL(null, source);
- //
- //
- // Map portTypes = wsdlDefinition.getPortTypes();
- // Iterator portIt = portTypes.keySet().iterator();
- // while(portIt.hasNext()){
- // PortType portType = (PortType)portTypes.get(portIt.next());
- // List operations = portType.getOperations();
- // Iterator opIt = operations.iterator();
- // String namespace = portType.getQName().getNamespaceURI();
- //
- // Binding soap11binding = wsdlDefinition.createBinding();
- // soap11binding.setQName(new QName(namespace,serviceName +
- // "Soap11Binding"));
- // soap11binding.setPortType(portType);
- // while(opIt.hasNext()){
- // Operation operation = (Operation)opIt.next();
- // BindingOperation boperation =
- // wsdlDefinition.createBindingOperation();
- // boperation.setName(operation.getName());
- // boperation.setOperation(operation);
- // soap11binding.addBindingOperation(boperation);
- // }
- //
- // opIt = operations.iterator();
- // Binding soap12binding = wsdlDefinition.createBinding();
- // soap12binding.setQName(new QName(namespace,serviceName +
- // "Soap12Binding"));
- // soap12binding.setPortType(portType);
- // while(opIt.hasNext()){
- // Operation operation = (Operation)opIt.next();
- // BindingOperation boperation =
- // wsdlDefinition.createBindingOperation();
- // boperation.setOperation(operation);
- // BindingInput input = wsdlDefinition.createBindingInput();
- // BindingOutput outpout = wsdlDefinition.createBindingOutput();
- // ExtensibilityElement element = new UnknownExtensibilityElement();
- // element.setElementType(new
- // QName("http://schemas.xmlsoap.org/wsdl/soap12/","body"));
- // SOAP12BodyImpl body = new SOAP12BodyImpl()
- // input.addExtensibilityElement();
- // boperation.setBindingInput();
- // boperation.setName(operation.getName());
- // soap12binding.addBindingOperation(boperation);
- // }
- //
- // opIt = operations.iterator();
- // Binding httpBinding = wsdlDefinition.create;
- // httpBinding.setQName(new QName(namespace, serviceName +
- // "httpBinding"));
- // httpBinding.setPortType(portType);
- // while(opIt.hasNext()){
- // Operation operation = (Operation)opIt.next();
- // BindingOperation boperation =
- // wsdlDefinition.createBindingOperation();
- // boperation.setOperation(operation);
- // boperation.setName(operation.getName());
- // httpBinding.addBindingOperation(boperation);
- // }
- // wsdlDefinition.addBinding(soap11binding);
- // wsdlDefinition.addBinding(soap12binding);
- // wsdlDefinition.addBinding(httpBinding);
- //
- // Port soap11port = wsdlDefinition.createPort();
- // Port soap12port = wsdlDefinition.createPort();
- // Port httpPort = wsdlDefinition.createPort();
- //
- //
- // soap11port.setName(serviceName + "HttpSoap11Endpoint");
- // soap12port.setName(serviceName + "HttpSoap12Endpoint");
- // httpPort.setName(serviceName + "HttpEndpoint");
- //
- // soap11port.setBinding(soap11binding);
- // soap12port.setBinding(soap12binding);
- // httpPort.setBinding(httpBinding);
- //
- // Service service = wsdlDefinition.createService();
- // service.setQName(new QName(namespace,serviceName));
- // service.addPort(soap11port);
- // service.addPort(soap12port);
- // service.addPort(httpPort);
- //
- // wsdlDefinition.addService(service);
- // break;
- // }
- //
- // ByteArrayOutputStream out = new ByteArrayOutputStream();
- // WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
- // writer.writeWSDL(wsdlDefinition,out);
- // out.toString();
- // reader = XMLInputFactory.newInstance().createXMLStreamReader(
- // new StringReader(out.toString()));
- // builder = new StAXOMBuilder(reader);
- // wsdlElement = builder.getDocumentElement();
- // TODO based on the abstact wsdl content fill up the required
- // information using wsdl4j api
+
+ //create Concrete WSDL
+ String cWSDL = WSDLUtil.createCWSDL(wsdlElement.toString(), serviceEpr);
+
SOAPFactory sf = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope responseEnv = sf.createSOAPEnvelope();
sf.createSOAPBody(responseEnv);
-
- XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(definitions.toString()));
+
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(
+ new StringReader(cWSDL.toString()));
StAXOMBuilder builder = new StAXOMBuilder(reader);
responseEnv.getBody().addChild(builder.getDocumentElement());
response = MessageContextBuilder.createOutMessageContext(messageContext);
@@ -396,7 +290,7 @@ public class GFacMessageReciever impleme
/**
* Get Abstract WSDL and build it as OMElement
- *
+ *
* @param context
* @param serviceName
* @return
@@ -412,7 +306,7 @@ public class GFacMessageReciever impleme
/**
* Get Registry Object in the configuration context
- *
+ *
* @param context
* @return
*/
@@ -432,20 +326,24 @@ public class GFacMessageReciever impleme
private String getEventBrokerURL(MessageContext context) {
SOAPHeader header = context.getEnvelope().getHeader();
- OMElement contextHeader = header.getFirstChildWithName(new QName("http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header", "context"));
- OMElement eventSink = contextHeader.getFirstChildWithName(new QName("http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header", "event-sink-epr"));
- String address = eventSink.getFirstChildWithName(new QName("http://www.w3.org/2005/08/addressing","Address")).getText();
+ OMElement contextHeader = header.getFirstChildWithName(new QName(
+ "http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header", "context"));
+ OMElement eventSink = contextHeader.getFirstChildWithName(new QName(
+ "http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header", "event-sink-epr"));
+ String address = eventSink.getFirstChildWithName(new QName("http://www.w3.org/2005/08/addressing", "Address"))
+ .getText();
return address;
}
-
private String getTopic(MessageContext context) {
SOAPHeader header = context.getEnvelope().getHeader();
- OMElement contextHeader = header.getFirstChildWithName(new QName("http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header", "context"));
- OMElement workflowId = contextHeader.getFirstChildWithName(new QName("http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header", "workflow-instance-id"));
- String topic = workflowId.getText();
+ OMElement contextHeader = header.getFirstChildWithName(new QName(
+ "http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header", "context"));
+ OMElement workflowId = contextHeader.getFirstChildWithName(new QName(
+ "http://lead.extreme.indiana.edu/namespaces/2005/10/lead-context-header", "workflow-instance-id"));
+ String topic = workflowId.getText();
topic = topic.substring(1);
- return topic.replaceAll("_","-");
+ return topic.replaceAll("_", "-");
}
}
Modified: incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSConstants.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSConstants.java?rev=1182191&r1=1182190&r2=1182191&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSConstants.java (original)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSConstants.java Wed Oct 12 04:09:19 2011
@@ -21,155 +21,7 @@
package org.apache.airavata.services.gfac.axis2.util;
-import org.xmlpull.infoset.XmlNamespace;
-import xsul5.XmlConstants;
-
-import javax.xml.namespace.QName;
-
public interface WSConstants {
-
- /**
- * xmlns
- */
- public final static String XMLNS = "xmlns";
-
- /**
- * XML Schema prefix, xsd
- */
- public static final String XSD_NS_PREFIX = "xsd";
-
- /**
- * XML Schema URI.
- */
- public static final String XSD_NS_URI = "http://www.w3.org/2001/XMLSchema";
-
- /**
- * XML Schema Namespace
- */
- public static final XmlNamespace XSD_NS = XmlConstants.BUILDER.newNamespace(XSD_NS_PREFIX, XSD_NS_URI);
-
- /**
- * The any type.
- */
- public static final QName XSD_ANY_TYPE = new QName(XSD_NS_URI, "any", XSD_NS_PREFIX);
-
- /**
- * xsd:anyURI
- */
- public static final QName XSD_ANY_URI = new QName(XSD_NS_URI, "anyURI", XSD_NS_PREFIX);
-
- /**
- * tns
- */
- public static final String TARGET_NS_PREFIX = "tns";
-
- /**
- * typens
- */
- public static final String TYPE_NS_PREFIX = "typens";
-
- /**
- * schema
- */
- public static final String SCHEMA_TAG = "schema";
-
- /**
- * Element name for annotation, annotation
- */
- public static final String ANNOTATION_TAG = "annotation";
-
- /**
- * Element name for documentation, documentation
- */
- public static final String DOCUMENTATION_TAG = "documentation";
-
- /**
- * appinfo
- */
- public static final String APPINFO_TAG = "appinfo";
-
- /**
- * element
- */
- public static final String ELEMENT_TAG = "element";
-
- /**
- * sequence
- */
- public static final String SEQUENCE_TAG = "sequence";
-
- /**
- * complexType
- */
- public static final String COMPLEX_TYPE_TAG = "complexType";
-
- /**
- * simpleType
- */
- public static final String SIMPLE_TYPE_TAG = "simpleType";
-
- /**
- * name
- */
- public static final String NAME_ATTRIBUTE = "name";
-
- /**
- * type
- */
- public static final String TYPE_ATTRIBUTE = "type";
-
- /**
- * targetNamespace
- */
- public static final String TARGET_NAMESPACE_ATTRIBUTE = "targetNamespace";
-
- /**
- * elementFormDefault
- */
- public final static String ELEMENT_FORM_DEFAULT_ATTRIBUTE = "elementFormDefault";
-
- /**
- * unqualified
- */
- public final static String UNQUALIFIED_VALUE = "unqualified";
-
- /**
- * default
- */
- public static final String DEFAULT_ATTRIBUTE = "default";
-
- /**
- * UsingAddressing
- */
- public static final String USING_ADDRESSING_TAG = "UsingAddressing";
-
- /**
- * <appinfo xmlns="http://www.w3.org/2001/XMLSchema">
- *
- * </appinfo>
- */
- public static final String EMPTY_APPINFO = "<appinfo xmlns=\"http://www.w3.org/2001/XMLSchema\">\n\n</appinfo>";
-
- /**
- * minOccurs
- */
- public static final String MIN_OCCURS_ATTRIBUTE = "minOccurs";
-
- /**
- * maxOccurs
- */
- public static final String MAX_OCCURS_ATTRIBUTE = "maxOccurs";
-
- /**
- * unbounded
- */
- public static final String UNBOUNDED_VALUE = "unbounded";
-
- /**
- * import
- */
- public static final String IMPORT_TAG = "import";
-
/**
* schemaLocation
*/
Modified: incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSDLUtil.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSDLUtil.java?rev=1182191&r1=1182190&r2=1182191&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSDLUtil.java (original)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSDLUtil.java Wed Oct 12 04:09:19 2011
@@ -21,419 +21,172 @@
package org.apache.airavata.services.gfac.axis2.util;
-import java.io.IOException;
import java.io.StringReader;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.LinkedList;
+import java.io.StringWriter;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import javax.wsdl.Binding;
+import javax.wsdl.BindingInput;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.BindingOutput;
+import javax.wsdl.Definition;
+import javax.wsdl.Operation;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.wsdl.xml.WSDLWriter;
import javax.xml.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.xmlpull.infoset.XmlAttribute;
-import org.xmlpull.infoset.XmlBuilderException;
-import org.xmlpull.infoset.XmlElement;
-import org.xmlpull.infoset.XmlNamespace;
-
-import xsul.XmlConstants;
-import xsul5.wsdl.WsdlBinding;
-import xsul5.wsdl.WsdlDefinitions;
-import xsul5.wsdl.WsdlPortType;
-import xsul5.wsdl.WsdlPortTypeOperation;
-import xsul5.wsdl.WsdlUtil;
+import org.xml.sax.InputSource;
+
+import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
+import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
+import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;
+import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;
public class WSDLUtil {
private static final Logger logger = LoggerFactory.getLogger(WSDLUtil.class);
-
- /**
- * @param definitions3
- * @return The WsdlDefinitions (XSUL5)
- */
- public static WsdlDefinitions wsdlDefinitions3ToWsdlDefintions5(xsul.wsdl.WsdlDefinitions definitions3) {
-
- return new WsdlDefinitions(XMLUtil.xmlElement3ToXmlElement5(definitions3));
- }
-
- /**
- * @param definitions5
- * @return The WsdlDefinitions (XSUL3)
- */
- public static xsul.wsdl.WsdlDefinitions wsdlDefinitions5ToWsdlDefintions3(WsdlDefinitions definitions5) {
-
- return new xsul.wsdl.WsdlDefinitions(XMLUtil.xmlElement5ToXmlElement3(definitions5.xml()));
- }
-
- /**
- * @param definitions
- * @return The name of the WSDL.
- */
- public static String getWSDLName(WsdlDefinitions definitions) {
- String wsdlName = definitions.xml().attributeValue(WSConstants.NAME_ATTRIBUTE);
- if (wsdlName == null) {
- // name is optional.
- wsdlName = "";
- }
- return wsdlName;
- }
-
- /**
- * @param definitions
- * @return The QName of the WSDL.
- */
- public static QName getWSDLQName(WsdlDefinitions definitions) {
- String targetNamespace = definitions.getTargetNamespace();
- String wsdlName = getWSDLName(definitions);
- return new QName(targetNamespace, wsdlName);
- }
-
-
- /**
- * @param definitions
- * @return The QName of the first portType.
- * @throws Exception
- */
- public static QName getFirstPortTypeQName(WsdlDefinitions definitions) throws Exception {
- String targetNamespace = definitions.getTargetNamespace();
- for (WsdlPortType portType : definitions.portTypes()) {
- String portTypeName = portType.getName();
- QName portTypeQName = new QName(targetNamespace, portTypeName);
- return portTypeQName;
- }
- throw new Exception("No portType is defined.");
- }
-
- /**
- * @param definitions
- * @param portTypeQName
- * @return The name of the first operation in a given portType.
- * @throws Exception
- */
- public static String getFirstOperationName(WsdlDefinitions definitions, QName portTypeQName)
- throws Exception {
- WsdlPortType portType = definitions.getPortType(portTypeQName.getLocalPart());
- for (WsdlPortTypeOperation operation : portType.operations()) {
- String operationName = operation.getOperationName();
-
- // XXX Temporary solution to skip some GFac specific operations.
- if ("Shutdown".equals(operationName)) {
- continue;
- } else if ("Kill".equals(operationName)) {
- continue;
- } else if ("Ping".equals(operationName)) {
- continue;
- }
-
- return operationName;
- }
- throw new Exception("No operation is defined");
- }
-
- /**
- * @param definitions
- * @return The cloned WsdlDefinitions
- */
- public static WsdlDefinitions deepClone(WsdlDefinitions definitions)throws Exception {
- return new WsdlDefinitions(XMLUtil.deepClone(definitions.xml()));
- }
-
-
-
- private static boolean isTypeDefinedInSchema(QName paramType, XmlElement schema) {
- String schemaTargetNamespace = schema.attributeValue(WSConstants.TARGET_NAMESPACE_ATTRIBUTE);
- if (schemaTargetNamespace.equals(paramType.getNamespaceURI())) {
- for (XmlElement complexType : schema.elements(WSConstants.XSD_NS, WSConstants.COMPLEX_TYPE_TAG)) {
- String complexTypeName = complexType.attributeValue(WSConstants.NAME_ATTRIBUTE);
- if (complexTypeName.equals(paramType.getLocalPart())) {
- return true;
- }
- }
- for (XmlElement simpleType : schema.elements(WSConstants.XSD_NS, WSConstants.SIMPLE_TYPE_TAG)) {
- String simpleTypeName = simpleType.attributeValue(WSConstants.NAME_ATTRIBUTE);
- if (simpleTypeName.equals(paramType.getLocalPart())) {
- return true;
- }
- }
- }
- return false;
- }
-
-
- /**
- * @param serviceWSDL
- * @param paramType
- * @return
- */
- public static XmlElement getImportContainingTypeDefinition(WsdlDefinitions definitions, QName paramType)throws Exception {
- XmlElement types = definitions.getTypes();
- XmlElement returnType = null;
- Iterable<XmlElement> schemas = types.elements(WSConstants.XSD_NS, WSConstants.SCHEMA_TAG);
- for (XmlElement schema : schemas) {
- Iterable<XmlElement> imports = schema.elements(WSConstants.XSD_NS, WSConstants.IMPORT_TAG);
- for (XmlElement importEle : imports) {
- String schemaLocation = importEle.attributeValue(WSConstants.SCHEMA_LOCATION_ATTRIBUTE);
- if (null != schemaLocation && !"".equals(schemaLocation)) {
- try {
- // connect using a url connection
- URL url = new URL(schemaLocation);
- URLConnection connection = url.openConnection();
- connection.connect();
- XmlElement importedSchema = xsul5.XmlConstants.BUILDER.parseFragmentFromInputStream(connection
- .getInputStream());
- returnType = findTypeInSchema(paramType, importedSchema);
- if (returnType != null) {
- return importEle;
- }
-
- } catch (MalformedURLException e) {
- throw new Exception(e);
- } catch (XmlBuilderException e) {
- throw new Exception(e);
- } catch (IOException e) {
- throw new Exception(e);
- }
- }
- }
- }
- return null;
- }
-
- /**
- * @param serviceWSDL
- * @param paramType
- */
- public static XmlElement findTypeDefinitionInImports(WsdlDefinitions definitions, QName paramType)throws Exception {
- XmlElement types = definitions.getTypes();
- XmlElement returnType = null;
- Iterable<XmlElement> schemas = types.elements(null, WSConstants.SCHEMA_TAG);
- for (XmlElement schema : schemas) {
- Iterable<XmlElement> imports = schema.elements(WSConstants.XSD_NS, WSConstants.IMPORT_TAG);
- for (XmlElement importEle : imports) {
- String schemaLocation = importEle.attributeValue(WSConstants.SCHEMA_LOCATION_ATTRIBUTE);
- if (null != schemaLocation && !"".equals(schemaLocation)) {
- try {
- // connect using a url connection
- URL url = new URL(schemaLocation);
- URLConnection connection = url.openConnection();
- connection.connect();
- XmlElement importedSchema = xsul5.XmlConstants.BUILDER.parseFragmentFromInputStream(connection
- .getInputStream());
- returnType = findTypeInSchema(paramType, importedSchema);
- if (returnType != null) {
- return returnType;
- }
-
- } catch (MalformedURLException e) {
- throw new Exception(e);
- } catch (XmlBuilderException e) {
- throw new Exception(e);
- } catch (IOException e) {
- throw new Exception(e);
- }
- }
- }
- }
- return null;
-
- }
-
- private static XmlElement findTypeInSchema(QName paramType, XmlElement schema) {
- String schemaTargetNamespace = schema.attributeValue(WSConstants.TARGET_NAMESPACE_ATTRIBUTE);
- if (null != schemaTargetNamespace && schemaTargetNamespace.equals(paramType.getNamespaceURI())) {
- for (XmlElement complexType : schema.elements(WSConstants.XSD_NS, WSConstants.COMPLEX_TYPE_TAG)) {
- String complexTypeName = complexType.attributeValue(WSConstants.NAME_ATTRIBUTE);
- if (complexTypeName.equals(paramType.getLocalPart())) {
- return complexType;
-
- }
- }
- for (XmlElement simpleType : schema.elements(WSConstants.XSD_NS, WSConstants.SIMPLE_TYPE_TAG)) {
- String simpleTypeName = simpleType.attributeValue(WSConstants.NAME_ATTRIBUTE);
- if (simpleTypeName.equals(paramType.getLocalPart())) {
- return simpleType;
- }
- }
- }
- return null;
- }
-
- /**
- * @param wsdl
- * @return true if the WSDL is AWSDL; false otherwise.
- */
- public static boolean isAWSDL(WsdlDefinitions wsdl) {
- if (wsdl.services().iterator().hasNext()) {
- return false;
- }
- return true;
- }
-
- /**
- * @param definitions
- * @return true if the service supports asynchronous invocation; false otherwise;
- */
- public static boolean isAsynchronousSupported(WsdlDefinitions definitions) {
- for (WsdlBinding binding : definitions.bindings()) {
- XmlElement element = binding.xml().element(WSConstants.USING_ADDRESSING_TAG);
- if (element != null) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Converts a specified AWSDL to CWSDL using DSC URI.
- *
- * @param definitions
- * The specified AWSDL. This will be modified.
- * @param url
- * The URL of the service
- * @return The CWSDL converted.
- */
- public static WsdlDefinitions convertToCWSDL(WsdlDefinitions definitions, URI url) {
- for (WsdlPortType portType : definitions.portTypes()) {
- WsdlUtil.createCWSDL(definitions, portType, url);
- }
- return definitions;
+
+ private WSDLUtil(){
}
-
- /**
- * @param uri
- * @return The URI with "?wsdl" at the end.
- */
- public static String appendWSDLQuary(String uri) {
- URI wsdlURI = appendWSDLQuary(URI.create(uri));
- return wsdlURI.toString();
- }
-
- public static List<XmlNamespace> getNamespaces(XmlElement element) {
- LinkedList<XmlNamespace> namespaces = new LinkedList<XmlNamespace>();
- namespaces.add(element.getNamespace());
- Iterable<XmlAttribute> attributes = element.attributes();
- for (XmlAttribute xmlAttribute : attributes) {
- if (xmlAttribute.getNamespace() != null && !namespaces.contains(xmlAttribute.getNamespace())) {
- namespaces.add(xmlAttribute.getNamespace());
- }
- int index = xmlAttribute.getValue().indexOf(':');
- if (-1 != index) {
- String prefix = xmlAttribute.getValue().substring(0, index);
- if (element.lookupNamespaceByPrefix(prefix) != null) {
- namespaces.add(element.lookupNamespaceByPrefix(prefix));
- }
- }
- }
- Iterable children = element.children();
- for (Object object : children) {
- if (object instanceof XmlElement) {
- List<XmlNamespace> newNSs = getNamespaces((XmlElement) object);
- for (XmlNamespace xmlNamespace : newNSs) {
- if (!namespaces.contains(xmlNamespace)) {
- namespaces.add(xmlNamespace);
- }
- }
- }
- }
- return namespaces;
- }
-
- /**
- * @param uri
- * @return The URI with "?wsdl" at the end.
- */
- public static URI appendWSDLQuary(URI uri) {
- if (uri.toString().endsWith("?wsdl")) {
- logger.warn("URL already has ?wsdl at the end: " + uri.toString());
- // Don't throw exception to be more error tolerant.
- return uri;
- }
- String path = uri.getPath();
- if (path == null || path.length() == 0) {
- uri = uri.resolve("/");
- }
- uri = URI.create(uri.toString() + "?wsdl");
- return uri;
- }
-
-
- /**
- * @param valueElement
- * @return
- */
- public static org.xmlpull.v1.builder.XmlElement xmlElement5ToXmlElementv1(XmlElement valueElement) {
-
- return XmlConstants.BUILDER.parseFragmentFromReader(new StringReader(xsul5.XmlConstants.BUILDER
- .serializeToStringPretty(valueElement)));
- }
-
- /**
- * @param values
- */
- public static <T extends Object> T getfirst(Iterable<T> vals) {
- for (T class1 : vals) {
- return class1;
- }
- throw new RuntimeException("Iterator empty");
-
- }
-
- /**
- * @param serviceSchema
- */
- public static void print(XmlElement serviceSchema) {
- System.out.println(xsul5.XmlConstants.BUILDER.serializeToStringPretty(serviceSchema));
- }
-
- /**
- * @param workflowID
- * @return
- */
- public static String findWorkflowName(URI workflowID) {
- String[] splits = workflowID.toString().split("/");
- return splits[splits.length - 1];
-
- }
-
+
/**
+ * Generate Concrete WSDL (including <Binding> and <Service>) from an Abstract WSDL using WSDL4J.
*
- * @param element
- * @param name
- * @param oldValue
- * @param newValue
- */
- public static void replaceAttributeValue(XmlElement element, String name, String oldValue, String newValue) {
- XmlAttribute attribute = element.attribute(name);
- if (null != attribute && oldValue.equals(attribute.getValue())) {
- element.removeAttribute(attribute);
- element.setAttributeValue(name, newValue);
- }
- Iterable iterator = element.children();
- for (Object object : iterator) {
- if (object instanceof XmlElement) {
- replaceAttributeValue((XmlElement) object, name, oldValue, newValue);
- }
- }
-
- }
-
- public static boolean attributeExist(XmlElement element, String name, String value) {
- XmlAttribute attribute = element.attribute(name);
- if (null != attribute && value.equals(attribute.getValue())) {
- return true;
- }
- Iterable iterator = element.children();
- boolean ret = false;
- for (Object object : iterator) {
- if (object instanceof XmlElement) {
- ret = ret || attributeExist((XmlElement) object, name, value);
- }
- }
- return ret;
-
+ * @param Abstract WSDL
+ * @param Service end point
+ * @return Concrete WSDL
+ * @throws WSDLException
+ */
+ public static String createCWSDL(String abstractWSDL, String epr) throws WSDLException{
+
+ /*
+ * Read to Definition
+ */
+ WSDLFactory factory = WSDLFactory.newInstance();
+ WSDLReader wsdlreader = factory.newWSDLReader();
+ InputSource source = new InputSource(new StringReader(abstractWSDL));
+ Definition wsdlDefinition = wsdlreader.readWSDL(null, source);
+
+ Map portTypes = wsdlDefinition.getPortTypes();
+ Iterator portIt = portTypes.keySet().iterator();
+ while (portIt.hasNext()) {
+ QName key = (QName)portIt.next();
+ PortType portType = (PortType) portTypes.get(key);
+ String portTypeName = key.getLocalPart();
+ List operations = portType.getOperations();
+ Iterator opIt = operations.iterator();
+ String namespace = portType.getQName().getNamespaceURI();
+
+
+ /*
+ * Create WSDL Binding
+ */
+ Binding binding = wsdlDefinition.createBinding();
+ binding.setQName(new QName(namespace, portTypeName + "SoapBinding"));
+ binding.setPortType(portType);
+ binding.setUndefined(false);
+
+ /*
+ * Create SOAPBinding for WSDL Binding
+ */
+ SOAPBinding soapbinding = new SOAPBindingImpl();
+ soapbinding.setTransportURI("http://schemas.xmlsoap.org/soap/http");
+ soapbinding.setStyle("document");
+ binding.addExtensibilityElement(soapbinding);
+
+ while (opIt.hasNext()) {
+ Operation operation = (Operation) opIt.next();
+
+ /*
+ * For each operation in portType, Create BindingOperation
+ */
+ BindingOperation boperation = wsdlDefinition.createBindingOperation();
+ boperation.setName(operation.getName());
+ boperation.setOperation(operation);
+
+ BindingInput input = wsdlDefinition.createBindingInput();
+ BindingOutput outpout = wsdlDefinition.createBindingOutput();
+
+ SOAPBodyImpl soapBodyIn = new SOAPBodyImpl();
+ soapBodyIn.setUse("literal");
+
+ SOAPBodyImpl soapBodyOut = new SOAPBodyImpl();
+ soapBodyOut.setUse("literal");
+
+ input.addExtensibilityElement(soapBodyIn);
+ outpout.addExtensibilityElement(soapBodyOut);
+
+ /*
+ * Create SOAP Operation for BindingOperation
+ */
+ SOAPOperation soapoperation = new SOAPOperationImpl();
+ soapoperation.setSoapActionURI(namespace + "invoke");
+ soapoperation.setStyle("document");
+
+ boperation.setBindingInput(input);
+ boperation.setBindingOutput(outpout);
+ boperation.addExtensibilityElement(soapoperation);
+
+ /*
+ * Add BindingOperation to Binding
+ */
+ binding.addBindingOperation(boperation);
+ }
+
+ /*
+ * Add Binding to WSDL
+ */
+ wsdlDefinition.addBinding(binding);
+
+ /*
+ * Create Service for each Binding
+ */
+ Service service = wsdlDefinition.createService();
+ service.setQName(new QName(namespace, portTypeName + "Service"));
+
+ /*
+ * Create Port for service
+ */
+ Port soapport = wsdlDefinition.createPort();
+ soapport.setName(portTypeName + "SoapPort");
+ soapport.setBinding(binding);
+ /*
+ * Set Address for SOAP Port
+ */
+ SOAPAddress address = new SOAPAddressImpl();
+ address.setLocationURI(epr);
+
+ soapport.addExtensibilityElement(address);
+
+ //add Port
+ service.addPort(soapport);
+
+ /*
+ * Add Service to WSDL
+ */
+ wsdlDefinition.addService(service);
+ }
+
+ /*
+ * Write to String
+ */
+ StringWriter out = new StringWriter();
+ WSDLWriter writer = WSDLFactory.newInstance().newWSDLWriter();
+ writer.writeWSDL(wsdlDefinition, out);
+
+ return out.toString();
}
}
\ No newline at end of file