You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2011/09/08 17:24:15 UTC
svn commit: r1166743 - 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/
src/main/resources/
Author: lahiru
Date: Thu Sep 8 15:24:14 2011
New Revision: 1166743
URL: http://svn.apache.org/viewvc?rev=1166743&view=rev
Log:
committing the feature of getting concrete wsdl from an abstract wsdl.
Added:
incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/
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
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/resources/services.xml
Modified: incubator/airavata/trunk/modules/gfac-axis2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/pom.xml?rev=1166743&r1=1166742&r2=1166743&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/pom.xml (original)
+++ incubator/airavata/trunk/modules/gfac-axis2/pom.xml Thu Sep 8 15:24:14 2011
@@ -19,6 +19,17 @@
<version>0.0.1-SNAPSHOT</version>
<name>GFac-Axis2-Interface</name>
<description>Axis2 Interface to the GFac-Core</description>
+
+ <repositories>
+ <repository>
+ <name>ogce.m2.all</name>
+ <id>ogce.m2.all</id>
+ <url>http://community.ucs.indiana.edu:9090/archiva/repository/ogce.m2.all</url>
+ <snapshots>
+ <updatePolicy>daily</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
<properties>
<org.slf4j.version>1.6.1</org.slf4j.version>
<log4j.version>1.2.16</log4j.version>
@@ -56,7 +67,16 @@
<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>
</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=1166743&r1=1166742&r2=1166743&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 Thu Sep 8 15:24:14 2011
@@ -23,6 +23,7 @@ package org.apache.airavata.services.gfa
import java.io.ByteArrayInputStream;
import java.io.StringReader;
+import java.net.URI;
import java.util.Iterator;
import java.util.List;
@@ -47,6 +48,7 @@ import org.apache.airavata.core.gfac.con
import org.apache.airavata.core.gfac.factory.PropertyServiceFactory;
import org.apache.airavata.core.gfac.notification.impl.LoggingNotification;
import org.apache.airavata.core.gfac.services.GenericService;
+import org.apache.airavata.services.gfac.axis2.util.WSDLUtil;
import org.apache.airavata.services.gfac.axis2.utils.GFacServiceOperations;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
@@ -56,6 +58,7 @@ import org.apache.axiom.om.impl.builder.
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.AxisEngine;
@@ -66,6 +69,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.InputSource;
+import org.xmlpull.v1.builder.XmlDocument;
+import org.xmlpull.v1.builder.XmlInfosetBuilder;
+import org.xmlpull.v1.builder.impl.XmlInfosetBuilderImpl;
+import xsul.wsdl.WsdlDefinitions;
+import xsul5.XmlConstants;
+
public class GFacMessageReciever implements MessageReceiver {
private static final Log log = LogFactory.getLog(GFacMessageReciever.class);
@@ -76,30 +85,30 @@ public class GFacMessageReciever impleme
GFacServiceOperations operation = GFacServiceOperations.valueFrom(axisRequestMsgCtx.getOperationContext()
.getOperationName());
switch (operation) {
- case GETABSTRACTWSDL:
- try {
- processgetAbstractWSDLOperation(axisRequestMsgCtx);
- } catch (Exception e) {
- throw new AxisFault("Error retrieving the WSDL", e);
- }
- log.info("getAbstractWSDL operation invoked !!");
- break;
- case INVOKE:
- try {
- processInvokeOperation(axisRequestMsgCtx);
- log.info("Invoke operation invoked !!");
- } catch (Exception e) {
- throw new AxisFault("Error Invoking the service", e);
- }
- break;
- case GETWSDL:
- try {
- processgetWSDLOperation(axisRequestMsgCtx);
- } catch (Exception e) {
- throw new AxisFault("Error retrieving the WSDL", e);
- }
- log.info("getWSDL operation invoked !!");
- break;
+ case GETABSTRACTWSDL:
+ try {
+ processgetAbstractWSDLOperation(axisRequestMsgCtx);
+ } catch (Exception e) {
+ throw new AxisFault("Error retrieving the WSDL", e);
+ }
+ log.info("getAbstractWSDL operation invoked !!");
+ break;
+ case INVOKE:
+ try {
+ processInvokeOperation(axisRequestMsgCtx);
+ log.info("Invoke operation invoked !!");
+ } catch (Exception e) {
+ throw new AxisFault("Error Invoking the service", e);
+ }
+ break;
+ case GETWSDL:
+ try {
+ processgetWSDLOperation(axisRequestMsgCtx);
+ } catch (Exception e) {
+ throw new AxisFault("Error retrieving the WSDL", e);
+ }
+ log.info("getWSDL operation invoked !!");
+ break;
}
}
@@ -108,25 +117,25 @@ public class GFacMessageReciever impleme
String serviceName = getOriginalServiceName(messageContext);
try {
ConfigurationContext context = messageContext.getConfigurationContext();
-
+
/*
- * We assume that input likes
- * <invoke>
- * <input_param_name1>value</input_param_name1>
- * <input_param_name2>value</input_param_name2>
- * <input_param_name3>value</input_param_name3>
- * </invoke>
- */
+ * We assume that input likes
+ * <invoke>
+ * <input_param_name1>value</input_param_name1>
+ * <input_param_name2>value</input_param_name2>
+ * <input_param_name3>value</input_param_name3>
+ * </invoke>
+ */
OMElement invoke = messageContext.getEnvelope().getBody().getFirstElement();
-
+
/*
- * We assume that output likes
- * <invokeResponse>
- * <output_param_name1>value</output_param_name1>
- * <output_param_name2>value</output_param_name2>
- * <output_param_name3>value</output_param_name3>
- * </invokeResponse>
- */
+ * We assume that output likes
+ * <invokeResponse>
+ * <output_param_name1>value</output_param_name1>
+ * <output_param_name2>value</output_param_name2>
+ * <output_param_name3>value</output_param_name3>
+ * </invokeResponse>
+ */
OMElement output = invokeApplication(serviceName, invoke, context);
SOAPFactory sf = OMAbstractFactory.getSOAP11Factory();
@@ -157,11 +166,11 @@ public class GFacMessageReciever impleme
ct.setServiceName(serviceName);
ct.getExecutionContext().setRegistryService(regis);
ct.getExecutionContext().setNotificationService(notification);
-
+
/*
- * read from registry and set the correct parameters
- */
+ * read from registry and set the correct parameters
+ */
ServiceDescription serviceDescription = regis.getServiceDescription(serviceName);
/*
@@ -207,8 +216,8 @@ public class GFacMessageReciever impleme
OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/axis2/xsd", "ns1");
outputElement = fac.createOMElement("invokeResponse", omNs);
- ParameterContextImpl paramContext = (ParameterContextImpl) ct.<AbstractParameter> getMessageContext("output");
- for (Iterator<String> iterator = paramContext.getNames(); iterator.hasNext();) {
+ ParameterContextImpl paramContext = (ParameterContextImpl) ct.<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);
@@ -225,7 +234,10 @@ public class GFacMessageReciever impleme
public void processgetWSDLOperation(MessageContext messageContext) throws Exception {
MessageContext response = null;
+ EndpointReference gfacUrl = messageContext.getConfigurationContext().getListenerManager().
+ getEPRforService("GFacService", "invoke", "http");
String serviceName = getOriginalServiceName(messageContext);
+ String serviceEpr = gfacUrl.getAddress().split("GFacService")[0] + serviceName;
ConfigurationContext context = messageContext.getConfigurationContext();
// todo this logic has to change based on the logic we are storing data
// into repository
@@ -239,17 +251,113 @@ public class GFacMessageReciever impleme
new StringReader(jcr.getWSDL(serviceName)));
StAXOMBuilder builder = new StAXOMBuilder(reader);
OMElement wsdlElement = builder.getDocumentElement();
- WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(wsdlElement.toString().getBytes());
- InputSource source = new InputSource(byteArrayInputStream);
- Definition wsdlDefinition = wsdlReader.readWSDL(null, source);
-
+ 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
SOAPFactory sf = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope responseEnv = sf.createSOAPEnvelope();
sf.createSOAPBody(responseEnv);
- responseEnv.getBody().addChild(wsdlElement);
+
+ reader = XMLInputFactory.newInstance().createXMLStreamReader(
+ new StringReader(definitions.toString()));
+ builder = new StAXOMBuilder(reader);
+ responseEnv.getBody().addChild(builder.getDocumentElement());
response = MessageContextBuilder.createOutMessageContext(messageContext);
response.setEnvelope(responseEnv);
response.getOperationContext().addMessageContext(response);
Added: 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=1166743&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSConstants.java (added)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSConstants.java Thu Sep 8 15:24:14 2011
@@ -0,0 +1,177 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+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
+ */
+ public static final String SCHEMA_LOCATION_ATTRIBUTE = "schemaLocation";
+}
\ No newline at end of file
Added: 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=1166743&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSDLUtil.java (added)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/WSDLUtil.java Thu Sep 8 15:24:14 2011
@@ -0,0 +1,429 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+package org.apache.airavata.services.gfac.axis2.util;
+
+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.MLogger;
+import xsul5.wsdl.*;
+
+import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.*;
+import java.util.LinkedList;
+import java.util.List;
+
+public class WSDLUtil {
+
+ private static final MLogger logger = MLogger.getLogger();
+
+ /**
+ * @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;
+ }
+
+ /**
+ * @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.warning("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];
+
+ }
+
+ /**
+ *
+ * @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;
+
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XMLUtil.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XMLUtil.java?rev=1166743&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XMLUtil.java (added)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XMLUtil.java Thu Sep 8 15:24:14 2011
@@ -0,0 +1,453 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+package org.apache.airavata.services.gfac.axis2.util;
+
+import org.apache.xmlbeans.XmlError;
+import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.XmlOptions;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+import org.xml.sax.SAXException;
+import org.xmlpull.infoset.XmlDocument;
+import org.xmlpull.infoset.XmlElement;
+import org.xmlpull.infoset.XmlNamespace;
+import org.xmlpull.mxp1.MXParserFactory;
+import org.xmlpull.mxp1_serializer.MXSerializer;
+import xsul5.MLogger;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+public class XMLUtil {
+
+ /**
+ * The XML builder for XPP5
+ */
+ public static final org.xmlpull.infoset.XmlInfosetBuilder BUILDER = org.xmlpull.infoset.XmlInfosetBuilder
+ .newInstance();
+
+ /**
+ * The XML builder for XPP3.
+ */
+ public static final org.xmlpull.v1.builder.XmlInfosetBuilder BUILDER3 = org.xmlpull.v1.builder.XmlInfosetBuilder
+ .newInstance(new MXParserFactory());
+
+ private static final MLogger logger = MLogger.getLogger();
+
+ private final static String PROPERTY_SERIALIZER_INDENTATION = "http://xmlpull.org/v1/doc/properties.html#serializer-indentation";
+
+ private final static String INDENT = " ";
+
+ /**
+ * Parses a specified string and returns the XmlElement (XPP3).
+ *
+ * @param string
+ * @return The XmlElement (XPP3) parsed.
+ */
+ public static org.xmlpull.v1.builder.XmlElement stringToXmlElement3(String string) {
+ return BUILDER3.parseFragmentFromReader(new StringReader(string));
+ }
+
+ /**
+ * Parses a specified string and returns the XmlElement (XPP5).
+ *
+ * @param string
+ * @return The XmlElement (XPP5) parsed.
+ */
+ public static XmlElement stringToXmlElement(String string) {
+ XmlDocument document = BUILDER.parseString(string);
+ XmlElement element = document.getDocumentElement();
+ return element;
+ }
+
+ /**
+ * Converts a specified XmlElement (XPP3) to the XmlElement (XPP5).
+ *
+ * @param element
+ * @return The XmlElement (XPP5) converted.
+ */
+ public static XmlElement xmlElement3ToXmlElement5(org.xmlpull.v1.builder.XmlElement element) {
+ String string = xmlElementToString(element);
+ return stringToXmlElement(string);
+ }
+
+ /**
+ * Converts a specified XmlElement (XPP5) to the XmlElement (XPP3).
+ *
+ * @param element
+ * @return The XmlElement (XPP3) converted.
+ */
+ public static org.xmlpull.v1.builder.XmlElement xmlElement5ToXmlElement3(XmlElement element) {
+ String string = xmlElementToString(element);
+ return stringToXmlElement3(string);
+ }
+
+ /**
+ * Returns the XML string of a specified XmlElement.
+ *
+ * @param element
+ * The specified XmlElement
+ * @return The XML string
+ */
+ public static String xmlElementToString(org.xmlpull.v1.builder.XmlElement element) {
+ MXSerializer serializer = new MXSerializer();
+ StringWriter writer = new StringWriter();
+ serializer.setOutput(writer);
+ serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, INDENT);
+ BUILDER3.serialize(element, serializer);
+ String xmlText = writer.toString();
+ return xmlText;
+ }
+
+ /**
+ * Returns the XML string as a specified XmlElement (XPP5).
+ *
+ * @param element
+ * The specified XmlElement
+ * @return The XML string
+ */
+ public static String xmlElementToString(XmlElement element) {
+ String string;
+ if (element == null) {
+ string = "";
+ } else {
+ string = BUILDER.serializeToStringPretty(element);
+ }
+ return string;
+ }
+
+ /**
+ * Converts a specified XPP5 XML element to a DOM element under a specified document.
+ *
+ * @param xppElement
+ * @param document
+ * @return The converted DOM element.
+ */
+ public static Element xppElementToDomElement(XmlElement xppElement, Document document) {
+ Element domElement = document.createElement(xppElement.getName());
+
+ for (XmlNamespace namespace : xppElement.namespaces()) {
+ logger.finest("namespace: " + namespace);
+ }
+
+ for (org.xmlpull.infoset.XmlAttribute attribute : xppElement.attributes()) {
+ domElement.setAttribute(attribute.getName(), attribute.getValue());
+ }
+
+ for (Object object : xppElement.children()) {
+ if (object instanceof XmlElement) {
+ domElement.appendChild(xppElementToDomElement((XmlElement) object, document));
+ } else if (object instanceof String) {
+ Text text = document.createTextNode((String) object);
+ domElement.appendChild(text);
+ } else {
+ logger.finest("object.getClass(): " + object.getClass());
+ }
+ }
+ return domElement;
+ }
+
+ /**
+ * @param definitions3
+ * @return The WsdlDefinitions (XSUL5)
+ */
+ @Deprecated
+ public static xsul5.wsdl.WsdlDefinitions wsdlDefinitions3ToWsdlDefintions5(xsul.wsdl.WsdlDefinitions definitions3) {
+ return WSDLUtil.wsdlDefinitions3ToWsdlDefintions5(definitions3);
+ }
+
+ /**
+ * @param definitions5
+ * @return The WsdlDefinitions (XSUL3)
+ */
+ @Deprecated
+ public static xsul.wsdl.WsdlDefinitions wsdlDefinitions5ToWsdlDefintions3(xsul5.wsdl.WsdlDefinitions definitions5) {
+ return WSDLUtil.wsdlDefinitions5ToWsdlDefintions3(definitions5);
+ }
+
+ /**
+ * Converts a specified XPP3 XML element to a DOM element under a specified document.
+ *
+ * @param xppElement
+ * @param document
+ * @return The converted DOM element.
+ */
+ public static Element xppElementToDomElement(org.xmlpull.v1.builder.XmlElement xppElement, Document document) {
+ Element domElement = document.createElement(xppElement.getName());
+
+ Iterator nsIt = xppElement.namespaces();
+ while (nsIt.hasNext()) {
+ org.xmlpull.v1.builder.XmlNamespace namespace = (org.xmlpull.v1.builder.XmlNamespace) nsIt.next();
+ logger.finest("namespace: " + namespace);
+ // TODO
+ }
+
+ Iterator attrIt = xppElement.attributes();
+ while (attrIt.hasNext()) {
+ org.xmlpull.v1.builder.XmlAttribute attribute = (org.xmlpull.v1.builder.XmlAttribute) attrIt.next();
+ // TODO namespace
+ domElement.setAttribute(attribute.getName(), attribute.getValue());
+ }
+
+ Iterator elementIt = xppElement.children();
+ while (elementIt.hasNext()) {
+ Object object = elementIt.next();
+ if (object instanceof org.xmlpull.v1.builder.XmlElement) {
+ domElement.appendChild(xppElementToDomElement((org.xmlpull.v1.builder.XmlElement) object, document));
+ } else if (object instanceof String) {
+ Text text = document.createTextNode((String) object);
+ domElement.appendChild(text);
+ } else {
+ logger.finest("object.getClass(): " + object.getClass());
+ }
+ }
+ return domElement;
+ }
+
+ /**
+ * @param element
+ * @return The cloned XmlElement.
+ */
+ public static XmlElement deepClone(XmlElement element)throws Exception {
+ try {
+ XmlElement clonedElement = element.clone();
+ clonedElement.setParent(null);
+ return clonedElement;
+ } catch (CloneNotSupportedException e) {
+ // This should not happen because we don't put any special Objects.
+ throw new Exception(e);
+ }
+ }
+
+
+
+
+ /**
+ * @param string
+ * @return true if the specified string is XML, false otherwise
+ */
+ public static boolean isXML(String string) {
+ try {
+ stringToXmlElement(string);
+ return true;
+ } catch (RuntimeException e) {
+ logger.caught(e);
+ return false;
+ }
+ }
+
+ /**
+ * Validates a specified XmlObject along with logging errors if any.
+ *
+ * @param xmlObject
+ */
+ public static void validate(XmlObject xmlObject)throws Exception{
+ XmlOptions validateOptions = new XmlOptions();
+ ArrayList errorList = new ArrayList();
+ validateOptions.setErrorListener(errorList);
+
+ boolean isValid = xmlObject.validate(validateOptions);
+ if (isValid) {
+ // Valid
+ return;
+ }
+
+ // Error
+ StringBuilder stringBuilder = new StringBuilder();
+ for (int i = 0; i < errorList.size(); i++) {
+ XmlError error = (XmlError) errorList.get(i);
+ logger.warning("Message: " + error.getMessage());
+ logger.warning("Location of invalid XML: " + error.getCursorLocation().xmlText());
+ stringBuilder.append("Message:" + error.getMessage());
+ stringBuilder.append("Location of invalid XML: " + error.getCursorLocation().xmlText());
+ }
+ throw new Exception(stringBuilder.toString());
+ }
+
+ /**
+ * Returns the local part of a specified QName.
+ *
+ * @param qname
+ * the specified QName in string, e.g. ns:value
+ * @return the local part of the QName, e.g. value
+ */
+ public static String getLocalPartOfQName(String qname) {
+ int index = qname.indexOf(':');
+ if (index < 0) {
+ return qname;
+ } else {
+ return qname.substring(index + 1);
+ }
+ }
+
+ /**
+ * Returns the prefix of a specified QName.
+ *
+ * @param qname
+ * the specified QName in string, e.g. ns:value
+ * @return the prefix of the QName, e.g. ns
+ */
+ public static String getPrefixOfQName(String qname) {
+ int index = qname.indexOf(':');
+ if (index < 0) {
+ return null;
+ } else {
+ return qname.substring(0, index);
+ }
+ }
+
+ /**
+ * @param prefixCandidate
+ * @param uri
+ * @param alwaysUseSuffix
+ * @param element
+ * @return The namespace found or declared.
+ */
+ public static XmlNamespace declareNamespaceIfNecessary(String prefixCandidate, String uri, boolean alwaysUseSuffix,
+ XmlElement element) {
+ XmlNamespace namespace = element.lookupNamespaceByName(uri);
+ if (namespace == null) {
+ return declareNamespace(prefixCandidate, uri, alwaysUseSuffix, element);
+ } else {
+ return namespace;
+ }
+ }
+
+ /**
+ * @param prefixCandidate
+ * @param uri
+ * @param alwaysUseSuffix
+ * @param element
+ * @return The namespace declared.
+ */
+ public static XmlNamespace declareNamespace(String prefixCandidate, String uri, boolean alwaysUseSuffix,
+ XmlElement element) {
+ if (prefixCandidate == null || prefixCandidate.length() == 0) {
+ prefixCandidate = "a";
+ }
+ String prefix = prefixCandidate;
+ if (alwaysUseSuffix) {
+ prefix += "0";
+ }
+ if (element.lookupNamespaceByPrefix(prefix) != null) {
+ int i = 1;
+ prefix = prefixCandidate + i;
+ while (element.lookupNamespaceByPrefix(prefix) != null) {
+ i++;
+ }
+ }
+ XmlNamespace namespace = element.declareNamespace(prefix, uri);
+ return namespace;
+ }
+
+ /**
+ * @param xml
+ * @param string
+ */
+ public static void removeElements(XmlElement xml, String name) {
+
+ Iterable<XmlElement> removeElements = xml.elements(null, name);
+ LinkedList<XmlElement> removeList = new LinkedList<XmlElement>();
+ for (XmlElement xmlElement : removeElements) {
+ removeList.add(xmlElement);
+ }
+ for (XmlElement xmlElement : removeList) {
+ xml.removeChild(xmlElement);
+ }
+ Iterable children = xml.children();
+ for (Object object : children) {
+ if (object instanceof XmlElement) {
+ XmlElement element = (XmlElement) object;
+ removeElements(element, name);
+ }
+ }
+ }
+
+ /**
+ * @param url
+ * @return Document
+ */
+ public static Document retrievalXMLDocFromUrl(String url) {
+ try {
+ URL xmlUrl = new URL(url);
+ InputStream in = xmlUrl.openStream();
+ Document ret = null;
+ DocumentBuilderFactory domFactory;
+ DocumentBuilder builder;
+
+ domFactory = DocumentBuilderFactory.newInstance();
+ domFactory.setValidating(false);
+ domFactory.setNamespaceAware(false);
+ builder = domFactory.newDocumentBuilder();
+
+ ret = builder.parse(in);
+
+ return ret;
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ } catch (SAXException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ /**
+ * @param url
+ * @return Document
+ */
+ public static Document retrievalXMLDocForParse(String url) {
+ try {
+ URL xmlUrl = new URL(url);
+ InputStream in = xmlUrl.openStream();
+ DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance();
+ xmlFact.setNamespaceAware(true);
+ DocumentBuilder builder = xmlFact.newDocumentBuilder();
+ Document doc = builder.parse(in);
+
+ return doc;
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ } catch (SAXException e) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XmlFormatter.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XmlFormatter.java?rev=1166743&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XmlFormatter.java (added)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/util/XmlFormatter.java Thu Sep 8 15:24:14 2011
@@ -0,0 +1,81 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+package org.apache.airavata.services.gfac.axis2.util;
+
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+/**
+ * Pretty-prints xml, supplied as a string.
+ * <p/>
+ * eg. <code>
+ * String formattedXml = new XmlFormatter().format("<tag><nested>hello</nested></tag>");
+ * </code>
+ */
+public class XmlFormatter {
+
+ /**
+ * @param unformattedXml
+ * @return formattedXml
+ */
+ public static String format(String unformattedXml) {
+ try {
+ final Document document = parseXmlFile(unformattedXml);
+ OutputFormat format = new OutputFormat(document);
+ format.setLineWidth(65);
+ format.setIndenting(true);
+ format.setIndent(2);
+ Writer out = new StringWriter();
+ XMLSerializer serializer = new XMLSerializer(out, format);
+ serializer.serialize(document);
+ return out.toString();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static Document parseXmlFile(String in) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ InputSource is = new InputSource(new StringReader(in));
+ return db.parse(is);
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ } catch (SAXException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/airavata/trunk/modules/gfac-axis2/src/main/resources/services.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/gfac-axis2/src/main/resources/services.xml?rev=1166743&r1=1166742&r2=1166743&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/gfac-axis2/src/main/resources/services.xml (original)
+++ incubator/airavata/trunk/modules/gfac-axis2/src/main/resources/services.xml Thu Sep 8 15:24:14 2011
@@ -22,6 +22,13 @@
<outputActionMapping>http://schemas.xmlsoap.org/ws/2004/08/eventing/RenewResponse
</outputActionMapping>
</operation>
+ <operation name="getAbstractWSDL">
+ <messageReceiver class="org.apache.airavata.services.gfac.axis2.reciever.GFacMessageReciever"/>
+ <actionMapping>http://schemas.xmlsoap.org/ws/2004/08/eventing/Renew
+ </actionMapping>
+ <outputActionMapping>http://schemas.xmlsoap.org/ws/2004/08/eventing/RenewResponse
+ </outputActionMapping>
+ </operation>
<operation name="invoke">
<messageReceiver class="org.apache.airavata.services.gfac.axis2.reciever.GFacMessageReciever"/>
<actionMapping>http://schemas.xmlsoap.org/ws/2004/08/eventing/Renew</actionMapping>