You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/07/20 23:23:54 UTC
svn commit: r558149 -
/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/
Author: rfeng
Date: Fri Jul 20 14:23:49 2007
New Revision: 558149
URL: http://svn.apache.org/viewvc?view=rev&rev=558149
Log:
Apply the patch from Simon Nash for TUSCANY-1469. Thanks\ you, Simon.
Added:
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceClient.java (with props)
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceProvider.java (with props)
Modified:
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingProviderFactory.java
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceBindingProvider.java
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceBindingProvider.java
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInMessageReceiver.java
incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java
Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingProviderFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingProviderFactory.java?view=diff&rev=558149&r1=558148&r2=558149
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingProviderFactory.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingProviderFactory.java Fri Jul 20 14:23:49 2007
@@ -45,7 +45,7 @@
}
public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, WebServiceBinding binding) {
- return new Axis2ReferenceBindingProvider(component, reference, binding, messageFactory);
+ return new Axis2ReferenceBindingProvider(component, reference, binding, servletHost, messageFactory);
}
public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, WebServiceBinding binding) {
Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceBindingProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceBindingProvider.java?view=diff&rev=558149&r1=558148&r2=558149
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceBindingProvider.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceBindingProvider.java Fri Jul 20 14:23:49 2007
@@ -1,20 +1,21 @@
-/**
- *
- * Copyright 2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-
package org.apache.tuscany.sca.binding.axis2;
import java.util.List;
@@ -39,6 +40,7 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.http.ServletHost;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.InvocationChain;
@@ -51,35 +53,57 @@
public class Axis2ReferenceBindingProvider implements ReferenceBindingProvider2 {
- private MessageFactory messageFactory;
private RuntimeComponent component;
private RuntimeComponentReference reference;
private WebServiceBinding wsBinding;
- private ConfigurationContext configContext;
- private ServiceClient serviceClient;
+ private ServletHost servletHost;
+ private MessageFactory messageFactory;
+ private Axis2ServiceClient axisClient;
+ private Axis2ServiceProvider axisProvider;
private WebServiceBinding callbackBinding;
+ //FIXME: following are only needed for the current tactical solutionn
+ private boolean tactical = true;
+ private ServiceClient serviceClient;
+
public Axis2ReferenceBindingProvider(RuntimeComponent component,
RuntimeComponentReference reference,
WebServiceBinding wsBinding,
+ ServletHost servletHost,
MessageFactory messageFactory) {
this.component = component;
this.reference = reference;
this.wsBinding = wsBinding;
+ this.servletHost = servletHost;
this.messageFactory = messageFactory;
- try {
- TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
- configContext = tuscanyAxisConfigurator.getConfigurationContext();
- } catch (AxisFault e) {
- throw new RuntimeException(e); // TODO: better exception
+ InterfaceContract contract = wsBinding.getBindingInterfaceContract();
+ if (contract == null) {
+ contract = reference.getInterfaceContract().makeUnidirectional(wsBinding.isCallback());
+ wsBinding.setBindingInterfaceContract(contract);
+ }
+
+ // Set to use the Axiom data binding
+ if (contract.getInterface() != null) {
+ contract.getInterface().setDefaultDataBinding(OMElement.class.getName());
+ }
+ if (contract.getCallbackInterface() != null) {
+ contract.getCallbackInterface().setDefaultDataBinding(OMElement.class.getName());
}
- initServiceClient();
+ // ??? following line was in Axis2BindingBuilder before the SPI changes
+ // and code reorg
+ //
+ // URI targetURI = wsBinding.getURI() != null ?
+ // URI.create(wsBinding.getURI()) : URI.create("foo");
+ //
+ // targetURI was passed to the ReferenceBindingExtension constructor and
+ // apparently was unused
+ // Do we still need a targetURI?
+
+ // wsBinding.setURI(component.getURI() + "#" + reference.getName());
- // FIXME: only needed for the current tactical solution
- // connect forward providers with matching callback providers
if (!wsBinding.isCallback()) {
// this is a forward binding, so look for a matching callback binding
if (reference.getCallback() != null) {
@@ -102,52 +126,33 @@
}
}
}
- }
- // FIXME: only needed for the current tactical solution
- public void setCallbackBinding(WebServiceBinding callbackBinding) {
- if (this.callbackBinding == null) {
- this.callbackBinding = callbackBinding;
+ if (tactical) {
+ if (!wsBinding.isCallback()) {
+ serviceClient = createServiceClient();
+ }
+ } else {
+ if (!wsBinding.isCallback()) {
+ axisClient = new Axis2ServiceClient(component, reference, wsBinding, servletHost,
+ messageFactory, callbackBinding);
+ } else {
+ axisProvider = new Axis2ServiceProvider(component, reference, wsBinding, servletHost,
+ messageFactory);
+ }
}
}
- public void initServiceClient() {
-
- InterfaceContract contract = wsBinding.getBindingInterfaceContract();
- if (contract == null) {
- contract = reference.getInterfaceContract().makeUnidirectional(wsBinding.isCallback());
- wsBinding.setBindingInterfaceContract(contract);
- }
-
- // Set to use the Axiom data binding
- if (contract.getInterface() != null) {
- contract.getInterface().setDefaultDataBinding(OMElement.class.getName());
- }
- if (contract.getCallbackInterface() != null) {
- contract.getCallbackInterface().setDefaultDataBinding(OMElement.class.getName());
+ protected void setCallbackBinding(WebServiceBinding callbackBinding) {
+ if (this.callbackBinding == null) {
+ this.callbackBinding = callbackBinding;
}
-
- // ??? following line was in Axis2BindingBuilder before the SPI changes
- // and code reorg
- //
- // URI targetURI = wsBinding.getURI() != null ?
- // URI.create(wsBinding.getURI()) : URI.create("foo");
- //
- // targetURI was passed to the ReferenceBindingExtension constructor and
- // apparently was unused
- // Do we still need a targetURI?
-
- // wsBinding.setURI(component.getURI() + "#" + reference.getName());
-
- // create an Axis2 ServiceClient
- serviceClient = createServiceClient();
}
- /**
- * Create an Axis2 ServiceClient
- */
+ //FIXME: only needed for the current tactical solution
protected ServiceClient createServiceClient() {
try {
+ TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
+ ConfigurationContext configContext = tuscanyAxisConfigurator.getConfigurationContext();
QName serviceQName = wsBinding.getServiceName();
String portName = wsBinding.getPortName();
Definition wsdlDefinition = wsBinding.getWSDLDefinition().getDefinition();
@@ -163,25 +168,45 @@
}
public void start() {
- // FIXME: only needed for the current tactical solution
- for (InvocationChain chain : reference.getRuntimeWire(wsBinding).getInvocationChains()) {
- Invoker tailInvoker = chain.getTailInvoker();
- if (tailInvoker instanceof Axis2AsyncBindingInvoker) {
- RuntimeWire callbackWire = reference.getRuntimeWire(callbackBinding);
- Operation callbackOperation = findCallbackOperation(callbackBinding.getBindingInterfaceContract());
- Axis2CallbackInvocationHandler invocationHandler
- = new Axis2CallbackInvocationHandler(messageFactory, callbackWire);
- Axis2ReferenceCallbackTargetInvoker callbackInvoker
- = new Axis2ReferenceCallbackTargetInvoker(callbackOperation, callbackWire, invocationHandler);
- ((Axis2AsyncBindingInvoker)tailInvoker).setCallbackTargetInvoker(callbackInvoker);
+ if (tactical) {
+ //FIXME: only needed for the current tactical solution
+ for (InvocationChain chain : reference.getRuntimeWire(wsBinding).getInvocationChains()) {
+ Invoker tailInvoker = chain.getTailInvoker();
+ if (tailInvoker instanceof Axis2AsyncBindingInvoker) {
+ RuntimeWire callbackWire = reference.getRuntimeWire(callbackBinding);
+ Operation callbackOperation = findCallbackOperation(callbackBinding.getBindingInterfaceContract());
+ Axis2CallbackInvocationHandler invocationHandler
+ = new Axis2CallbackInvocationHandler(messageFactory, callbackWire);
+ Axis2ReferenceCallbackTargetInvoker callbackInvoker
+ = new Axis2ReferenceCallbackTargetInvoker(callbackOperation, callbackWire, invocationHandler);
+ ((Axis2AsyncBindingInvoker)tailInvoker).setCallbackTargetInvoker(callbackInvoker);
+ }
+ }
+ } else {
+ if (!wsBinding.isCallback()) {
+ axisClient.start();
+ } else {
+ axisProvider.start();
}
}
}
public void stop() {
+ if (tactical) {
+ if (!wsBinding.isCallback()) {
+ closeAxis2Connections();
+ }
+ } else {
+ if (!wsBinding.isCallback()) {
+ axisClient.stop();
+ } else {
+ axisProvider.stop();
+ }
+ }
+ }
- // close all connections that we have initiated, so that the jetty
- // server
+ private void closeAxis2Connections() {
+ // close all connections that we have initiated, so that the jetty server
// can be restarted without seeing ConnectExceptions
HttpClient httpClient = (HttpClient)serviceClient.getServiceContext().getConfigurationContext()
.getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
@@ -207,7 +232,14 @@
}
public Invoker createInvoker(Operation operation) {
+ if (wsBinding.isCallback()) {
+ throw new RuntimeException("Cannot create invoker for a callback binding");
+ }
+ if (!tactical) {
+ return axisClient.createInvoker(operation);
+ }
+ //FIXME: remainder of this method's code only needed for the current tactical solution
Axis2BindingInvoker invoker;
if (reference.getInterfaceContract().getCallbackInterface() == null) {
@@ -233,6 +265,7 @@
return invoker;
}
+ //FIXME: only needed for the current tactical solution
private Operation findCallbackOperation(InterfaceContract contract) {
List callbackOperations = contract.getCallbackInterface().getOperations();
if (callbackOperations.size() != 1) {
@@ -242,6 +275,7 @@
return callbackOperation;
}
+ //FIXME: only needed for the current tactical solution
/**
* Create and configure an Axis2BindingInvoker for each operation
*/
@@ -278,6 +312,7 @@
return invoker;
}
+ //FIXME: only needed for the current tactical solution
protected EndpointReference getPortLocationEPR() {
String ep = wsBinding.getURI();
if (ep == null && wsBinding.getPort() != null) {
@@ -292,6 +327,7 @@
return new EndpointReference(ep);
}
+ //FIXME: only needed for the current tactical solution
protected String getSOAPAction(String operationName) {
Binding binding = wsBinding.getBinding();
if (binding != null) {
Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceBindingProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceBindingProvider.java?view=diff&rev=558149&r1=558148&r2=558149
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceBindingProvider.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceBindingProvider.java Fri Jul 20 14:23:49 2007
@@ -1,20 +1,21 @@
-/**
- *
- * Copyright 2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
-
package org.apache.tuscany.sca.binding.axis2;
import java.lang.reflect.InvocationTargetException;
@@ -65,10 +66,14 @@
private RuntimeComponentService service;
private WebServiceBinding wsBinding;
private ServletHost servletHost;
- private ConfigurationContext configContext;
private MessageFactory messageFactory;
- private Axis2ServiceBindingProvider callbackProvider;
+ private Axis2ServiceClient axisClient;
+ private Axis2ServiceProvider axisProvider;
+ //FIXME: following are only needed for the current tactical solutionn
+ private boolean tactical = true;
+ private ConfigurationContext configContext;
+ private Axis2ServiceBindingProvider callbackProvider;
// TODO: what to do about the base URI?
private static final String BASE_URI = "http://localhost:8080/";
@@ -84,11 +89,13 @@
this.servletHost = servletHost;
this.messageFactory = messageFactory;
- try {
- TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
- configContext = tuscanyAxisConfigurator.getConfigurationContext();
- } catch (AxisFault e) {
- throw new RuntimeException(e); // TODO: better exception
+ if (tactical) {
+ try {
+ TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
+ configContext = tuscanyAxisConfigurator.getConfigurationContext();
+ } catch (AxisFault e) {
+ throw new RuntimeException(e); // TODO: better exception
+ }
}
InterfaceContract contract = wsBinding.getBindingInterfaceContract();
@@ -105,73 +112,123 @@
contract.getCallbackInterface().setDefaultDataBinding(OMElement.class.getName());
}
- // FIXME: only needed for the current tactical solution
- // connect forward providers with matching callback providers
- if (!wsBinding.isCallback()) {
- // this is a forward binding, so look for a matching callback binding
- if (service.getCallback() != null) {
- for (Binding binding : service.getCallback().getBindings()) {
+ //FIXME: only needed for the current tactical solution
+ if (tactical) {
+ // connect forward providers with matching callback providers
+ if (!wsBinding.isCallback()) {
+ // this is a forward binding, so look for a matching callback binding
+ if (service.getCallback() != null) {
+ for (Binding binding : service.getCallback().getBindings()) {
+ if (service.getBindingProvider(binding) instanceof Axis2ServiceBindingProvider) {
+ // use the first compatible callback binding provider for this service
+ setCallbackProvider((Axis2ServiceBindingProvider)service.getBindingProvider(binding));
+ continue;
+ }
+ }
+ }
+ } else {
+ // this is a callback binding, so look for all matching forward bindings
+ for (Binding binding : service.getBindings()) {
if (service.getBindingProvider(binding) instanceof Axis2ServiceBindingProvider) {
- // use the first compatible callback binding provider for this service
- setCallbackProvider((Axis2ServiceBindingProvider)service.getBindingProvider(binding));
- continue;
+ // set all compatible forward binding providers for this service
+ ((Axis2ServiceBindingProvider)service.getBindingProvider(binding)).setCallbackProvider(this);
}
}
}
} else {
- // this is a callback binding, so look for all matching forward bindings
- for (Binding binding : service.getBindings()) {
- if (service.getBindingProvider(binding) instanceof Axis2ServiceBindingProvider) {
- // set all compatible forward binding providers for this service
- ((Axis2ServiceBindingProvider)service.getBindingProvider(binding)).setCallbackProvider(this);
- }
+ if (!wsBinding.isCallback()) {
+ axisProvider = new Axis2ServiceProvider(component, service, wsBinding, servletHost,
+ messageFactory);
+ } else {
+ // pass null as last parameter because SCDL doesn't allow a callback callback binding
+ // to be specified for a callback binding, i.e., can't have the following:
+ // <service>
+ // <binding.x/>
+ // <callback>
+ // <binding.y/>
+ // <callback>
+ // <binding.z/>
+ // </callback>
+ // </callback>
+ // </service>
+ // This means that you can't do a callback from a callback (at least not
+ // in s spec-compliant way).
+ axisClient = new Axis2ServiceClient(component, service, wsBinding, servletHost,
+ messageFactory, null);
}
}
}
- // FIXME: only needed for the current tactical solution
- public void setCallbackProvider(Axis2ServiceBindingProvider callbackProvider) {
+ //FIXME: only needed for the current tactical solution
+ protected void setCallbackProvider(Axis2ServiceBindingProvider callbackProvider) {
if (this.callbackProvider == null) {
this.callbackProvider = callbackProvider;
}
}
public void start() {
- if (!wsBinding.isCallback()) {
- String uri = computeActualURI(BASE_URI, component, service).normalize().toString();
- if (uri.endsWith("/")) {
- uri = uri.substring(0, uri.length() - 1);
+ if (tactical) {
+ if (!wsBinding.isCallback()) {
+ startAxis2Service();
+ }
+ } else {
+ if (!wsBinding.isCallback()) {
+ axisProvider.start();
+ } else {
+ axisClient.start();
}
- wsBinding.setURI(uri.toString());
+ }
+ }
- // TODO: if <binding.ws> specifies the wsdl service then should create a
- // service for every port
+ //FIXME: only needed for the current tactical solution
+ private void startAxis2Service() {
+ String uri = computeActualURI(BASE_URI, component, service).normalize().toString();
+ if (uri.endsWith("/")) {
+ uri = uri.substring(0, uri.length() - 1);
+ }
+ wsBinding.setURI(uri.toString());
- try {
- configContext.getAxisConfiguration().addService(createAxisService());
- } catch (AxisFault e) {
- throw new RuntimeException(e);
- }
+ // TODO: if <binding.ws> specifies the wsdl service then should create a
+ // service for every port
- Axis2ServiceServlet servlet = new Axis2ServiceServlet();
- servlet.init(configContext);
- String servletURI = wsBinding.getURI();
- configContext.setContextRoot(servletURI);
- servletHost.addServletMapping(servletURI, servlet);
+ try {
+ configContext.getAxisConfiguration().addService(createAxisService());
+ } catch (AxisFault e) {
+ throw new RuntimeException(e);
}
+
+ Axis2ServiceServlet servlet = new Axis2ServiceServlet();
+ servlet.init(configContext);
+ String servletURI = wsBinding.getURI();
+ configContext.setContextRoot(servletURI);
+ servletHost.addServletMapping(servletURI, servlet);
}
public void stop() {
- if (!wsBinding.isCallback()) {
- servletHost.removeServletMapping(wsBinding.getURI());
- try {
- configContext.getAxisConfiguration().removeService(wsBinding.getURI());
- } catch (AxisFault e) {
- throw new RuntimeException(e);
+ if (tactical) {
+ if (!wsBinding.isCallback()) {
+ stopAxis2Service();
+ }
+ } else {
+ if (!wsBinding.isCallback()) {
+ axisProvider.stop();
+ } else {
+ axisClient.stop();
}
}
}
+ //FIXME: only needed for the current tactical solution
+ private void stopAxis2Service() {
+ servletHost.removeServletMapping(wsBinding.getURI());
+ try {
+ configContext.getAxisConfiguration().removeService(wsBinding.getURI());
+ } catch (AxisFault e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ //FIXME: only needed for the current tactical solution
/**
* Compute the endpoint URI based on section 2.1.1 of the WS binding spec 1.
* The URIs in the endpoint(s) of the referenced WSDL, which may be relative
@@ -255,6 +312,7 @@
return URI.create(actualURI);
}
+ //FIXME: only needed for the current tactical solution
/**
* Returns the endpoint of a given port.
*/
@@ -270,6 +328,7 @@
return null;
}
+ //FIXME: only needed for the current tactical solution
private AxisService createAxisService() throws AxisFault {
AxisService axisService;
if (wsBinding.getWSDLDefinition() != null) {
@@ -281,6 +340,7 @@
return axisService;
}
+ //FIXME: only needed for the current tactical solution
/**
* Create an AxisService from the interface class from the SCA service interface
*/
@@ -301,6 +361,7 @@
return axisService;
}
+ //FIXME: only needed for the current tactical solution
/**
* Create an AxisService from the WSDL doc used by ws binding
*/
@@ -330,6 +391,7 @@
return axisService;
}
+ //FIXME: only needed for the current tactical solution
protected void initAxisOperations(AxisService axisService) {
for (Iterator i = axisService.getOperations(); i.hasNext();) {
AxisOperation axisOp = (AxisOperation)i.next();
@@ -355,6 +417,7 @@
}
}
+ //FIXME: only needed for the current tactical solution
protected Operation getOperation(AxisOperation axisOp) {
String operationName = axisOp.getName().getLocalPart();
for (Operation op : wsBinding.getBindingInterfaceContract().getInterface().getOperations()) {
@@ -370,12 +433,21 @@
}
public Invoker createCallbackInvoker(Operation operation) {
- return new Axis2ServiceCallbackTargetInvoker(this);
+ if (!wsBinding.isCallback()) {
+ throw new RuntimeException("Cannot create callback invoker for a forward binding");
+ }
+ if (tactical) {
+ return new Axis2ServiceCallbackTargetInvoker(this);
+ } else {
+ return axisClient.createInvoker(operation);
+ }
}
public boolean supportsAsyncOneWayInvocation() {
return true;
}
+
+ //FIXME: remaining code only needed for the current tactical solution
// methods for Axis2 message receivers
Added: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceClient.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceClient.java?view=auto&rev=558149
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceClient.java (added)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceClient.java Fri Jul 20 14:23:49 2007
@@ -0,0 +1,181 @@
+/*
+ * 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.sca.binding.axis2;
+
+import java.util.List;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Definition;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.extensions.soap.SOAPOperation;
+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.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.tuscany.sca.assembly.AbstractContract;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+import org.apache.tuscany.sca.http.ServletHost;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+public class Axis2ServiceClient {
+
+ private RuntimeComponent component;
+ private AbstractContract contract; // not used currently
+ private WebServiceBinding wsBinding;
+ private ServletHost servletHost;
+ private MessageFactory messageFactory;
+ private ServiceClient serviceClient;
+ private WebServiceBinding callbackBinding;
+
+ public Axis2ServiceClient(RuntimeComponent component,
+ AbstractContract contract,
+ WebServiceBinding wsBinding,
+ ServletHost servletHost,
+ MessageFactory messageFactory,
+ WebServiceBinding callbackBinding) {
+ this.component = component;
+ this.contract = contract;
+ this.wsBinding = wsBinding;
+ this.servletHost = servletHost;
+ this.messageFactory = messageFactory;
+ this.callbackBinding = callbackBinding;
+
+ serviceClient = createServiceClient();
+ }
+
+ protected void start() {
+ }
+
+ /**
+ * Create an Axis2 ServiceClient
+ */
+ protected ServiceClient createServiceClient() {
+ try {
+ TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
+ ConfigurationContext configContext = tuscanyAxisConfigurator.getConfigurationContext();
+ QName serviceQName = wsBinding.getServiceName();
+ String portName = wsBinding.getPortName();
+ Definition wsdlDefinition = wsBinding.getWSDLDefinition().getDefinition();
+ AxisService axisService =
+ AxisService.createClientSideAxisService(wsdlDefinition, serviceQName, portName, new Options());
+
+ return new ServiceClient(configContext, axisService);
+ } catch (AxisFault e) {
+ throw new RuntimeException(e); // TODO: better exception
+ }
+ }
+
+ protected void stop() {
+ // close all connections that we have initiated, so that the jetty server
+ // can be restarted without seeing ConnectExceptions
+ HttpClient httpClient =
+ (HttpClient)serviceClient.getServiceContext().getConfigurationContext()
+ .getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
+ if (httpClient != null)
+ ((MultiThreadedHttpConnectionManager)httpClient.getHttpConnectionManager()).shutdown();
+ }
+
+ /**
+ * Create and configure an Axis2BindingInvoker for each operation
+ */
+ protected Invoker createInvoker(Operation operation) {
+ EndpointReference epTo = getPortLocationEPR(wsBinding);
+ if (epTo == null) {
+ org.apache.tuscany.sca.runtime.EndpointReference epr = ThreadMessageContext.getMessageContext().getTo();
+ if (epr != null) {
+ epTo = new EndpointReference(epr.getURI());
+ } else {
+ throw new RuntimeException("Unable to determine destination endpoint");
+ }
+ }
+
+ Options options = new Options();
+ options.setTo(epTo);
+ if (callbackBinding != null) {
+ options.setFrom(getPortLocationEPR(callbackBinding));
+ }
+ options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);
+
+ String operationName = operation.getName();
+
+ String soapAction = getSOAPAction(operationName);
+ if (soapAction != null && soapAction.length() > 1) {
+ options.setAction(soapAction);
+ }
+
+ options.setTimeOutInMilliSeconds(30 * 1000); // 30 seconds
+
+ SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
+ QName wsdlOperationQName = new QName(operationName);
+
+ Axis2BindingInvoker invoker;
+ if (operation.isNonBlocking()) {
+ invoker = new Axis2OneWayBindingInvoker(serviceClient, wsdlOperationQName, options, soapFactory);
+ } else {
+ invoker = new Axis2BindingInvoker(serviceClient, wsdlOperationQName, options, soapFactory);
+ }
+ return invoker;
+ }
+
+ protected EndpointReference getPortLocationEPR(WebServiceBinding binding) {
+ String ep = binding.getURI();
+ if (ep == null && binding.getPort() != null) {
+ List wsdlPortExtensions = binding.getPort().getExtensibilityElements();
+ for (final Object extension : wsdlPortExtensions) {
+ if (extension instanceof SOAPAddress) {
+ ep = ((SOAPAddress)extension).getLocationURI();
+ break;
+ }
+ }
+ }
+ return ep != null ? new EndpointReference(ep) : null;
+ }
+
+ protected String getSOAPAction(String operationName) {
+ Binding binding = wsBinding.getBinding();
+ if (binding != null) {
+ for (Object o : binding.getBindingOperations()) {
+ BindingOperation bop = (BindingOperation)o;
+ if (bop.getName().equalsIgnoreCase(operationName)) {
+ for (Object o2 : bop.getExtensibilityElements()) {
+ if (o2 instanceof SOAPOperation) {
+ return ((SOAPOperation)o2).getSoapActionURI();
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceClient.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInMessageReceiver.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInMessageReceiver.java?view=diff&rev=558149&r1=558148&r2=558149
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInMessageReceiver.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInMessageReceiver.java Fri Jul 20 14:23:49 2007
@@ -30,13 +30,22 @@
protected Operation operation;
- private Axis2ServiceBindingProvider provider;
+ private Axis2ServiceProvider provider;
- public Axis2ServiceInMessageReceiver(Axis2ServiceBindingProvider provider, Operation operation) {
+ public Axis2ServiceInMessageReceiver(Axis2ServiceProvider provider, Operation operation) {
this.provider = provider;
this.operation = operation;
}
+ //FIXME: only needed for the current tactical solution
+ private Axis2ServiceBindingProvider bindingProvider;
+
+ //FIXME: only needed for the current tactical solution
+ public Axis2ServiceInMessageReceiver(Axis2ServiceBindingProvider bindingProvider, Operation operation) {
+ this.bindingProvider = bindingProvider;
+ this.operation = operation;
+ }
+
public Axis2ServiceInMessageReceiver() {
}
@@ -46,10 +55,17 @@
try {
OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement();
Object[] args = new Object[] {requestOM};
- String conversationID = provider.isConversational() ? Axis2ServiceBindingProvider.getConversationID(inMC) : null;
-
- provider.invokeTarget(operation, args, null, conversationID);
-
+ //FIXME: remove tactical code
+ if (bindingProvider != null) {
+ String conversationID = bindingProvider.isConversational() ?
+ Axis2ServiceBindingProvider.getConversationID(inMC) : null;
+ bindingProvider.invokeTarget(operation, args, null, conversationID);
+ } else {
+ String conversationID = provider.isConversational() ?
+ Axis2ServiceProvider.getConversationID(inMC) : null;
+ String callbackAddress = inMC.getFrom() != null ? inMC.getFrom().getAddress() : null;
+ provider.invokeTarget(operation, args, null, conversationID, callbackAddress);
+ }
} catch (InvocationTargetException e) {
Throwable t = e.getCause();
if (t instanceof Exception) {
Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java?view=diff&rev=558149&r1=558148&r2=558149
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java Fri Jul 20 14:23:49 2007
@@ -32,25 +32,44 @@
protected Operation operation;
- private Axis2ServiceBindingProvider provider;
+ private Axis2ServiceProvider provider;
- public Axis2ServiceInOutSyncMessageReceiver() {
+ public Axis2ServiceInOutSyncMessageReceiver(Axis2ServiceProvider provider, Operation operation) {
+ this.provider = provider;
+ this.operation = operation;
}
- public Axis2ServiceInOutSyncMessageReceiver(Axis2ServiceBindingProvider provider, Operation operation) {
- this.provider = provider;
+ //FIXME: only needed for the current tactical solution
+ private Axis2ServiceBindingProvider bindingProvider;
+
+ //FIXME: only needed for the current tactical solution
+ public Axis2ServiceInOutSyncMessageReceiver(Axis2ServiceBindingProvider bindingProvider, Operation operation) {
+ this.bindingProvider = bindingProvider;
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};
- String conversationID = provider.isConversational() ? Axis2ServiceBindingProvider.getConversationID(inMC) : null;
-
- OMElement responseOM = (OMElement) provider.invokeTarget(operation, args, null, conversationID);
+ //FIXME: remove tactical code
+ OMElement responseOM = null;
+ if (bindingProvider != null) {
+ String conversationID = bindingProvider.isConversational() ?
+ Axis2ServiceBindingProvider.getConversationID(inMC) : null;
+ responseOM = (OMElement)bindingProvider.invokeTarget(operation, args, null, conversationID);
+ } else {
+ String conversationID = provider.isConversational() ?
+ Axis2ServiceProvider.getConversationID(inMC) : null;
+ String callbackAddress = inMC.getFrom() != null ? inMC.getFrom().getAddress() : null;
+ responseOM = (OMElement)provider.invokeTarget(operation, args, null, conversationID,
+ callbackAddress);
+ }
SOAPEnvelope soapEnvelope = getSOAPFactory(inMC).getDefaultEnvelope();
if(null != responseOM ){
Added: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceProvider.java?view=auto&rev=558149
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceProvider.java (added)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceProvider.java Fri Jul 20 14:23:49 2007
@@ -0,0 +1,447 @@
+/*
+ * 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.sca.binding.axis2;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Port;
+import javax.wsdl.extensions.soap.SOAPAddress;
+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.Constants;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.deployment.util.Utils;
+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.WSDL2Constants;
+import org.apache.axis2.description.WSDLToAxisServiceBuilder;
+import org.apache.axis2.engine.MessageReceiver;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.tuscany.sca.assembly.AbstractContract;
+import org.apache.tuscany.sca.binding.ws.WebServiceBinding;
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+import org.apache.tuscany.sca.core.runtime.EndpointReferenceImpl;
+import org.apache.tuscany.sca.http.ServletHost;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+public class Axis2ServiceProvider {
+
+ private RuntimeComponent component;
+ private AbstractContract contract;
+ private WebServiceBinding wsBinding;
+ private ServletHost servletHost;
+ private MessageFactory messageFactory;
+ private ConfigurationContext configContext;
+
+ // TODO: what to do about the base URI?
+ private static final String BASE_URI = "http://localhost:8080/";
+
+ public Axis2ServiceProvider(RuntimeComponent component,
+ AbstractContract contract,
+ WebServiceBinding wsBinding,
+ ServletHost servletHost,
+ MessageFactory messageFactory) {
+
+ this.component = component;
+ this.contract = contract;
+ this.wsBinding = wsBinding;
+ this.servletHost = servletHost;
+ this.messageFactory = messageFactory;
+
+ try {
+ TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator();
+ configContext = tuscanyAxisConfigurator.getConfigurationContext();
+ } catch (AxisFault e) {
+ throw new RuntimeException(e); // TODO: better exception
+ }
+
+ String uri = computeActualURI(BASE_URI, component, contract).normalize().toString();
+ if (uri.endsWith("/")) {
+ uri = uri.substring(0, uri.length() - 1);
+ }
+ wsBinding.setURI(uri.toString());
+ }
+
+ protected void start() {
+
+ // TODO: if <binding.ws> specifies the wsdl service then should create a
+ // service for every port
+
+ try {
+ configContext.getAxisConfiguration().addService(createAxisService());
+ } catch (AxisFault e) {
+ throw new RuntimeException(e);
+ }
+
+ Axis2ServiceServlet servlet = new Axis2ServiceServlet();
+ servlet.init(configContext);
+ String servletURI = wsBinding.getURI();
+ configContext.setContextRoot(servletURI);
+ System.out.println("adding servlet mapping for " + servletURI);
+ (new RuntimeException()).printStackTrace();
+ servletHost.addServletMapping(servletURI, servlet);
+ }
+
+ protected void stop() {
+ servletHost.removeServletMapping(wsBinding.getURI());
+ try {
+ configContext.getAxisConfiguration().removeService(wsBinding.getURI());
+ } catch (AxisFault e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Compute the endpoint URI based on section 2.1.1 of the WS binding spec 1.
+ * The URIs in the endpoint(s) of the referenced WSDL, which may be relative
+ * 2. The URI specified by the wsa:Address element of the
+ * wsa:EndpointReference, which may be relative 3. The explicitly stated URI
+ * in the "uri" attribute of the binding.ws element, which may be relative,
+ * 4. The implicit URI as defined by in section 1.7 in the SCA Assembly spec
+ * If the <binding.ws> has no wsdlElement but does have a uri attribute then
+ * the uri takes precidence over any implicitly used WSDL.
+ *
+ * @param parent
+ */
+ protected URI computeActualURI(String baseURI, RuntimeComponent component, AbstractContract contract) {
+
+ // TODO: support wsa:Address
+
+ URI wsdlURI = null;
+ if (wsBinding.getServiceName() != null && wsBinding.getBindingName() == null) {
+ // <binding.ws> explicitly points at a wsdl port, may be a relative
+ // URI
+ wsdlURI = getEndpoint(wsBinding.getPort());
+ }
+ if (wsdlURI != null && wsdlURI.isAbsolute()) {
+ if (wsBinding.getURI() != null && (wsBinding.getServiceName() != null && wsBinding.getBindingName() == null)) {
+ throw new IllegalArgumentException("binding URI cannot be used with absolute WSDL endpoint URI");
+ }
+ return URI.create(wsdlURI.toString());
+ }
+
+ // either there is no wsdl port endpoint URI or that URI is relative
+
+ URI bindingURI = null;
+ if (wsBinding.getURI() != null) {
+ bindingURI = URI.create(wsBinding.getURI());
+ }
+ if (bindingURI != null && bindingURI.isAbsolute()) {
+ // there is an absoulte uri specified on the binding: <binding.ws
+ // uri="xxx"
+ if (wsdlURI != null) {
+ // there is a relative URI in the wsdl port
+ return URI.create(bindingURI + "/" + wsdlURI);
+ } else {
+ return bindingURI;
+ }
+ }
+
+ // both the WSDL endpoint and binding uri are either unspecified or
+ // relative so
+ // the endpoint is based on the component name and service binding URI
+
+ URI componentURI = URI.create(component.getName());
+
+ String actualURI;
+ if (componentURI.isAbsolute()) {
+ actualURI = componentURI.toString();
+ } else {
+ actualURI = baseURI + "/" + componentURI;
+ }
+
+ // with multiple services the default binding URI is the binding name
+ if (bindingURI == null && component.getServices().size() > 1) {
+ // if the binding doesn't have a name use the name of the service
+ // (assumption, not in spec)
+ if (wsBinding.getName() != null) {
+ bindingURI = URI.create(wsBinding.getName());
+ } else {
+ bindingURI = URI.create(contract.getName());
+ }
+ }
+
+ // add any relative binding URI
+ if (bindingURI != null) {
+ actualURI += "/" + bindingURI;
+ }
+
+ // add any relative WSDL port URI
+ if (wsdlURI != null) {
+ actualURI += "/" + wsdlURI.toString();
+ }
+
+ return URI.create(actualURI);
+ }
+
+ /**
+ * Returns the endpoint of a given port.
+ */
+ protected URI getEndpoint(Port wsdlPort) {
+ if (wsdlPort != null) {
+ List wsdlPortExtensions = wsdlPort.getExtensibilityElements();
+ for (Object extension : wsdlPortExtensions) {
+ if (extension instanceof SOAPAddress) {
+ return URI.create(((SOAPAddress)extension).getLocationURI());
+ }
+ }
+ }
+ return null;
+ }
+
+ private AxisService createAxisService() throws AxisFault {
+ AxisService axisService;
+ if (wsBinding.getWSDLDefinition() != null) {
+ axisService = createWSDLAxisService();
+ } else {
+ axisService = createJavaAxisService();
+ }
+ initAxisOperations(axisService);
+ return axisService;
+ }
+
+ /**
+ * Create an AxisService from the interface class from the SCA service
+ * interface
+ */
+ protected AxisService createJavaAxisService() throws AxisFault {
+ AxisService axisService = new AxisService();
+ String path = URI.create(wsBinding.getURI()).getPath();
+ axisService.setName(path);
+ axisService.setServiceDescription("Tuscany configured AxisService for service: " + wsBinding.getURI());
+ axisService.setClientSide(false);
+ Parameter classParam =
+ new Parameter(Constants.SERVICE_CLASS, ((JavaInterface)contract.getInterfaceContract().getInterface())
+ .getJavaClass().getName());
+ axisService.addParameter(classParam);
+ try {
+ Utils.fillAxisService(axisService, configContext.getAxisConfiguration(), null, null);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return axisService;
+ }
+
+ /**
+ * Create an AxisService from the WSDL doc used by ws binding
+ */
+ protected AxisService createWSDLAxisService() throws AxisFault {
+ Definition definition = wsBinding.getWSDLDefinition().getDefinition();
+
+ // WSDLToAxisServiceBuilder only uses the service and port to find the wsdl4J Binding
+ // An SCA service with binding.ws does not require a service or port so we may not have
+ // these but ...
+
+ WSDLToAxisServiceBuilder builder =
+ new WSDL11ToAxisServiceBuilder(definition, wsBinding.getServiceName(), wsBinding.getPortName());
+ builder.setServerSide(true);
+ AxisService axisService = builder.populateService();
+
+ String path = URI.create(wsBinding.getURI()).getPath();
+ axisService.setName(path);
+ axisService.setServiceDescription("Tuscany configured AxisService for service: " + wsBinding.getURI());
+
+ // 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);
+
+ return axisService;
+ }
+
+ protected void initAxisOperations(AxisService axisService) {
+ for (Iterator i = axisService.getOperations(); i.hasNext();) {
+ AxisOperation axisOp = (AxisOperation)i.next();
+ Operation op = getOperation(axisOp);
+ if (op != null) {
+
+ if (op.isNonBlocking()) {
+ axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_ONLY);
+ } else {
+ axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_OUT);
+ }
+
+ MessageReceiver msgrec = null;
+ if (op.isNonBlocking()) {
+ msgrec = new Axis2ServiceInMessageReceiver(this, op);
+ } else {
+ msgrec = new Axis2ServiceInOutSyncMessageReceiver(this, op);
+ }
+ axisOp.setMessageReceiver(msgrec);
+ }
+ }
+ }
+
+ protected Operation getOperation(AxisOperation axisOp) {
+ String operationName = axisOp.getName().getLocalPart();
+ Interface iface =
+ wsBinding.isCallback() ? wsBinding.getBindingInterfaceContract().getCallbackInterface() : wsBinding
+ .getBindingInterfaceContract().getInterface();
+ for (Operation op : iface.getOperations()) {
+ if (op.getName().equalsIgnoreCase(operationName)) {
+ return op;
+ }
+ }
+ return null;
+ }
+
+ // methods for Axis2 message receivers
+
+ /**
+ * @param inMC
+ * @return
+ */
+ protected static String getConversationID(MessageContext inMC) {
+ String conversationID = null;
+ Iterator i =
+ inMC.getEnvelope().getHeader()
+ .getChildrenWithName(new QName("http://www.w3.org/2005/08/addressing", "From"));
+ for (; i.hasNext();) {
+ Object a = i.next();
+ if (a instanceof OMElement) {
+ OMElement ao = (OMElement)a;
+ for (Iterator rpI =
+ ao.getChildrenWithName(new QName("http://www.w3.org/2005/08/addressing", "ReferenceParameters")); rpI
+ .hasNext();) {
+ OMElement rpE = (OMElement)rpI.next();
+ for (Iterator cidI = rpE.getChildrenWithName(Axis2BindingInvoker.CONVERSATION_ID_REFPARM_QN); cidI
+ .hasNext();) {
+ OMElement cidE = (OMElement)cidI.next();
+ conversationID = cidE.getText();
+ }
+ }
+
+ }
+
+ }
+ return conversationID;
+ }
+
+ public Object invokeTarget(Operation op,
+ Object[] args,
+ Object messageId,
+ String conversationID,
+ String callbackAddress) throws InvocationTargetException {
+
+ Message requestMsg = messageFactory.createMessage();
+
+ if (messageId != null) {
+ requestMsg.setMessageID(messageId);
+ }
+ requestMsg.setBody(args);
+
+ if (contract instanceof RuntimeComponentService)
+ requestMsg.setFrom(((RuntimeComponentService)contract).getRuntimeWire(wsBinding).getSource());
+ else
+ requestMsg.setFrom(((RuntimeComponentReference)contract).getRuntimeWire(wsBinding).getSource());
+ if (callbackAddress != null) {
+ requestMsg.setTo(new EndpointReferenceImpl(callbackAddress));
+ }
+
+ Message workContext = ThreadMessageContext.getMessageContext();
+
+ ThreadMessageContext.setMessageContext(requestMsg);
+ try {
+ if (isConversational() && conversationID != null) {
+ requestMsg.setConversationID(conversationID);
+ } else {
+ requestMsg.setConversationID(null);
+ }
+
+ Message responseMsg =
+ contract instanceof RuntimeComponentService ? ((RuntimeComponentService)contract).getInvoker(wsBinding,
+ op)
+ .invoke(requestMsg) : ((RuntimeComponentReference)contract).getInvoker(wsBinding, op)
+ .invoke(requestMsg);
+
+ if (responseMsg.isFault()) {
+ throw new InvocationTargetException((Throwable)responseMsg.getBody());
+ }
+ return responseMsg.getBody();
+
+ } finally {
+ ThreadMessageContext.setMessageContext(workContext);
+ }
+ }
+
+ public boolean isConversational() {
+ return wsBinding.getBindingInterfaceContract().getInterface().isConversational();
+ }
+
+ // methods for handling callbacks
+
+ private Map<Object, InvocationContext> invCtxMap = new HashMap<Object, InvocationContext>();
+
+ public void addMapping(Object msgId, InvocationContext invCtx) {
+ this.invCtxMap.put(msgId, invCtx);
+ }
+
+ public InvocationContext retrieveMapping(Object msgId) {
+ return this.invCtxMap.get(msgId);
+ }
+
+ public void removeMapping(Object msgId) {
+ this.invCtxMap.remove(msgId);
+ }
+
+ protected class InvocationContext {
+ public MessageContext inMessageContext;
+
+ public Operation operation;
+
+ public SOAPFactory soapFactory;
+
+ public CountDownLatch doneSignal;
+
+ public InvocationContext(MessageContext messageCtx,
+ Operation operation,
+ SOAPFactory soapFactory,
+ CountDownLatch doneSignal) {
+ this.inMessageContext = messageCtx;
+ this.operation = operation;
+ this.soapFactory = soapFactory;
+ this.doneSignal = doneSignal;
+ }
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org