summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2')
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2AsyncTargetInvoker.java84
-rwxr-xr-xsca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java208
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilderRuntimeException.java65
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingRunTimeException.java48
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2CallbackInvocationHandler.java74
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2OneWayTargetInvoker.java71
-rwxr-xr-xsca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java187
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java55
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java100
-rwxr-xr-xsca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Service.java290
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceCallbackTargetInvoker.java114
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInMessageReceiver.java67
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java95
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java73
-rw-r--r--sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceServlet.java207
-rwxr-xr-xsca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java136
-rwxr-xr-xsca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBinding.java78
-rwxr-xr-xsca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java143
-rwxr-xr-xsca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java44
-rwxr-xr-xsca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java491
-rwxr-xr-xsca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java377
21 files changed, 3007 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2AsyncTargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2AsyncTargetInvoker.java
new file mode 100644
index 0000000000..0cf3976f37
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2AsyncTargetInvoker.java
@@ -0,0 +1,84 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+
+public class Axis2AsyncTargetInvoker extends Axis2TargetInvoker {
+
+ protected static final OMElement RESPONSE = null;
+
+ private InboundWire wire;
+ private Object messageId;
+ private Axis2ReferenceCallbackTargetInvoker callbackInvoker;
+
+ public Axis2AsyncTargetInvoker(ServiceClient serviceClient,
+ QName wsdlOperationName,
+ Options options,
+ SOAPFactory soapFactory,
+ InboundWire wire) {
+ super(serviceClient, wsdlOperationName, options, soapFactory);
+ this.wire = wire;
+ }
+
+ public Object invokeTarget(final Object payload) throws InvocationTargetException {
+ try {
+ Object[] args = (Object[])payload;
+ OperationClient operationClient = createOperationClient(args);
+ callbackInvoker.setCorrelationId(messageId);
+ Axis2ReferenceCallback callback = new Axis2ReferenceCallback(callbackInvoker);
+ operationClient.setCallback(callback);
+
+ operationClient.execute(false);
+
+ // REVIEW it seems ok to return null
+ return RESPONSE;
+ } catch (AxisFault e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ wire.addMapping(msg.getMessageId(), msg.getFromAddress());
+ messageId = msg.getMessageId();
+ Object resp = invokeTarget(msg.getBody());
+ msg.setBody(resp);
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+
+ public void setCallbackTargetInvoker(Axis2ReferenceCallbackTargetInvoker callbackInvoker) {
+ this.callbackInvoker = callbackInvoker;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java
new file mode 100755
index 0000000000..1090be874d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilder.java
@@ -0,0 +1,208 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.tuscany.binding.axis2.util.TuscanyAxisConfigurator;
+import org.apache.tuscany.idl.wsdl.InterfaceWSDLIntrospector;
+import org.apache.tuscany.idl.wsdl.WSDLServiceContract;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.Reference;
+import org.apache.tuscany.spi.component.Service;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.BindingBuilderExtension;
+import org.apache.tuscany.spi.host.ServletHost;
+import org.apache.tuscany.spi.idl.InvalidServiceContractException;
+import org.apache.tuscany.spi.model.BoundReferenceDefinition;
+import org.apache.tuscany.spi.model.BoundServiceDefinition;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.IncompatibleServiceContractException;
+
+/**
+ * Builds a {@link org.osoa.sca.annotations.Service} or {@link org.apache.tuscany.spi.component.Reference} configured
+ * with the Axis2 binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class Axis2BindingBuilder extends BindingBuilderExtension<WebServiceBinding> {
+ private static final String OM_DATA_BINDING = OMElement.class.getName();
+
+ private ServletHost servletHost;
+
+ private ConfigurationContext configContext;
+
+ private WorkContext workContext;
+
+ private InterfaceWSDLIntrospector introspector;
+
+ public Axis2BindingBuilder() {
+ initAxis();
+ }
+
+ @Autowire(required = false)
+ public void setServletHost(ServletHost servletHost) {
+ this.servletHost = servletHost;
+ }
+
+ /**
+ * @param introspector the introspector to set
+ */
+ @Autowire
+ public void setIntrospector(InterfaceWSDLIntrospector introspector) {
+ this.introspector = introspector;
+ }
+
+ @Autowire
+ public void setWorkContext(WorkContext workContext) {
+ this.workContext = workContext;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Service build(
+ CompositeComponent parent,
+ BoundServiceDefinition<WebServiceBinding> serviceDefinition,
+ DeploymentContext deploymentContext) {
+
+ try {
+ // Set the default databinding
+ ServiceContract<?> outboundContract = serviceDefinition.getServiceContract();
+ if (WSDLServiceContract.class.isInstance(outboundContract)) {
+ outboundContract.setDataBinding(OM_DATA_BINDING);
+ }
+
+ // FIXME: We need to define how the WSDL PortType is honored in the case that
+ // both the binding.ws and interface.wsdl are in place.
+ // The WSDL portType from the WSDL Port decides the incoming SOAP message format
+ // There are also cases that interface.java is used.
+
+ ServiceContract<?> inboundContract = null;
+ WebServiceBinding wsBinding = serviceDefinition.getBinding();
+ Port port = wsBinding.getWSDLPort();
+ if (port == null) {
+ // FIXME: [rfeng] No WSDL is referenced by binding.ws, we need to create one from
+ // the outbound service contract if it's JavaServiceContract
+ inboundContract = outboundContract;
+ }
+
+ PortType portType = wsBinding.getWSDLPort().getBinding().getPortType();
+ inboundContract = introspector.introspect(portType);
+
+ // FIXME:
+ inboundContract.setInterfaceClass(serviceDefinition.getServiceContract().getInterfaceClass());
+ inboundContract.setDataBinding(OM_DATA_BINDING);
+ inboundContract.setCallbackName(serviceDefinition.getServiceContract().getCallbackName());
+
+ try {
+ wireService.checkCompatibility(inboundContract, outboundContract, true);
+ } catch (IncompatibleServiceContractException e) {
+ throw new Axis2BindingBuilderRuntimeException(e);
+ }
+
+ Service service = new Axis2Service(serviceDefinition.getName(), outboundContract, parent, wireService, wsBinding,
+ servletHost, configContext, workContext);
+ service.setBindingServiceContract(inboundContract);
+
+ return service;
+
+ } catch (InvalidServiceContractException e) {
+ throw new Axis2BindingBuilderRuntimeException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public Reference build(
+ CompositeComponent parent,
+ BoundReferenceDefinition<WebServiceBinding> boundReferenceDefinition,
+ DeploymentContext deploymentContext) {
+
+ try {
+ // Set the default binding
+ ServiceContract<?> inboundContract = boundReferenceDefinition.getServiceContract();
+ if (WSDLServiceContract.class.isInstance(inboundContract)) {
+ inboundContract.setDataBinding(OM_DATA_BINDING);
+ }
+
+ // FIXME: We need to define how the WSDL PortType is honored in the case that
+ // both the binding.ws and interface.wsdl are in place
+ // The WSDL portType from the WSDL Port decides the incoming SOAP message format
+
+ ServiceContract<?> outboundContract = inboundContract;
+ WebServiceBinding wsBinding = boundReferenceDefinition.getBinding();
+ Port port = wsBinding.getWSDLPort();
+ if (port == null) {
+ // FIXME: [rfeng] No WSDL is referenced by binding.ws, we need to create one from
+ // the inbound service contract if it's JavaServiceContract
+ outboundContract = inboundContract;
+ }
+ PortType portType = port.getBinding().getPortType();
+ outboundContract = introspector.introspect(portType);
+
+ // Set the default databinding
+ outboundContract.setDataBinding(OM_DATA_BINDING);
+
+ try {
+ wireService.checkCompatibility(inboundContract, outboundContract, true);
+ } catch (IncompatibleServiceContractException e) {
+ throw new Axis2BindingBuilderRuntimeException(e);
+ }
+
+ Reference reference = new Axis2Reference(boundReferenceDefinition.getName(), parent, wireService, wsBinding,
+ inboundContract, workContext);
+ reference.setBindingServiceContract(outboundContract);
+
+ return reference;
+
+ } catch (InvalidServiceContractException e) {
+ throw new Axis2BindingBuilderRuntimeException(e);
+ }
+ }
+
+ protected Class<WebServiceBinding> getBindingType() {
+ return WebServiceBinding.class;
+ }
+
+ protected void initAxis() {
+ // TODO: Fix classloader switching. See TUSCANY-647
+ // TODO: also consider having a system component wrapping the Axis2 ConfigContext
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ ClassLoader scl = getClass().getClassLoader();
+ try {
+ if (tccl != scl) {
+ Thread.currentThread().setContextClassLoader(scl);
+ }
+ try {
+ this.configContext = new TuscanyAxisConfigurator().getConfigurationContext();
+ } catch (AxisFault e) {
+ throw new BuilderConfigException(e);
+ }
+ } finally {
+ if (tccl != scl) {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilderRuntimeException.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilderRuntimeException.java
new file mode 100644
index 0000000000..a5743668a4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingBuilderRuntimeException.java
@@ -0,0 +1,65 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+
+/**
+ * Base class for Exceptions raised during the loading process. Loader implementations should throw a subclass of this
+ * to indicate the actual problem.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Axis2BindingBuilderRuntimeException extends Axis2BindingRunTimeException {
+ private static final long serialVersionUID = -7459051598906813461L;
+ private String resourceURI;
+
+ public Axis2BindingBuilderRuntimeException() {
+ }
+
+ public Axis2BindingBuilderRuntimeException(String message) {
+ super(message);
+ }
+
+ public Axis2BindingBuilderRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public Axis2BindingBuilderRuntimeException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns the location of the resource that was being loaded.
+ *
+ * @return the location of the resource that was being loaded
+ */
+ public String getResourceURI() {
+ return resourceURI;
+ }
+
+ /**
+ * Sets the location of the resource that was being loaded.
+ *
+ * @param resourceURI the location of the resource that was being loaded
+ */
+ public void setResourceURI(String resourceURI) {
+ this.resourceURI = resourceURI;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingRunTimeException.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingRunTimeException.java
new file mode 100644
index 0000000000..cd957c2ec6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2BindingRunTimeException.java
@@ -0,0 +1,48 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Denotes an error creating a new object instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class Axis2BindingRunTimeException extends TuscanyRuntimeException {
+ private static final long serialVersionUID = -6423113430265944499L;
+
+ public Axis2BindingRunTimeException() {
+ super();
+ }
+
+ public Axis2BindingRunTimeException(String message) {
+ super(message);
+ }
+
+ public Axis2BindingRunTimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public Axis2BindingRunTimeException(Throwable cause) {
+ super(cause);
+ }
+
+}
+
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2CallbackInvocationHandler.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2CallbackInvocationHandler.java
new file mode 100644
index 0000000000..4a9e054237
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2CallbackInvocationHandler.java
@@ -0,0 +1,74 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.util.Map;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.AbstractOutboundInvocationHandler;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.OutboundInvocationChain;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+public class Axis2CallbackInvocationHandler extends AbstractOutboundInvocationHandler {
+
+ private InboundWire inboundWire;
+ private Object messageId;
+ private Object correlationId;
+
+ public Axis2CallbackInvocationHandler(InboundWire inboundWire) {
+ this.inboundWire = inboundWire;
+ }
+
+ public Object invoke(Operation operation, Object[] args) throws Throwable {
+ Object targetAddress = inboundWire.retrieveMapping(correlationId);
+ if (targetAddress == null) {
+ throw new AssertionError("No from address associated with message id [" + correlationId + "]");
+ }
+ //TODO optimize as this is slow in local invocations
+ Map<Operation<?>, OutboundInvocationChain> sourceCallbackInvocationChains =
+ inboundWire.getSourceCallbackInvocationChains(targetAddress);
+ OutboundInvocationChain chain = sourceCallbackInvocationChains.get(operation);
+ TargetInvoker invoker = chain.getTargetInvoker();
+ return invoke(chain, invoker, args);
+ }
+
+ // This must be called before invoke
+ public void setMessageId(Object messageId) {
+ this.messageId = messageId;
+ }
+
+ // This must be called before invoke
+ public void setCorrelationId(Object correlationId) {
+ this.correlationId = correlationId;
+ }
+
+ protected Object getFromAddress() {
+ return (inboundWire.getContainer() == null) ? null : inboundWire.getContainer().getName();
+ }
+
+ protected Object getMessageId() {
+ return messageId;
+ }
+
+ protected Object getCorrelationId() {
+ return correlationId;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2OneWayTargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2OneWayTargetInvoker.java
new file mode 100644
index 0000000000..a85c57313f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2OneWayTargetInvoker.java
@@ -0,0 +1,71 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+
+public class Axis2OneWayTargetInvoker extends Axis2TargetInvoker {
+
+ protected static final OMElement RESPONSE = null;
+
+ public Axis2OneWayTargetInvoker(ServiceClient serviceClient,
+ QName wsdlOperationName,
+ Options options,
+ SOAPFactory soapFactory) {
+
+ super(serviceClient, wsdlOperationName, options, soapFactory);
+ }
+
+ public Object invokeTarget(final Object payload) throws InvocationTargetException {
+ try {
+ Object[] args = (Object[])payload;
+ OperationClient operationClient = createOperationClient(args);
+
+ operationClient.execute(false);
+
+ // REVIEW it seems ok to return null
+ return RESPONSE;
+ } catch (AxisFault e) {
+ throw new InvocationTargetException(e);
+ } catch (Throwable t) {
+ throw new Axis2BindingRunTimeException(t);
+ }
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ Object resp = invokeTarget(msg.getBody());
+ msg.setBody(resp);
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java
new file mode 100755
index 0000000000..53ae1ae51e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Reference.java
@@ -0,0 +1,187 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.util.Collection;
+
+import javax.wsdl.Definition;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.tuscany.binding.axis2.util.TuscanyAxisConfigurator;
+import org.apache.tuscany.binding.axis2.util.WebServiceOperationMetaData;
+import org.apache.tuscany.binding.axis2.util.WebServicePortMetaData;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.ReferenceExtension;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.OutboundWire;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireService;
+
+/**
+ * Axis2Reference uses Axis2 to invoke a remote web service
+ */
+public class Axis2Reference<T> extends ReferenceExtension {
+
+ private WebServicePortMetaData wsPortMetaData;
+ private ServiceClient serviceClient;
+
+ // private WorkContext workContext;
+
+ @SuppressWarnings("unchecked")
+ public Axis2Reference(String theName,
+ CompositeComponent parent,
+ WireService wireService,
+ WebServiceBinding wsBinding,
+ ServiceContract contract,
+ WorkContext workContext) {
+ super(theName, (Class<T>)contract.getInterfaceClass(), parent, wireService);
+ try {
+ Definition wsdlDefinition = wsBinding.getWSDLDefinition();
+ wsPortMetaData =
+ new WebServicePortMetaData(wsdlDefinition, wsBinding.getWSDLPort(), wsBinding.getURI(), false);
+ serviceClient = createServiceClient(wsdlDefinition, wsPortMetaData);
+ // this.workContext = workContext;
+ } catch (AxisFault e) {
+ throw new Axis2BindingRunTimeException(e);
+ }
+ }
+
+ public TargetInvoker createTargetInvoker(ServiceContract contract, Operation operation) {
+ Axis2TargetInvoker invoker;
+ try {
+ boolean isOneWay = operation.isNonBlocking();
+ invoker = createOperationInvoker(serviceClient, operation, wsPortMetaData, false, isOneWay);
+ } catch (AxisFault e) {
+ throw new Axis2BindingRunTimeException(e);
+ }
+ return invoker;
+ }
+
+ public TargetInvoker createAsyncTargetInvoker(OutboundWire wire, Operation operation) {
+ Axis2AsyncTargetInvoker invoker;
+ try {
+ // FIXME: SDODataBinding needs to pass in TypeHelper and classLoader
+ // as parameters.
+ invoker =
+ (Axis2AsyncTargetInvoker)createOperationInvoker(serviceClient,
+ operation,
+ wsPortMetaData,
+ true,
+ false);
+ // FIXME: This makes the (BIG) assumption that there is only one
+ // callback method
+ // Relaxing this assumption, however, does not seem to be trivial,
+ // it may depend on knowledge
+ // of what actual callback method was invoked by the service at the
+ // other end
+ Operation callbackOperation = findCallbackOperation();
+ Axis2CallbackInvocationHandler invocationHandler =
+ new Axis2CallbackInvocationHandler(inboundWire);
+ Axis2ReferenceCallbackTargetInvoker callbackInvoker =
+ new Axis2ReferenceCallbackTargetInvoker(callbackOperation, inboundWire, invocationHandler);
+ invoker.setCallbackTargetInvoker(callbackInvoker);
+ } catch (AxisFault e) {
+ throw new Axis2BindingRunTimeException(e);
+ }
+ return invoker;
+ }
+
+ private Operation findCallbackOperation() {
+ ServiceContract contract = inboundWire.getServiceContract();
+ Operation callbackOperation = null;
+ Collection callbackOperations = contract.getCallbackOperations().values();
+ if (callbackOperations.size() != 1) {
+ throw new Axis2BindingRunTimeException("Can only handle one callback operation");
+ } else {
+ callbackOperation = (Operation)callbackOperations.iterator().next();
+ }
+ return callbackOperation;
+ }
+
+ /**
+ * Create an Axis2 ServiceClient
+ */
+ private ServiceClient createServiceClient(Definition wsdlDefinition, WebServicePortMetaData wsPortMetaData)
+ throws AxisFault {
+
+ TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
+ ConfigurationContext configurationContext = tuscanyAxisConfigurator.getConfigurationContext();
+ QName serviceQName = wsPortMetaData.getServiceName();
+ String portName = wsPortMetaData.getPortName().getLocalPart();
+ AxisService axisService =
+ AxisService.createClientSideAxisService(wsdlDefinition, serviceQName, portName, new Options());
+ return new ServiceClient(configurationContext, axisService);
+ }
+
+ /**
+ * Create and configure an Axis2TargetInvoker for each operations
+ */
+ private Axis2TargetInvoker createOperationInvoker(ServiceClient serviceClient,
+ Operation m,
+ WebServicePortMetaData wsPortMetaData,
+ boolean hasCallback,
+ boolean isOneWay) throws AxisFault {
+ SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
+ String portTypeNS = wsPortMetaData.getPortTypeName().getNamespaceURI();
+
+ String methodName = m.getName();
+
+ WebServiceOperationMetaData operationMetaData = wsPortMetaData.getOperationMetaData(methodName);
+
+ Options options = new Options();
+ options.setTo(new EndpointReference(wsPortMetaData.getEndpoint()));
+ options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);
+
+ String wsdlOperationName = operationMetaData.getBindingOperation().getOperation().getName();
+
+ String soapAction = wsPortMetaData.getOperationMetaData(wsdlOperationName).getSOAPAction();
+ if (soapAction != null && soapAction.length() > 1) {
+ options.setAction(soapAction);
+ }
+
+ options.setTimeOutInMilliSeconds(5 * 60 * 1000);
+
+ QName wsdlOperationQName = new QName(portTypeNS, wsdlOperationName);
+
+ Axis2TargetInvoker invoker;
+ if (hasCallback) {
+ invoker =
+ new Axis2AsyncTargetInvoker(serviceClient, wsdlOperationQName, options, soapFactory,
+ inboundWire);
+ } else if (isOneWay) {
+ invoker = new Axis2OneWayTargetInvoker(serviceClient, wsdlOperationQName, options, soapFactory);
+ } else {
+ invoker = new Axis2TargetInvoker(serviceClient, wsdlOperationQName, options, soapFactory);
+ }
+
+ return invoker;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java
new file mode 100644
index 0000000000..d6bb1a0290
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallback.java
@@ -0,0 +1,55 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.client.async.AsyncResult;
+import org.apache.axis2.client.async.Callback;
+import org.apache.axis2.context.MessageContext;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+
+public class Axis2ReferenceCallback extends Callback {
+
+ private Axis2ReferenceCallbackTargetInvoker targetInvoker;
+
+ public Axis2ReferenceCallback(Axis2ReferenceCallbackTargetInvoker targetInvoker) {
+ this.targetInvoker = targetInvoker;
+ }
+
+ public void onComplete(AsyncResult result) {
+ MessageContext responseMC = result.getResponseMessageContext();
+ OMElement responseOM = responseMC.getEnvelope().getBody().getFirstElement();
+ try {
+ targetInvoker.invokeTarget(new Object[] {responseOM});
+ } catch (InvocationTargetException e) {
+ // FIXME what is the appropriate exception here?
+ throw new InvocationRuntimeException(e);
+ }
+ }
+
+ public void setComplete(boolean complete) {
+ super.setComplete(complete);
+ }
+
+ public void onError(Exception e) {
+ throw new InvocationRuntimeException(e);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java
new file mode 100644
index 0000000000..87f9b5654b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java
@@ -0,0 +1,100 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InboundWire;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+public class Axis2ReferenceCallbackTargetInvoker implements TargetInvoker {
+
+ private Operation operation;
+ private InboundWire inboundWire;
+ private Object correlationId;
+ private boolean cacheable;
+ Axis2CallbackInvocationHandler invocationHandler;
+
+ public Axis2ReferenceCallbackTargetInvoker(Operation operation,
+ InboundWire inboundWire,
+ Axis2CallbackInvocationHandler invocationHandler) {
+
+ this.operation = operation;
+ this.inboundWire = inboundWire;
+ this.invocationHandler = invocationHandler;
+ }
+
+ public Object invokeTarget(final Object payload) throws InvocationTargetException {
+ invocationHandler.setMessageId(null);
+ invocationHandler.setCorrelationId(correlationId);
+ Object[] args;
+ if (payload != null && !payload.getClass().isArray()) {
+ args = new Object[]{payload};
+ } else {
+ args = (Object[]) payload;
+ }
+ try {
+ return invocationHandler.invoke(operation, args);
+ } catch(Throwable t) {
+ t.printStackTrace();
+ throw new InvocationTargetException(t);
+ }
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ Object resp = invokeTarget(msg.getBody());
+ msg.setBody(resp);
+ } catch (InvocationTargetException e) {
+ msg.setBodyWithFault(e.getCause());
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+
+ public boolean isCacheable() {
+ return cacheable;
+ }
+
+ public void setCacheable(boolean cacheable) {
+ this.cacheable = cacheable;
+ }
+
+ public boolean isOptimizable() {
+ return isCacheable(); // we only need to check if the scopes are correct
+ }
+
+ public Axis2ReferenceCallbackTargetInvoker clone() throws CloneNotSupportedException {
+ Axis2ReferenceCallbackTargetInvoker invoker = (Axis2ReferenceCallbackTargetInvoker) super.clone();
+ invoker.operation = this.operation;
+ invoker.inboundWire = this.inboundWire;
+ invoker.correlationId = this.correlationId;
+ invoker.cacheable = this.cacheable;
+ invoker.invocationHandler = this.invocationHandler;
+ return invoker;
+ }
+
+ public void setCorrelationId(Object correlationId) {
+ this.correlationId = correlationId;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Service.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Service.java
new file mode 100755
index 0000000000..47c9d8308a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2Service.java
@@ -0,0 +1,290 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Operation;
+import javax.wsdl.PortType;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
+import org.apache.axis2.description.WSDLToAxisServiceBuilder;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004Constants;
+import org.apache.tuscany.binding.axis2.util.WebServicePortMetaData;
+import org.apache.tuscany.spi.builder.BuilderConfigException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.extension.ServiceExtension;
+import org.apache.tuscany.spi.host.ServletHost;
+import org.apache.tuscany.spi.model.ServiceContract;
+import org.apache.tuscany.spi.wire.Interceptor;
+import org.apache.tuscany.spi.wire.InvocationChain;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageId;
+import org.apache.tuscany.spi.wire.MessageImpl;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+import org.apache.tuscany.spi.wire.WireService;
+import org.osoa.sca.annotations.Destroy;
+
+/**
+ * An implementation of a {@link ServiceExtension} configured with the Axis2
+ * binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class Axis2Service extends ServiceExtension {
+ private ServiceContract<?> serviceContract;
+
+ private ServletHost servletHost;
+
+ private ConfigurationContext configContext;
+
+ private WebServiceBinding binding;
+
+ private WorkContext workContext;
+
+ private Map<MessageId, InvocationContext> invCtxMap = new HashMap<MessageId, InvocationContext>();
+
+ private String serviceName;
+
+ public Axis2Service(String theName,
+ ServiceContract<?> serviceContract,
+ CompositeComponent parent,
+ WireService wireService,
+ WebServiceBinding binding,
+ ServletHost servletHost,
+ ConfigurationContext configContext,
+ WorkContext workContext) {
+
+ super(theName, serviceContract.getInterfaceClass(), parent, wireService);
+
+ this.serviceContract = serviceContract;
+ this.binding = binding;
+ this.servletHost = servletHost;
+ this.configContext = configContext;
+ this.workContext = workContext;
+ this.serviceName = theName;
+ }
+
+ public void start() {
+ super.start();
+
+ try {
+ configContext.getAxisConfiguration().addService(createAxisService(binding));
+ } catch (AxisFault e) {
+ throw new Axis2BindingRunTimeException(e);
+ }
+
+ Axis2ServiceServlet servlet = new Axis2ServiceServlet();
+ servlet.init(configContext);
+ configContext.setContextRoot(getName());
+ servletHost.registerMapping("/" + getName(), servlet);
+ }
+
+ @Destroy
+ public void stop() {
+ servletHost.unregisterMapping("/" + getName());
+ try {
+ configContext.getAxisConfiguration().removeService(getName());
+ } catch (AxisFault e) {
+ throw new Axis2BindingRunTimeException(e);
+ }
+ super.stop();
+ }
+
+ private AxisService createAxisService(WebServiceBinding wsBinding) throws AxisFault {
+ Definition definition = wsBinding.getWSDLDefinition();
+ WebServicePortMetaData wsdlPortInfo =
+ new WebServicePortMetaData(definition, wsBinding.getWSDLPort(), null, false);
+
+ // TODO investigate if this is 20 wsdl what todo?
+ WSDLToAxisServiceBuilder builder =
+ new WSDL11ToAxisServiceBuilder(definition, wsdlPortInfo.getServiceName(), wsdlPortInfo.getPort()
+ .getName());
+ builder.setServerSide(true);
+ AxisService axisService = builder.populateService();
+
+ axisService.setName(this.getName());
+ axisService.setServiceDescription("Tuscany configured AxisService for service: '" + this.getName()
+ + "'");
+
+ // Use the existing WSDL
+ Parameter wsdlParam = new Parameter(WSDLConstants.WSDL_4_J_DEFINITION, null);
+ wsdlParam.setValue(definition);
+ axisService.addParameter(wsdlParam);
+ Parameter userWSDL = new Parameter("useOriginalwsdl", "true");
+ axisService.addParameter(userWSDL);
+
+ PortType wsdlPortType = wsdlPortInfo.getPortType();
+ for (Object o : wsdlPortType.getOperations()) {
+ Operation wsdlOperation = (Operation)o;
+ String operationName = wsdlOperation.getName();
+ QName operationQN = new QName(definition.getTargetNamespace(), operationName);
+
+ org.apache.tuscany.spi.model.Operation<?> op = serviceContract.getOperations().get(operationName);
+
+ MessageReceiver msgrec = null;
+ boolean opIsNonBlocking = op.isNonBlocking();
+ if (serviceContract.getCallbackName() != null) {
+ msgrec = new Axis2ServiceInOutAsyncMessageReceiver(this, op, workContext);
+ } else if (opIsNonBlocking) {
+ msgrec = new Axis2ServiceInMessageReceiver(this, op);
+ } else {
+ msgrec = new Axis2ServiceInOutSyncMessageReceiver(this, op);
+ }
+
+ AxisOperation axisOp = axisService.getOperation(operationQN);
+ if (opIsNonBlocking) {
+ axisOp.setMessageExchangePattern(WSDL20_2004Constants.MEP_URI_IN_ONLY);
+ } else {
+ axisOp.setMessageExchangePattern(WSDL20_2004Constants.MEP_URI_IN_OUT);
+ }
+ axisOp.setMessageReceiver(msgrec);
+ }
+
+ return axisService;
+ }
+
+ public Object invokeTarget(org.apache.tuscany.spi.model.Operation<?> op, Object[] args)
+ throws InvocationTargetException {
+ InvocationChain chain = inboundWire.getInvocationChains().get(op);
+ Interceptor headInterceptor = chain.getHeadInterceptor();
+ if (headInterceptor == null) {
+ try {
+ // short-circuit the dispatch and invoke the target directly
+ if (chain.getTargetInvoker() == null) {
+ throw new AssertionError("No target invoker [" + chain.getOperation().getName() + "]");
+ }
+ return chain.getTargetInvoker().invokeTarget(args);
+ } catch (InvocationTargetException e) {
+ // the cause was thrown by the target so throw it
+ throw e;
+ }
+ } else {
+ Object messageId = workContext.getCurrentMessageId();
+ workContext.setCurrentMessageId(null);
+ Object correlationId = workContext.getCurrentCorrelationId();
+ workContext.setCurrentCorrelationId(null);
+
+ Message msg = new MessageImpl();
+ msg.setTargetInvoker(chain.getTargetInvoker());
+ msg.setFromAddress(getFromAddress());
+ if (messageId == null) {
+ messageId = new MessageId();
+ }
+ msg.setMessageId(messageId);
+ msg.setCorrelationId(correlationId);
+ msg.setBody(args);
+ Message resp;
+ // dispatch the wire down the chain and get the response
+ // TODO http://issues.apache.org/jira/browse/TUSCANY-777
+ ClassLoader oldtccl = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ resp = headInterceptor.invoke(msg);
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldtccl);
+ }
+ Object body = resp.getBody();
+ if (resp.isFault()) {
+ throw new InvocationTargetException((Throwable)body);
+ }
+ return body;
+ }
+ }
+
+ protected Object getFromAddress() {
+ return this.serviceName;
+ }
+
+ /**
+ * Get the Method from an interface matching the WSDL operation name
+ */
+ protected Method getMethod(Class<?> serviceInterface, String operationName) {
+ // Note: this doesn't support overloaded operations
+ Method[] methods = serviceInterface.getMethods();
+ for (Method m : methods) {
+ if (m.getName().equals(operationName)) {
+ return m;
+ }
+ // tolerate WSDL with capatalized operation name
+ StringBuilder sb = new StringBuilder(operationName);
+ sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
+ if (m.getName().equals(sb.toString())) {
+ return m;
+ }
+ }
+ throw new BuilderConfigException("no operation named " + operationName
+ + " found on service interface: "
+ + serviceInterface.getName());
+ }
+
+ public TargetInvoker createCallbackTargetInvoker(ServiceContract contract,
+ org.apache.tuscany.spi.model.Operation operation) {
+
+ return new Axis2ServiceCallbackTargetInvoker(workContext, this);
+ }
+
+ public void addMapping(MessageId msgId, InvocationContext invCtx) {
+ this.invCtxMap.put(msgId, invCtx);
+ }
+
+ public InvocationContext retrieveMapping(MessageId msgId) {
+ return this.invCtxMap.get(msgId);
+ }
+
+ public void removeMapping(MessageId msgId) {
+ this.invCtxMap.remove(msgId);
+ }
+
+ protected class InvocationContext {
+ public MessageContext inMessageContext;
+
+ public org.apache.tuscany.spi.model.Operation<?> operation;
+
+ public SOAPFactory soapFactory;
+
+ public CountDownLatch doneSignal;
+
+ public InvocationContext(MessageContext messageCtx,
+ org.apache.tuscany.spi.model.Operation<?> operation,
+ SOAPFactory soapFactory,
+ CountDownLatch doneSignal) {
+ this.inMessageContext = messageCtx;
+ this.operation = operation;
+ this.soapFactory = soapFactory;
+ this.doneSignal = doneSignal;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceCallbackTargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceCallbackTargetInvoker.java
new file mode 100644
index 0000000000..ca7812e01b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceCallbackTargetInvoker.java
@@ -0,0 +1,114 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.util.Utils;
+import org.apache.tuscany.binding.axis2.Axis2Service.InvocationContext;
+import org.apache.tuscany.binding.axis2.Axis2AsyncTargetInvoker;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.MessageId;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+public class Axis2ServiceCallbackTargetInvoker implements TargetInvoker {
+
+ private Axis2Service service;
+
+ private MessageId currentCorrelationId;
+
+ public Axis2ServiceCallbackTargetInvoker(WorkContext workContext, Axis2Service service) {
+ this.service = service;
+ }
+
+ public Object invokeTarget(final Object payload) throws InvocationTargetException {
+ try {
+ // Use current correlation id as index to retrieve inv context
+ InvocationContext invCtx = service.retrieveMapping(this.currentCorrelationId);
+
+ MessageContext outMC = Utils.createOutMessageContext(invCtx.inMessageContext);
+ outMC.getOperationContext().addMessageContext(outMC);
+
+ OMElement responseOM = null;
+ if (payload != null && !payload.getClass().isArray()) {
+ responseOM = (OMElement)payload;
+ } else {
+ responseOM = (OMElement)((Object[])payload)[0];
+ }
+ SOAPEnvelope soapEnvelope = invCtx.soapFactory.getDefaultEnvelope();
+ soapEnvelope.getBody().addChild(responseOM);
+ outMC.setEnvelope(soapEnvelope);
+ outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE);
+
+ AxisEngine engine =
+ new AxisEngine(invCtx.inMessageContext.getOperationContext().getServiceContext().getConfigurationContext());
+ engine.send(outMC);
+
+ invCtx.doneSignal.countDown();
+
+ service.removeMapping(this.currentCorrelationId);
+ } catch (AxisFault e) {
+ throw new InvocationTargetException(e);
+ } catch(Throwable t) {
+ throw new Axis2BindingRunTimeException(t);
+ }
+
+ return Axis2AsyncTargetInvoker.RESPONSE;
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ this.currentCorrelationId = (MessageId)msg.getCorrelationId();
+ Object resp = invokeTarget(msg.getBody());
+ msg.setBody(resp);
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+
+ public Axis2ServiceCallbackTargetInvoker clone() throws CloneNotSupportedException {
+ try {
+ return (Axis2ServiceCallbackTargetInvoker)super.clone();
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ return null;
+ }
+ }
+
+ public boolean isCacheable() {
+ return true;
+ }
+
+ public void setCacheable(boolean cacheable) {
+
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInMessageReceiver.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInMessageReceiver.java
new file mode 100644
index 0000000000..3b1b0d25e4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInMessageReceiver.java
@@ -0,0 +1,67 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.receivers.AbstractInMessageReceiver;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+
+public class Axis2ServiceInMessageReceiver extends AbstractInMessageReceiver {
+
+ protected Operation<?> operation;
+
+ private Axis2Service axis2Service;
+
+ public Axis2ServiceInMessageReceiver(Axis2Service service, Operation<?> operation) {
+ this.axis2Service = service;
+ this.operation = operation;
+ }
+
+ public Axis2ServiceInMessageReceiver() {
+
+ }
+
+ @Override
+ public void invokeBusinessLogic(MessageContext inMC) throws AxisFault {
+ try {
+ OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement();
+ Object[] args = new Object[] {requestOM};
+
+ axis2Service.invokeTarget(operation, args);
+
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getCause();
+ if (t instanceof Exception) {
+ throw AxisFault.makeFault((Exception)t);
+ }
+ throw new InvocationRuntimeException(e);
+ } catch (Throwable t) {
+ if (t instanceof Exception) {
+ throw AxisFault.makeFault((Exception)t);
+ }
+ throw new Axis2BindingRunTimeException(t);
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java
new file mode 100644
index 0000000000..f83862399c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java
@@ -0,0 +1,95 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.concurrent.CountDownLatch;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.receivers.AbstractMessageReceiver;
+import org.apache.tuscany.binding.axis2.Axis2Service.InvocationContext;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.MessageId;
+
+public class Axis2ServiceInOutAsyncMessageReceiver extends AbstractMessageReceiver {
+
+ private Operation<?> operation;
+
+ private WorkContext workContext;
+
+ private Axis2Service service;
+
+ public Axis2ServiceInOutAsyncMessageReceiver(Axis2Service service,
+ Operation operation,
+ WorkContext workContext) {
+ this.operation = operation;
+ this.workContext = workContext;
+ this.service = service;
+ }
+
+ public Axis2ServiceInOutAsyncMessageReceiver() {
+ }
+
+ public final void receive(final MessageContext messageCtx) {
+ try {
+ // Create a new message id and hand it to
+ // JDKInboundInvocationHandler
+ // via work context
+ MessageId messageId = new MessageId();
+ workContext.setCurrentMessageId(messageId);
+ // Now use message id as index to context to be used by callback
+ // target invoker
+ CountDownLatch doneSignal = new CountDownLatch(1);
+ InvocationContext invCtx =
+ service.new InvocationContext(messageCtx, operation, getSOAPFactory(messageCtx), doneSignal);
+ service.addMapping(messageId, invCtx);
+
+ invokeBusinessLogic(messageCtx);
+
+ try {
+ doneSignal.await();
+ } catch(InterruptedException e) {
+ e.printStackTrace();
+ }
+ } catch (AxisFault e) {
+ // log.error(e);
+ }
+ }
+
+ public void invokeBusinessLogic(MessageContext inMC) throws AxisFault {
+ try {
+ OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement();
+ Object[] args = new Object[] {requestOM};
+ service.invokeTarget(operation, args);
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getCause();
+ if (t instanceof Exception) {
+ throw AxisFault.makeFault((Exception)t);
+ }
+ throw new InvocationRuntimeException(e);
+ } catch (Exception e) {
+ throw AxisFault.makeFault(e);
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java
new file mode 100644
index 0000000000..4522632d9f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java
@@ -0,0 +1,73 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver;
+import org.apache.tuscany.spi.model.Operation;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+
+public class Axis2ServiceInOutSyncMessageReceiver extends AbstractInOutSyncMessageReceiver {
+
+ protected Operation<?> operation;
+
+ private Axis2Service axis2Service;
+
+ public Axis2ServiceInOutSyncMessageReceiver(Axis2Service service, Operation<?> operation) {
+ this.axis2Service = service;
+ this.operation = operation;
+ }
+
+ public Axis2ServiceInOutSyncMessageReceiver() {
+
+ }
+
+ @Override
+ public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault {
+ try {
+ OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement();
+ Object[] args = new Object[] {requestOM};
+
+ OMElement responseOM = (OMElement)axis2Service.invokeTarget(operation, args);
+
+ SOAPEnvelope soapEnvelope = getSOAPFactory(inMC).getDefaultEnvelope();
+ soapEnvelope.getBody().addChild(responseOM);
+ outMC.setEnvelope(soapEnvelope);
+ outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE);
+
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ Throwable t = e.getCause();
+ if (t instanceof Exception) {
+ throw AxisFault.makeFault((Exception)t);
+ }
+ throw new InvocationRuntimeException(e);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw AxisFault.makeFault(e);
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceServlet.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceServlet.java
new file mode 100644
index 0000000000..cab5b28ee7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2ServiceServlet.java
@@ -0,0 +1,207 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.transport.http.AxisServlet;
+
+/**
+ * This overrides the servlet init of the AxisServlet so Tuscany can use
+ * a single Axis2 ConfigurationContext instance shared between AxisServlet
+ * instances for each SCA service with a ws binding.
+ * TODO: need to review if thats really what we want to be doing
+ */
+public class Axis2ServiceServlet extends AxisServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final ServletConfig DUMMY_CONFIG = createDummyServletConfig();
+
+ private boolean inited;
+
+ public void init(ConfigurationContext configContext) {
+ this.configContext = configContext;
+ try {
+ super.init(DUMMY_CONFIG);
+ } catch (ServletException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * We've setup the Servlet by passing in a ConfigurationContext on our init method
+ * override this method to just return that
+ */
+ @Override
+ protected ConfigurationContext initConfigContext(ServletConfig config) throws ServletException {
+ return this.configContext;
+ }
+
+ /**
+ * The AxisServlet gets NPE during init without a ServletConfig so this is a mocked up one to prevent that.
+ */
+ private static ServletConfig createDummyServletConfig() {
+ ServletConfig sc = new ServletConfig() {
+
+ public String getServletName() {
+ return "TuscanyAxis2DummyServlet";
+ }
+
+ public ServletContext getServletContext() {
+ return new ServletContext() {
+
+ public ServletContext getContext(String uripath) {
+ return null;
+ }
+
+ public int getMajorVersion() {
+ return 0;
+ }
+
+ public int getMinorVersion() {
+ return 0;
+ }
+
+ public String getMimeType(String file) {
+ return null;
+ }
+
+ public Set getResourcePaths(String path) {
+ return Collections.emptySet();
+ }
+
+ public URL getResource(String path) throws MalformedURLException {
+ if("/".equals(path)) {
+ // HACK: To avoid NPE
+ return new URL("/axis2");
+ }
+ return null;
+ }
+
+ public InputStream getResourceAsStream(String path) {
+ return null;
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path) {
+ return null;
+ }
+
+ public RequestDispatcher getNamedDispatcher(String arg0) {
+ return null;
+ }
+
+ public Servlet getServlet(String arg0) throws ServletException {
+ return null;
+ }
+
+ public Enumeration getServlets() {
+ return null;
+ }
+
+ public Enumeration getServletNames() {
+ return null;
+ }
+
+ public void log(String arg0) {
+ }
+
+ public void log(Exception arg0, String arg1) {
+ }
+
+ public void log(String arg0, Throwable arg1) {
+ }
+
+ public String getRealPath(String arg0) {
+ return null;
+ }
+
+ public String getServerInfo() {
+ return null;
+ }
+
+ public String getInitParameter(String arg0) {
+ return null;
+ }
+
+ public Enumeration getInitParameterNames() {
+ return null;
+ }
+
+ public Object getAttribute(String arg0) {
+ return null;
+ }
+
+ public Enumeration getAttributeNames() {
+ return null;
+ }
+
+ public void setAttribute(String arg0, Object arg1) {
+ }
+
+ public void removeAttribute(String arg0) {
+ }
+
+ public String getServletContextName() {
+ return null;
+ }
+ };
+ }
+
+ public String getInitParameter(String arg0) {
+ return null;
+ }
+
+ public Enumeration getInitParameterNames() {
+ return new Vector().elements();
+ }
+ };
+ return sc;
+ }
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ // HACK: Get the correct context root which is not available during init() call
+ if (!inited) {
+ synchronized (configContext) {
+ configContext.setContextRoot(request.getContextPath());
+ inited = true;
+ }
+ }
+ super.service(request, response);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java
new file mode 100755
index 0000000000..175f995c76
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/Axis2TargetInvoker.java
@@ -0,0 +1,136 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.OperationClient;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.tuscany.spi.wire.InvocationRuntimeException;
+import org.apache.tuscany.spi.wire.Message;
+import org.apache.tuscany.spi.wire.TargetInvoker;
+
+/**
+ * Axis2TargetInvoker uses an Axis2 OperationClient to invoke a remote web service
+ */
+public class Axis2TargetInvoker implements TargetInvoker {
+
+ private QName wsdlOperationName;
+
+ private Options options;
+
+ private SOAPFactory soapFactory;
+
+ private ServiceClient serviceClient;
+
+ public Axis2TargetInvoker(ServiceClient serviceClient, QName wsdlOperationName, Options options,
+ SOAPFactory soapFactory) {
+ this.wsdlOperationName = wsdlOperationName;
+ this.options = options;
+ this.soapFactory = soapFactory;
+ this.serviceClient = serviceClient;
+ }
+
+ /**
+ * Invoke a WS operation
+ *
+ * @param payload
+ * @return
+ * @throws InvocationTargetException
+ */
+ public Object invokeTarget(final Object payload) throws InvocationTargetException {
+ try {
+ Object[] args = (Object[]) payload;
+ OperationClient operationClient = createOperationClient(args);
+
+ operationClient.execute(true);
+
+ MessageContext responseMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ return responseMC.getEnvelope().getBody().getFirstElement();
+
+ } catch (AxisFault e) {
+ throw new InvocationTargetException(e);
+ }
+
+ }
+
+ protected OperationClient createOperationClient(Object[] args) throws AxisFault {
+ SOAPEnvelope env = soapFactory.getDefaultEnvelope();
+ if (args != null && args.length > 0) {
+ SOAPBody body = env.getBody();
+ for (Object bc : args) {
+ if (bc instanceof OMElement) {
+ body.addChild((OMElement) bc);
+ } else {
+ throw new IllegalArgumentException(
+ "Can't handle mixed payloads betweem OMElements and other types.");
+ }
+ }
+ }
+ MessageContext requestMC = new MessageContext();
+ requestMC.setEnvelope(env);
+ // Axis2 operationClients can not be shared so create a new one for each request
+ OperationClient operationClient = serviceClient.createClient(wsdlOperationName);
+ operationClient.setOptions(options);
+ operationClient.addMessageContext(requestMC);
+ return operationClient;
+ }
+
+ public Message invoke(Message msg) throws InvocationRuntimeException {
+ try {
+ Object resp = invokeTarget(msg.getBody());
+ msg.setBody(resp);
+ } catch (Throwable e) {
+ msg.setBodyWithFault(e);
+ }
+ return msg;
+ }
+
+ public Axis2TargetInvoker clone() throws CloneNotSupportedException {
+ try {
+ return (Axis2TargetInvoker) super.clone();
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ return null;
+ }
+ }
+
+ public boolean isCacheable() {
+ return true;
+ }
+
+ public void setCacheable(boolean cacheable) {
+
+ }
+
+ public boolean isOptimizable() {
+ return false;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBinding.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBinding.java
new file mode 100755
index 0000000000..6d4ec6eaf9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBinding.java
@@ -0,0 +1,78 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import org.apache.tuscany.spi.model.Binding;
+
+/**
+ * Represents a Celtix binding configuration in an assembly
+ *
+ * @version $Rev$ $Date$
+ */
+public class WebServiceBinding extends Binding {
+
+ private Definition definition;
+ private Port port;
+ private Service service;
+ //private String portURI;
+ private String uri;
+ public WebServiceBinding(Definition definition, Port port, String uri, String portURI, Service service) {
+ this.definition = definition;
+ this.port = port;
+ this.uri = uri;
+ //this.portURI = portURI;
+ this.service = service;
+ }
+
+ public Port getWSDLPort() {
+ return port;
+ }
+
+ public Service getWSDLService() {
+ return service;
+ }
+
+ public void setWSDLPort(Port value) {
+ port = value;
+ }
+
+ public Definition getWSDLDefinition() {
+ return definition;
+ }
+
+ public void setWSDLDefinition(Definition def) {
+ definition = def;
+ }
+
+ // public void setPortURI(String uri) {
+ // portURI = uri;
+ // }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String theUri) {
+ this.uri = theUri;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java
new file mode 100755
index 0000000000..5535dbb5c2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/WebServiceBindingLoader.java
@@ -0,0 +1,143 @@
+/*
+ * 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.tuscany.binding.axis2;
+
+import static org.osoa.sca.Version.XML_NAMESPACE_1_0;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.Service;
+import javax.wsdl.WSDLException;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.idl.wsdl.WSDLDefinitionRegistry;
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.osoa.sca.annotations.Constructor;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * Parses a <code>WebServiceBinding</code> entry in an assembly XML file
+ *
+ * @version $Rev$ $Date$
+ */
+@Scope("MODULE")
+@SuppressWarnings("deprecation")
+public class WebServiceBindingLoader extends LoaderExtension<WebServiceBinding> {
+ public static final QName BINDING_WS = new QName(XML_NAMESPACE_1_0, "binding.ws");
+
+ private WSDLDefinitionRegistry wsdlDefinitionRegistry;
+
+ @Constructor( { "loaderRegistry", "wsdlDefinitionRegistry" })
+ public WebServiceBindingLoader(@Autowire LoaderRegistry loaderRegistry,
+ @Autowire WSDLDefinitionRegistry wsdlDefinitionRegistry) {
+ super(loaderRegistry);
+ this.wsdlDefinitionRegistry = wsdlDefinitionRegistry;
+ }
+
+ public QName getXMLType() {
+ return BINDING_WS;
+ }
+
+ public WebServiceBinding load(CompositeComponent parent, XMLStreamReader reader, DeploymentContext deploymentContext)
+ throws XMLStreamException, LoaderException {
+ // not sure what uri was here ? String uri = reader.getAttributeValue(null, "uri");
+ String uri = null;
+ String endpoint = reader.getAttributeValue(null, "endpoint");
+ String wsdlLocation = reader.getAttributeValue(null, "location");
+ LoaderUtil.skipToEndElement(reader);
+ try {
+ return createBinding(uri, endpoint, wsdlLocation, deploymentContext);
+ } catch (Exception e) {
+ throw new LoaderException(e);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ private WebServiceBinding createBinding(String uri, String endpoint, String wsdlLocation, DeploymentContext deploymentContext)
+ throws WSDLException, IOException, LoaderException {
+ // Get the WSDL port namespace and name
+ if (uri == null && endpoint != null) {
+ int h = endpoint.indexOf('#');
+ String serviceName;
+ String portName;
+
+ String namespace = endpoint.substring(0, h);
+ String fragment = endpoint.substring(h + 1);
+ if (fragment.startsWith("wsdl.endpoint(") && fragment.endsWith(")")) {
+ fragment = fragment.substring(14, fragment.length() - 1);
+ int slash = fragment.indexOf('/');
+ if (slash != -1) {
+ serviceName = fragment.substring(0, slash);
+ portName = fragment.substring(slash + 1);
+ } else {
+ serviceName = null;
+ portName = fragment;
+ }
+ } else {
+ serviceName = null;
+ portName = fragment;
+ }
+ // FIXME need to find out how to get wsdl and what context to use --- terrible hack attack!
+ if (null == wsdlLocation) {
+ throw new Axis2BindingRunTimeException(
+ "Failed to determine wsdl location on binding. Try specifying 'location' attribute on binding.");
+ }
+ Definition definition =
+ wsdlDefinitionRegistry.loadDefinition(namespace+" "+wsdlLocation, deploymentContext.getClassLoader());
+
+ Port thePort = null;
+ Service service = null;
+ // Find the port with the given name
+ for (Service serv : (Collection<Service>) definition.getServices().values()) {
+ QName sqn = serv.getQName();
+ if (serviceName != null && !serviceName.equals(sqn.getLocalPart())) {
+ continue;
+ }
+
+ Port p = serv.getPort(portName);
+ if (p != null) {
+ service = serv;
+ thePort = p;
+ break;
+ }
+ }
+ if (thePort == null) {
+ throw new IllegalArgumentException("Cannot find WSDL port " + endpoint);
+
+ }
+ return new WebServiceBinding(definition, thePort, uri, endpoint, service);
+ }
+ // FIXME: Find the first port?
+ throw new LoaderException("Web Service endpoint cannot be resolved: " + endpoint);
+
+ }
+
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java
new file mode 100755
index 0000000000..c0ef46fee3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/TuscanyAxisConfigurator.java
@@ -0,0 +1,44 @@
+/*
+ * 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.tuscany.binding.axis2.util;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.deployment.URLBasedAxisConfigurator;
+import org.apache.axis2.engine.AxisConfigurator;
+
+/**
+ * Helps configure Axis2 from a resource in binding.axis2 instead of Axis2.xml
+ * <p/> TODO: Review: should there be a single global Axis
+ * ConfigurationContext
+ */
+public class TuscanyAxisConfigurator extends URLBasedAxisConfigurator implements AxisConfigurator {
+
+ public TuscanyAxisConfigurator() throws AxisFault {
+ super(TuscanyAxisConfigurator.class.getResource("/org/apache/tuscany/binding/axis2/engine/config/axis2.xml"), null);
+ }
+
+ public ConfigurationContext getConfigurationContext() throws AxisFault {
+ if (configContext == null)
+ configContext = ConfigurationContextFactory.createConfigurationContext(this);
+ return configContext;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java
new file mode 100755
index 0000000000..2a453bdf15
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServiceOperationMetaData.java
@@ -0,0 +1,491 @@
+/*
+ * 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.tuscany.binding.axis2.util;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import javax.wsdl.Binding;
+import javax.wsdl.BindingInput;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.BindingOutput;
+import javax.wsdl.Input;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.Output;
+import javax.wsdl.Part;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap.SOAPHeader;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.xml.namespace.QName;
+
+/**
+ * Metadata for a WSDL operation
+ */
+@SuppressWarnings({"all"})
+public class WebServiceOperationMetaData implements Serializable {
+ private static final long serialVersionUID = 2425306250256227724L;
+
+ // WSDL Binding and BindingOperation
+ private Binding binding;
+ private BindingOperation bindingOperation;
+ // Fields to cache derived metadata
+ private transient Set<Part> inputHeaderParts;
+ private transient Set<Part> outputHeaderParts;
+ private transient String style;
+ private transient String use;
+ private transient String soapAction;
+ private transient List<Object> signature;
+ private String encoding;
+ private transient QName rpcOperationName;
+
+ public WebServiceOperationMetaData(Binding binding, BindingOperation bindingOperation) {
+ this.binding = binding;
+ this.bindingOperation = bindingOperation;
+ }
+
+ public WebServiceOperationMetaData(Binding binding, BindingOperation bindingOperation, String style, String use,
+ String encoding,
+ String soapAction) {
+ this.binding = binding;
+ this.bindingOperation = bindingOperation;
+ this.style = style;
+ this.use = use;
+ this.encoding = encoding;
+ this.soapAction = soapAction;
+ }
+
+ public Set<Part> getInputHeaderParts() {
+ if (inputHeaderParts == null) {
+ // Build a set of header parts that we need to exclude
+ inputHeaderParts = new HashSet<Part>();
+ BindingInput bindingInput = bindingOperation.getBindingInput();
+
+ if (bindingInput != null) {
+ Operation operation = bindingOperation.getOperation();
+ javax.wsdl.Message message = operation.getInput().getMessage();
+ List elements = bindingInput.getExtensibilityElements();
+ for (Iterator i = elements.iterator(); i.hasNext();) {
+ Object extensibilityElement = i.next();
+ Part part = getPartFromSOAPHeader(message, extensibilityElement);
+ if (part != null) {
+ inputHeaderParts.add(part);
+ }
+ }
+ }
+ }
+ return inputHeaderParts;
+ }
+
+ public Set<Part> getOutputHeaderParts() {
+ if (outputHeaderParts == null) {
+ // Build a set of header parts that we need to exclude
+ outputHeaderParts = new HashSet<Part>();
+ BindingOutput bindingOutput = bindingOperation.getBindingOutput();
+
+ if (bindingOutput != null) {
+ Operation operation = bindingOperation.getOperation();
+ javax.wsdl.Message message = operation.getOutput().getMessage();
+ List elements = bindingOutput.getExtensibilityElements();
+ for (Iterator i = elements.iterator(); i.hasNext();) {
+ Object extensibilityElement = i.next();
+ Part part = getPartFromSOAPHeader(message, extensibilityElement);
+ if (part != null) {
+ outputHeaderParts.add(part);
+ }
+ }
+ }
+ }
+ return outputHeaderParts;
+ }
+
+ private Part getPartFromSOAPHeader(Message message, Object extensibilityElement) {
+ Part part = null;
+ if (extensibilityElement instanceof SOAPHeader) {
+ SOAPHeader soapHeader = (SOAPHeader) extensibilityElement;
+ QName msgName = soapHeader.getMessage();
+ if (message.getQName().equals(msgName)) {
+ part = message.getPart(soapHeader.getPart());
+ }
+ } else if (extensibilityElement instanceof SOAPHeader) {
+ SOAPHeader soapHeader = (SOAPHeader) extensibilityElement;
+ QName msgName = soapHeader.getMessage();
+ if (message.getQName().equals(msgName)) {
+ part = message.getPart(soapHeader.getPart());
+ }
+ }
+ return part;
+ }
+
+ public String getStyle() {
+ if (style == null) {
+ SOAPOperation soapOperation = (SOAPOperation) WebServicePortMetaData
+ .getExtensibilityElement(bindingOperation.getExtensibilityElements(),
+ SOAPOperation.class);
+ if (soapOperation != null) {
+ style = soapOperation.getStyle();
+ }
+ if (style == null) {
+ SOAPBinding soapBinding = WebServicePortMetaData
+ .getExtensibilityElement(binding.getExtensibilityElements(), SOAPBinding.class);
+ if (soapBinding != null) {
+ style = soapBinding.getStyle();
+ }
+ }
+ if (style == null) {
+ style = "document";
+ }
+ }
+ return style;
+ }
+
+ /**
+ * Returns the SOAP action for the given operation.
+ */
+ public String getSOAPAction() {
+ if (soapAction == null) {
+ final List wsdlBindingOperationExtensions = bindingOperation.getExtensibilityElements();
+ final SOAPOperation soapOp =
+ WebServicePortMetaData.getExtensibilityElement(wsdlBindingOperationExtensions, SOAPOperation.class);
+ if (soapOp != null) {
+ soapAction = soapOp.getSoapActionURI();
+ }
+ }
+ return soapAction;
+ }
+
+ public QName getRPCOperationName() {
+ if (rpcOperationName == null) {
+ javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(true);
+ String ns =
+ (soapBody != null) ? soapBody.getNamespaceURI() : binding.getPortType().getQName().getNamespaceURI();
+ String name = bindingOperation.getOperation().getName();
+ rpcOperationName = new QName(ns, name);
+ }
+ return rpcOperationName;
+ }
+
+ private List<String> getSOAPBodyParts(boolean input) {
+ javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(input);
+ if (soapBody != null) {
+ List parts = soapBody.getParts();
+ if (parts != null) {
+ List<String> names = new ArrayList<String>();
+ for (Iterator i = parts.iterator(); i.hasNext();) {
+ Object part = i.next();
+ if (part instanceof String) {
+ names.add((String) part);
+ } else if (part instanceof Part) {
+ names.add(((Part) part).getName());
+ }
+ }
+ return names;
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ private javax.wsdl.extensions.soap.SOAPBody getSOAPBody(boolean input) {
+ List elements = null;
+ if (input) {
+ BindingInput bindingInput = bindingOperation.getBindingInput();
+ if (bindingInput == null) {
+ return null;
+ }
+ elements = bindingInput.getExtensibilityElements();
+ } else {
+ BindingOutput bindingOutput = bindingOperation.getBindingOutput();
+ if (bindingOutput == null) {
+ return null;
+ }
+ elements = bindingOutput.getExtensibilityElements();
+ }
+ javax.wsdl.extensions.soap.SOAPBody soapBody = WebServicePortMetaData.getExtensibilityElement(elements,
+ javax.wsdl.extensions.soap.SOAPBody.class);
+ return soapBody;
+ }
+
+ /**
+ * Returns the use attribute
+ */
+ public String getUse() {
+ if (use == null) {
+ javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(true);
+ if (soapBody != null) {
+ use = soapBody.getUse();
+ }
+ if (use == null) {
+ use = "literal";
+ }
+ }
+ return use;
+ }
+
+ @SuppressWarnings("unchecked")
+ public String getEncoding() {
+ if (encoding == null) {
+ javax.wsdl.extensions.soap.SOAPBody soapBody = getSOAPBody(true);
+ if (soapBody != null) {
+ List<String> styles = (List<String>) soapBody.getEncodingStyles();
+ if (styles != null && !styles.isEmpty()) {
+ encoding = styles.get(0);
+ }
+ }
+ if (encoding == null) {
+ encoding = "";
+ }
+ }
+ return encoding;
+ }
+
+ public boolean isDocLitWrapped() {
+ boolean flag = getStyle().equals("document") && getUse().equals("literal");
+ if (!flag) {
+ return false;
+ }
+ Message msg = getMessage(true);
+ if (msg == null) {
+ return false;
+ }
+ List parts = msg.getOrderedParts(null);
+ if (parts.size() != 1) {
+ return false;
+ }
+ Part part = (Part) parts.get(0);
+ QName element = part.getElementName();
+ if (element == null) {
+ return false;
+ }
+ return element.getLocalPart().equals(bindingOperation.getOperation().getName());
+ }
+
+ /*
+ * public SOAPMediator createMediator(boolean serverMode) throws SOAPException {
+ * // create a new mediator for each invoke for thread-safety
+ * boolean rpcStyle = getStyle().equals("rpc"); boolean rpcEncoded = isEncoded();
+ *
+ * SOAPMediator mediator = null;
+ *
+ * if (!rpcStyle) { // Document mediator = new SOAPDocumentLiteralMediatorImpl(this, serverMode);
+ * } else { if (!rpcEncoded) mediator = new
+ * SOAPRPCLiteralMediatorImpl(this, serverMode); // RPC-literal else mediator =
+ * new SOAPRPCEncodedMediatorImpl(this, serverMode); // RPC-encoded }
+ * return mediator; }
+ */
+
+ /**
+ * Get the operation signature from the WSDL operation
+ */
+ public List<?> getOperationSignature() {
+ if (signature == null) {
+ signature = new ArrayList<Object>();
+
+ Operation operation = bindingOperation.getOperation();
+ if (operation == null) {
+ return signature;
+ }
+
+ final Input input = operation.getInput();
+ if (input == null) {
+ return signature;
+ }
+
+ String sstyle = getStyle();
+
+ if ("rpc".equals(sstyle)) {
+ Collection partNames = input.getMessage().getParts().values();
+ for (Iterator i = partNames.iterator(); i.hasNext();) {
+ Part part = (Part) i.next();
+ signature.add(part.getName());
+ }
+ } else {
+ /*
+ * WS-I Basic Profile 1.1 4.7.6 Operation Signatures Definition: operation signature
+ *
+ * The profile defines the "operation signature" to be the fully qualified name of the child element of
+ * SOAP body of the SOAP input
+ * message described by an operation in a WSDL binding.
+ *
+ * In the case of rpc-literal binding, the operation name is used as a wrapper for the part accessors.
+ * In the document-literal case, designed so that they meet this requirement.
+ *
+ * An endpoint that supports multiple operations must unambiguously identify the operation being
+ * invoked based on the input message
+ * that it receives. This is only possible if all the operations specified in the wsdl:binding
+ * associated with an endpoint have a
+ * unique operation signature.
+ *
+ * R2710 The operations in a wsdl:binding in a DESCRIPTION MUST result in operation signatures that are
+ * different from one another.
+ */
+ List<String> bodyParts = getSOAPBodyParts(true);
+
+ Collection<?> parts = input.getMessage().getParts().values();
+ // Exclude the parts to be transmitted in SOAP header
+ if (bodyParts == null) {
+ parts.removeAll(getInputHeaderParts());
+ }
+ for (Iterator i = parts.iterator(); i.hasNext();) {
+ Part part = (Part) i.next();
+ if (bodyParts == null) {
+ // All parts
+ QName elementName = part.getElementName();
+ if (elementName == null) {
+ elementName = new QName("", part.getName());
+ // TODO: [rfeng] throw new
+ // ServiceRuntimeException("Message part for
+ // document style must refer to an XSD element
+ // using a QName: " + part);
+ }
+ signature.add(elementName);
+ } else {
+ // "parts" in soap:body
+ if (bodyParts.contains(part.getName())) {
+ QName elementName = part.getElementName();
+ if (elementName == null) {
+ elementName = new QName("", part.getName());
+ // TODO: [rfeng] throw new
+ // ServiceRuntimeException("Message part for
+ // document style must refer to an XSD
+ // element using a QName: " + part);
+ }
+ signature.add(elementName);
+ }
+
+ }
+ }
+ }
+ }
+ return signature;
+ }
+
+ public Message getMessage(boolean isInput) {
+ Operation operation = bindingOperation.getOperation();
+ if (operation == null) {
+ return null;
+ }
+
+ if (isInput) {
+ final Input input = operation.getInput();
+ return input == null ? null : input.getMessage();
+ } else {
+ final Output output = operation.getOutput();
+ return output == null ? null : output.getMessage();
+ }
+ }
+
+ public Part getInputPart(int index) {
+ Part part = null;
+ Message message = getMessage(true);
+ if (message == null) {
+ return part;
+ }
+
+ List parts = message.getOrderedParts(null);
+ return (Part) parts.get(index);
+
+ }
+
+ public Part getOutputPart(int index) {
+ Part part = null;
+ Message message = getMessage(false);
+ if (message == null) {
+ return part;
+ }
+
+ List parts = message.getOrderedParts(null);
+ return (Part) parts.get(index);
+
+ }
+
+ /**
+ * Get a list of indexes for each part in the SOAP body
+ *
+ * @param isInput
+ */
+ public List<Integer> getBodyPartIndexes(boolean isInput) {
+ List<Integer> indexes = new ArrayList<Integer>();
+
+ Message message = getMessage(isInput);
+ if (message == null) {
+ return indexes;
+ }
+
+ List<String> bodyParts = getSOAPBodyParts(isInput);
+ List parts = message.getOrderedParts(null);
+ Set headerParts = isInput ? getInputHeaderParts() : getOutputHeaderParts();
+
+ int index = 0;
+ for (Iterator i = parts.iterator(); i.hasNext(); index++) {
+ Part part = (Part) i.next();
+ if (headerParts.contains(part)) {
+ continue;
+ }
+ if (bodyParts == null) {
+ // All parts
+ indexes.add(index);
+ } else {
+ // "parts" in soap:body
+ if (bodyParts.contains(part.getName())) {
+ indexes.add(index);
+ }
+ }
+ }
+ return indexes;
+ }
+
+ /**
+ * Get the corresponding index for a part in the SOAP header by element name
+ *
+ * @param elementName
+ * @param isInput
+ */
+ public int getHeaderPartIndex(QName elementName, boolean isInput) {
+
+ Message message = getMessage(isInput);
+ if (message == null) {
+ return -1;
+ }
+
+ List parts = message.getOrderedParts(null);
+ Set headerParts = isInput ? getInputHeaderParts() : getOutputHeaderParts();
+
+ int index = 0;
+ for (Iterator i = parts.iterator(); i.hasNext(); index++) {
+ Part part = (Part) i.next();
+ // Test if the part is in header section
+ if (headerParts.contains(part) && elementName.equals(part.getElementName())) {
+ return index;
+ }
+ }
+ return -1;
+ }
+
+ public BindingOperation getBindingOperation() {
+ return bindingOperation;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java
new file mode 100755
index 0000000000..a8d4f0f581
--- /dev/null
+++ b/sca-java-1.x/branches/sca-java-M2/sca/services/bindings/binding.axis2/src/main/java/org/apache/tuscany/binding/axis2/util/WebServicePortMetaData.java
@@ -0,0 +1,377 @@
+/*
+ * 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.tuscany.binding.axis2.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Definition;
+import javax.wsdl.Operation;
+import javax.wsdl.Port;
+import javax.wsdl.PortType;
+import javax.wsdl.Service;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.idl.wsdl.WSDLServiceContract;
+
+/**
+ * Metadata for a WSDL port
+ *
+ */
+public class WebServicePortMetaData {
+
+ private Service wsdlService;
+ private QName wsdlServiceName;
+ private Port wsdlPort;
+ private Binding wsdlBinding;
+ private QName wsdlPortName;
+ private PortType wsdlPortType;
+ private QName wsdlPortTypeName;
+ private String endpoint;
+ private boolean managed;
+ private List<WebServiceOperationMetaData> allOperationMetaData;
+ private WSDLServiceContract interfaceType;
+
+ /**
+ * Constructor
+ *
+ * @param wsdlDefinition
+ */
+ public WebServicePortMetaData(Definition wsdlDefinition, Port wsdlPort, String endpoint, boolean managed) {
+
+ // Lookup the named port
+ this.wsdlPort = wsdlPort;
+ wsdlPortName = new QName(wsdlDefinition.getTargetNamespace(), wsdlPort.getName());
+ Collection services = wsdlDefinition.getServices().values();
+ for (Object serviceObj : services) {
+ Service service = (Service) serviceObj;
+ if (service.getPorts().containsValue(wsdlPort)) {
+ wsdlService = service;
+ wsdlServiceName = service.getQName();
+ break;
+ }
+ }
+
+ // Save the binding
+ wsdlBinding = wsdlPort.getBinding();
+ if (wsdlBinding == null) {
+ throw new IllegalArgumentException("WSDL binding cannot be found for " + wsdlPortName);
+ }
+
+ // Save the portType
+ wsdlPortType = wsdlBinding.getPortType();
+ if (wsdlPortType == null) {
+ throw new IllegalArgumentException("WSDL portType cannot be found for " + wsdlPortName);
+ }
+ wsdlPortTypeName = wsdlPortType.getQName();
+
+ // Save the endpoint
+ this.endpoint = endpoint;
+
+ // Track if this endpoint is managed or not
+ this.managed = managed;
+ }
+
+ /**
+ * Constructor
+ *
+ * @param serviceName
+ * @param portName
+ * @param portTypeName
+ * @param endpoint
+ */
+ public WebServicePortMetaData(QName serviceName, String portName, QName portTypeName, String endpoint) {
+ wsdlServiceName = serviceName;
+ wsdlPortName = new QName(serviceName.getNamespaceURI(), portName);
+ wsdlPortTypeName = portTypeName;
+ this.endpoint = endpoint;
+ }
+
+ /**
+ * @return Returns the wsdlPort.
+ */
+ public javax.wsdl.Port getPort() {
+ return wsdlPort;
+ }
+
+ /**
+ * @return Returns the wsdlService.
+ */
+ public QName getServiceName() {
+ return wsdlServiceName;
+ }
+
+ /**
+ * @return Returns the wsdlService.
+ */
+ public javax.wsdl.Service getService() {
+ return wsdlService;
+ }
+
+ /**
+ * @return Returns the wsdlPortType.
+ */
+ public PortType getPortType() {
+ return wsdlPortType;
+ }
+
+ /**
+ * @return Returns the wsdlPortType.
+ */
+ public QName getPortTypeName() {
+ return wsdlPortTypeName;
+ }
+
+ /**
+ * @return Returns the wsdlBinding.
+ */
+ public Binding getBinding() {
+ return wsdlBinding;
+ }
+
+ /**
+ * @return Returns the wsdlPortName.
+ */
+ public QName getPortName() {
+ return wsdlPortName;
+ }
+
+ /**
+ * Returns the endpoint of a given port.
+ */
+ public String getEndpoint() {
+
+ // Return the specified endpoint
+ if (endpoint != null) {
+ return endpoint;
+ }
+
+ // Find the target endpoint on the port
+ if (wsdlPort != null) {
+ final List wsdlPortExtensions = wsdlPort.getExtensibilityElements();
+ for (final Object extension : wsdlPortExtensions) {
+ if (extension instanceof SOAPAddress) {
+ return ((SOAPAddress) extension).getLocationURI();
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the SOAP binding style.
+ */
+ public String getStyle() {
+
+ // Find the binding style
+ String style = null;
+ if (wsdlBinding != null) {
+ final List wsdlBindingExtensions = wsdlBinding.getExtensibilityElements();
+ SOAPBinding soapBinding = getExtensibilityElement(wsdlBindingExtensions, SOAPBinding.class);
+ if (soapBinding != null) {
+ style = soapBinding.getStyle();
+ }
+ }
+
+ // Default to document
+ return (style == null) ? "document" : style;
+ }
+
+ /**
+ * Returns the use attribute
+ */
+ public String getUse() {
+ List<WebServiceOperationMetaData> list = getAllOperationMetaData();
+ return list.get(0).getUse();
+ }
+
+ /**
+ * Returns the encoding attribute
+ */
+ public String getEncoding() {
+ List<WebServiceOperationMetaData> list = getAllOperationMetaData();
+ return list.get(0).getEncoding();
+ }
+
+ /**
+ * @return Returns true if this is a managed web service.
+ */
+ public boolean isManaged() {
+ return managed;
+ }
+
+ /**
+ * Returns the first extensibility element of the given type.
+ *
+ * @param elements
+ * @param type
+ */
+ public static <T> T getExtensibilityElement(List elements, Class<T> type) {
+ for (Object element : elements) {
+ if (type.isInstance(element)) {
+ return type.cast(element);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the extensibility elements of the given type.
+ *
+ * @param elements
+ * @param type
+ * @return List
+ */
+ public static <T> List<T> getExtensibilityElements(List elements, Class<T> type) {
+ List<T> result = new ArrayList<T>();
+ for (Object element : elements) {
+ if (type.isInstance(element)) {
+ result.add(type.cast(element));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get the operation signature from the SOAP Body
+ *
+ * @return A list of QNames
+ */
+ // public static List getOperationSignature(javax.xml.soap.SOAPBody body) {
+ // List signature = new ArrayList();
+ // for (Iterator i = body.getChildElements(); i.hasNext();) {
+ // Object child = i.next();
+ // if (child instanceof SOAPBodyElement) {
+ // Name name = ((SOAPBodyElement) child).getElementName();
+ // QName qname = new QName(name.getURI(), name.getLocalName(), name.getPrefix());
+ // signature.add(qname);
+ // }
+ // }
+ // return signature;
+ // }
+ // public static List getRPCOperationSignature(javax.xml.soap.SOAPBody body) {
+ // List signature = new ArrayList();
+ // for (Iterator i = body.getChildElements(); i.hasNext();) {
+ // Object child = i.next();
+ // if (child instanceof SOAPBodyElement) {
+ // SOAPBodyElement op = ((SOAPBodyElement) child);
+ // for (Iterator j = op.getChildElements(); j.hasNext();) {
+ // Object part = i.next();
+ // if (part instanceof SOAPElement) {
+ // SOAPElement p = (SOAPElement) part;
+ // signature.add(p.getLocalName());
+ // }
+ // }
+ // }
+ // }
+ // return signature;
+ // }
+ // public WebServiceOperationMetaData getOperationMetaData(javax.xml.soap.SOAPBody body) {
+ // List s1 = getOperationSignature(body);
+ // // List rpcParts = getRPCOperationSignature(body);
+ // for (Iterator it = getAllOperationMetaData().iterator(); it.hasNext();) {
+ // WebServiceOperationMetaData descriptor = (WebServiceOperationMetaData) it.next();
+ //
+ // String style = descriptor.getStyle();
+ //
+ // if (style.equals("document")) {
+ // List s2 = descriptor.getOperationSignature();
+ // if (s1.equals(s2))
+ // return descriptor;
+ // } else {
+ // QName op1 = (QName) s1.get(0);
+ // QName op2 = descriptor.getRPCOperationName();
+ // if (op1.equals(op2)) {
+ // /*
+ // * // FIXME: [rfeng] We don't support method overloading
+ // * List partNames = getOperationSignature(binding,
+ // * bindingOperation); if (rpcParts.equals(partNames))
+ // */
+ // return descriptor;
+ // }
+ // }
+ // }
+ // return null;
+ // }
+ public List<WebServiceOperationMetaData> getAllOperationMetaData() {
+ if (allOperationMetaData == null) {
+ allOperationMetaData = new ArrayList<WebServiceOperationMetaData>();
+ for (Iterator it = wsdlBinding.getBindingOperations().iterator(); it.hasNext();) {
+ final BindingOperation bindingOperation = (BindingOperation) it.next();
+ if (bindingOperation.getOperation() != null) {
+ allOperationMetaData.add(new WebServiceOperationMetaData(wsdlBinding, bindingOperation));
+ }
+ }
+ }
+ return allOperationMetaData;
+ }
+
+ public WebServiceOperationMetaData getOperationMetaData(String operationName) {
+ StringBuilder sb = new StringBuilder(operationName);
+ sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
+ String capatalizedOpName = sb.toString();
+
+ for (WebServiceOperationMetaData webServiceOperationMetaData : getAllOperationMetaData()) {
+ WebServiceOperationMetaData descriptor = (WebServiceOperationMetaData) webServiceOperationMetaData;
+ String opName = descriptor.getBindingOperation().getOperation().getName();
+
+ if (opName.equals(operationName) || opName.equals(capatalizedOpName)) {
+ return descriptor;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the WSDL service contract
+ *
+ * @return WSDLServiceContract
+ */
+ public WSDLServiceContract getInterfaceType() {
+ return interfaceType;
+ }
+
+ /**
+ * Get the WSDL operation name for a Java method name
+ */
+ public String getWSDLOperationName(String methodName) {
+ StringBuilder sb = new StringBuilder(methodName);
+ sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
+ String capatalizedOpName = sb.toString();
+ for (Object o : wsdlPortType.getOperations()) {
+ Operation operation = (Operation) o;
+ String wsdlOpName = operation.getName();
+ if (wsdlOpName.equals(methodName)) {
+ return wsdlOpName;
+ }
+ if (wsdlOpName.equals(capatalizedOpName)) {
+ return wsdlOpName;
+ }
+ }
+ return null;
+ }
+
+}