From bd33c63da2568e01cb428e953ece0e48c59a5ba1 Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 12 Feb 2010 16:20:01 +0000 Subject: Add the word Reference into the binding invoker class name git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@909481 13f79535-47bb-0310-9956-ffa450edef68 --- .../ws/axis2/Axis2ReferenceBindingProvider.java | 4 +- .../ws/axis2/provider/Axis2BindingInvoker.java | 172 --------------------- .../provider/Axis2ReferenceBindingInvoker.java | 172 +++++++++++++++++++++ 3 files changed, 174 insertions(+), 174 deletions(-) delete mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingInvoker.java create mode 100644 sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java (limited to 'sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding') diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java index 8a5aab0ac6..67ffcaebe7 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java @@ -57,7 +57,7 @@ import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.xml.Constants; import org.apache.tuscany.sca.binding.ws.axis2.transport.TransportReferenceInterceptor; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2BindingInvoker; +import org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2ReferenceBindingInvoker; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.InterfaceContract; @@ -248,7 +248,7 @@ public class Axis2ReferenceBindingProvider implements EndpointReferenceProvider options.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM, org.apache.axis2.Constants.VALUE_TRUE); } - return new Axis2BindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); + return new Axis2ReferenceBindingInvoker(endpointReference, serviceClient, wsdlOperationQName, options, soapFactory, wsBinding); /* if (operation.isNonBlocking()) { diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingInvoker.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingInvoker.java deleted file mode 100644 index dd5a49d4dd..0000000000 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2BindingInvoker.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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.ws.axis2.provider; - -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; - -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.axiom.soap.SOAPHeader; -import org.apache.axis2.AxisFault; -import org.apache.axis2.addressing.AddressingConstants; -import org.apache.axis2.addressing.EndpointReference; -import org.apache.axis2.addressing.EndpointReferenceHelper; -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.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.binding.ws.WebServiceBinding; -import org.apache.tuscany.sca.interfacedef.util.FaultException; -import org.apache.tuscany.sca.invocation.DataExchangeSemantics; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; - - -/** - * Axis2BindingInvoker creates an Axis2 OperationClient to pass down the - * binding chain - * - * @version $Rev$ $Date$ - */ -public class Axis2BindingInvoker implements Invoker, DataExchangeSemantics { - public static final QName QNAME_WSA_FROM = - new QName(AddressingConstants.Final.WSA_NAMESPACE, - AddressingConstants.WSA_FROM, - AddressingConstants.WSA_DEFAULT_PREFIX); - - private RuntimeEndpointReference endpointReference; - private ServiceClient serviceClient; - private QName wsdlOperationName; - private Options options; - private SOAPFactory soapFactory; - private WebServiceBinding wsBinding; - - public Axis2BindingInvoker(RuntimeEndpointReference endpointReference, - ServiceClient serviceClient, - QName wsdlOperationName, - Options options, - SOAPFactory soapFactory, - WebServiceBinding wsBinding) { - this.endpointReference = endpointReference; - this.serviceClient = serviceClient; - this.wsdlOperationName = wsdlOperationName; - this.options = options; - this.soapFactory = soapFactory; - this.wsBinding = wsBinding; - } - - public Message invoke(Message msg) { - try { - final OperationClient operationClient = createOperationClient(msg); - msg.setBindingContext(operationClient); - msg = endpointReference.getBindingInvocationChain().getHeadInvoker().invoke(msg); - - } catch (AxisFault e) { - if (e.getDetail() != null ) { - FaultException f = new FaultException(e.getMessage(), e.getDetail(), e); - f.setFaultName(e.getDetail().getQName()); - msg.setFaultBody(f); - } else { - msg.setFaultBody(e); - } - } catch (Throwable e) { - msg.setFaultBody(e); - } - - return msg; - } - - @SuppressWarnings("deprecation") - protected OperationClient createOperationClient(Message msg) throws AxisFault { - SOAPEnvelope env = soapFactory.getDefaultEnvelope(); - Object[] args = (Object[])msg.getBody(); - 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 between OMElements and other types."); - } - } - } - final MessageContext requestMC = new MessageContext(); - requestMC.setEnvelope(env); - - // Axis2 operationClients can not be shared so create a new one for each request - final OperationClient operationClient = serviceClient.createClient(wsdlOperationName); - operationClient.setOptions(options); - - Endpoint callbackEndpoint = msg.getFrom().getCallbackEndpoint(); - - // add WS-Addressing header - //FIXME: is there any way to use the Axis2 addressing support for this? - if (callbackEndpoint != null) { - EndpointReference fromEPR = new EndpointReference(callbackEndpoint.getURI()); - SOAPEnvelope sev = requestMC.getEnvelope(); - SOAPHeader sh = sev.getHeader(); - OMElement epr = - EndpointReferenceHelper.toOM(sev.getOMFactory(), - fromEPR, - QNAME_WSA_FROM, - AddressingConstants.Final.WSA_NAMESPACE); - sh.addChild(epr); - requestMC.setFrom(fromEPR); - } - - // if target endpoint was not specified when this invoker was created, - // use dynamically specified target endpoint passed in on this call - if (options.getTo() == null) { - Endpoint ep = msg.getTo(); - if (ep != null) { - requestMC.setTo(new EndpointReference(ep.getBinding().getURI())); - } else { - throw new RuntimeException("Unable to determine destination endpoint"); - } - } else { - requestMC.setTo(new EndpointReference(options.getTo().getAddress())); - } - - // Allow privileged access to read properties. Requires PropertiesPermission read in - // security policy. - try { - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws AxisFault { - operationClient.addMessageContext(requestMC); - return null; - } - }); - } catch (PrivilegedActionException e) { - throw (AxisFault)e.getException(); - } - return operationClient; - } - - public boolean allowsPassByReference() { - return true; - } -} diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java new file mode 100644 index 0000000000..0117d2b2e7 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingInvoker.java @@ -0,0 +1,172 @@ +/* + * 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.ws.axis2.provider; + +import java.security.AccessController; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; + +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.axiom.soap.SOAPHeader; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.addressing.EndpointReferenceHelper; +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.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + + +/** + * Axis2BindingInvoker creates an Axis2 OperationClient to pass down the + * binding chain + * + * @version $Rev$ $Date$ + */ +public class Axis2ReferenceBindingInvoker implements Invoker, DataExchangeSemantics { + public static final QName QNAME_WSA_FROM = + new QName(AddressingConstants.Final.WSA_NAMESPACE, + AddressingConstants.WSA_FROM, + AddressingConstants.WSA_DEFAULT_PREFIX); + + private RuntimeEndpointReference endpointReference; + private ServiceClient serviceClient; + private QName wsdlOperationName; + private Options options; + private SOAPFactory soapFactory; + private WebServiceBinding wsBinding; + + public Axis2ReferenceBindingInvoker(RuntimeEndpointReference endpointReference, + ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory, + WebServiceBinding wsBinding) { + this.endpointReference = endpointReference; + this.serviceClient = serviceClient; + this.wsdlOperationName = wsdlOperationName; + this.options = options; + this.soapFactory = soapFactory; + this.wsBinding = wsBinding; + } + + public Message invoke(Message msg) { + try { + final OperationClient operationClient = createOperationClient(msg); + msg.setBindingContext(operationClient); + msg = endpointReference.getBindingInvocationChain().getHeadInvoker().invoke(msg); + + } catch (AxisFault e) { + if (e.getDetail() != null ) { + FaultException f = new FaultException(e.getMessage(), e.getDetail(), e); + f.setFaultName(e.getDetail().getQName()); + msg.setFaultBody(f); + } else { + msg.setFaultBody(e); + } + } catch (Throwable e) { + msg.setFaultBody(e); + } + + return msg; + } + + @SuppressWarnings("deprecation") + protected OperationClient createOperationClient(Message msg) throws AxisFault { + SOAPEnvelope env = soapFactory.getDefaultEnvelope(); + Object[] args = (Object[])msg.getBody(); + 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 between OMElements and other types."); + } + } + } + final MessageContext requestMC = new MessageContext(); + requestMC.setEnvelope(env); + + // Axis2 operationClients can not be shared so create a new one for each request + final OperationClient operationClient = serviceClient.createClient(wsdlOperationName); + operationClient.setOptions(options); + + Endpoint callbackEndpoint = msg.getFrom().getCallbackEndpoint(); + + // add WS-Addressing header + //FIXME: is there any way to use the Axis2 addressing support for this? + if (callbackEndpoint != null) { + EndpointReference fromEPR = new EndpointReference(callbackEndpoint.getURI()); + SOAPEnvelope sev = requestMC.getEnvelope(); + SOAPHeader sh = sev.getHeader(); + OMElement epr = + EndpointReferenceHelper.toOM(sev.getOMFactory(), + fromEPR, + QNAME_WSA_FROM, + AddressingConstants.Final.WSA_NAMESPACE); + sh.addChild(epr); + requestMC.setFrom(fromEPR); + } + + // if target endpoint was not specified when this invoker was created, + // use dynamically specified target endpoint passed in on this call + if (options.getTo() == null) { + Endpoint ep = msg.getTo(); + if (ep != null) { + requestMC.setTo(new EndpointReference(ep.getBinding().getURI())); + } else { + throw new RuntimeException("Unable to determine destination endpoint"); + } + } else { + requestMC.setTo(new EndpointReference(options.getTo().getAddress())); + } + + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws AxisFault { + operationClient.addMessageContext(requestMC); + return null; + } + }); + } catch (PrivilegedActionException e) { + throw (AxisFault)e.getException(); + } + return operationClient; + } + + public boolean allowsPassByReference() { + return true; + } +} -- cgit v1.2.3