Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 45099 invoked from network); 17 Apr 2008 17:38:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Apr 2008 17:38:24 -0000 Received: (qmail 71243 invoked by uid 500); 17 Apr 2008 17:38:23 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 71095 invoked by uid 500); 17 Apr 2008 17:38:22 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 71059 invoked by uid 500); 17 Apr 2008 17:38:22 -0000 Delivered-To: apmail-ws-axis2-cvs@ws.apache.org Received: (qmail 71052 invoked by uid 99); 17 Apr 2008 17:38:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Apr 2008 10:38:22 -0700 X-ASF-Spam-Status: No, hits=-1998.5 required=10.0 tests=ALL_TRUSTED,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Apr 2008 17:37:36 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CDF651A9832; Thu, 17 Apr 2008 10:37:48 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r649197 - in /webservices/axis2/trunk/java/modules: jaxws-integration/ jaxws-integration/test-resources/ jaxws-integration/test/org/apache/axis2/jaxws/provider/ jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/ jaxws-integr... Date: Thu, 17 Apr 2008 17:37:47 -0000 To: axis2-cvs@ws.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080417173748.CDF651A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gawor Date: Thu Apr 17 10:37:44 2008 New Revision: 649197 URL: http://svn.apache.org/viewvc?rev=649197&view=rev Log: try to find the real operation on the context when annonymous operation is used so that right wsa action (and other properties) are used (AXIS2-3742) Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/AddressingProviderTests.java (with props) webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/AddressingProvider.java (with props) webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/AddressingProvider.wsdl (with props) webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/MANIFEST.MF webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/DispatchOperationHandler.java (with props) Modified: webservices/axis2/trunk/java/modules/jaxws-integration/pom.xml webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml Modified: webservices/axis2/trunk/java/modules/jaxws-integration/pom.xml URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/pom.xml?rev=649197&r1=649196&r2=649197&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/pom.xml (original) +++ webservices/axis2/trunk/java/modules/jaxws-integration/pom.xml Thu Apr 17 10:37:44 2008 @@ -749,6 +749,20 @@ /> + + + + + + + + + + + + @@ -1329,6 +1343,7 @@ **/ParallelAsyncTests.java **/SWAMTOMTests.java **/RuntimeExceptionsAsyncMepTest.java + **/AddressingProviderTests.java Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml?rev=649197&r1=649196&r2=649197&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml (original) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/axis2.xml Thu Apr 17 10:37:44 2008 @@ -181,6 +181,12 @@ + + + + + @@ -239,7 +245,12 @@ - + + + + + @@ -248,6 +259,12 @@ + + + + + " + + ""; + + static final String END_SOAP = ""; + + static final String XML_MESSAGE = "Hello"; + + static final String SOAP_MESSAGE_1 = START_SOAP + + "" + + XML_MESSAGE + + END_SOAP; + + static final String SOAP_MESSAGE_2 = START_SOAP + + "{0}{1}{2}" + + "" + + XML_MESSAGE + + END_SOAP; + + static final String ACTION = "http://addressing.provider.jaxws.axis2.apache.org/AddressingProviderInterface/In"; + + public static Test suite() { + return getTestSetup(new TestSuite(AddressingProviderTests.class), null, + "test-resources/axis2_addressing.xml"); + } + + /** + * Inject correct wsa header (wsa:Action must be set the the action of hello operation) + */ + public void testInjectAddressingHeaders() throws Exception { + + Dispatch dispatch = createDispatch(); + + String msg = SOAP_MESSAGE_1; + MessageFactory factory = MessageFactory.newInstance(); + SOAPMessage request = factory.createMessage(null, new ByteArrayInputStream(msg.getBytes())); + + SOAPMessage response = dispatch.invoke(request); + + assertResponseXML(response, "Hello Response"); + + System.out.println(response.toString()); + } + + /** + * Message already contains wsa headers. Make sure there is no mismatch between + * SOAPAction and wsa:Action. + */ + public void testWithAddressingHeaders() throws Exception { + + Dispatch dispatch = createDispatch(); + + String msg = MessageFormat.format(SOAP_MESSAGE_2, + endpointUrl, + "urn:" + UUID.randomUUID(), + ACTION); + + System.out.println(msg); + + MessageFactory factory = MessageFactory.newInstance(); + SOAPMessage request = factory.createMessage(null, new ByteArrayInputStream(msg.getBytes())); + + SOAPMessage response = dispatch.invoke(request); + + assertResponseXML(response, "Hello Response"); + + System.out.println(response.toString()); + } + + private SOAPElement assertResponseXML(SOAPMessage msg, String expectedText) throws Exception { + assertTrue(msg != null); + SOAPBody body = msg.getSOAPBody(); + assertTrue(body != null); + + Node invokeElement = (Node) body.getFirstChild(); + assertTrue(invokeElement instanceof SOAPElement); + assertEquals("outMessage", invokeElement.getLocalName()); + + String text = invokeElement.getValue(); + + System.out.println("Received: " + text); + assertEquals("Found ("+ text + ") but expected (" + expectedText + ")", expectedText, text); + + return (SOAPElement) invokeElement; + } + + private Dispatch createDispatch() throws Exception { + URL wsdlURL = getWsdl(); + assertNotNull(wsdlURL); + Service svc = Service.create(wsdlURL, serviceName); + + WebServiceFeature[] wsf = {new AddressingFeature(true)}; + + Dispatch dispatch = + svc.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE, wsf); + + BindingProvider p = (BindingProvider) dispatch; + p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl); + + return dispatch; + } + + private URL getWsdl() throws Exception { + String wsdlLocation = "/test/org/apache/axis2/jaxws/provider/addressing/META-INF/AddressingProvider.wsdl"; + String baseDir = new File(System.getProperty("basedir",".")).getCanonicalPath(); + wsdlLocation = new File(baseDir + wsdlLocation).getAbsolutePath(); + File file = new File(wsdlLocation); + return file.toURL(); + } + +} Propchange: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/AddressingProviderTests.java ------------------------------------------------------------------------------ svn:eol-style = native Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/AddressingProvider.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/AddressingProvider.java?rev=649197&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/AddressingProvider.java (added) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/AddressingProvider.java Thu Apr 17 10:37:44 2008 @@ -0,0 +1,60 @@ +/* + * 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.axis2.jaxws.provider.addressing; + +import java.io.ByteArrayInputStream; + +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPMessage; +import javax.xml.ws.BindingType; +import javax.xml.ws.Provider; +import javax.xml.ws.Service; +import javax.xml.ws.ServiceMode; +import javax.xml.ws.WebServiceProvider; +import javax.xml.ws.soap.Addressing; +import javax.xml.ws.soap.SOAPBinding; +import javax.xml.ws.soap.SOAPFaultException; + +@WebServiceProvider(serviceName="AddressingProviderService", + targetNamespace="http://addressing.provider.jaxws.axis2.apache.org", + wsdlLocation="META-INF/AddressingProvider.wsdl", + portName="AddressingProviderPort") +@BindingType(SOAPBinding.SOAP11HTTP_BINDING) +@Addressing(enabled=true) +@ServiceMode(value=Service.Mode.MESSAGE) +public class AddressingProvider implements Provider { + + String responseMsgStart = ""; + String responseMsgEnd = ""; + String XML_RETURN = "Hello Response"; + + public SOAPMessage invoke(SOAPMessage soapMessage) throws SOAPFaultException { + try { + MessageFactory factory = MessageFactory.newInstance(); + String responseXML = responseMsgStart + XML_RETURN + responseMsgEnd; + SOAPMessage response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes())); + + return response; + } catch(Exception e){ + e.printStackTrace(); + } + return null; + } +} Propchange: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/AddressingProvider.java ------------------------------------------------------------------------------ svn:eol-style = native Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/AddressingProvider.wsdl URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/AddressingProvider.wsdl?rev=649197&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/AddressingProvider.wsdl (added) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/AddressingProvider.wsdl Thu Apr 17 10:37:44 2008 @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Propchange: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/AddressingProvider.wsdl ------------------------------------------------------------------------------ svn:eol-style = native Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/MANIFEST.MF URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/MANIFEST.MF?rev=649197&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/MANIFEST.MF (added) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/provider/addressing/META-INF/MANIFEST.MF Thu Apr 17 10:37:44 2008 @@ -0,0 +1 @@ +Manifest-Version: 1.0 \ No newline at end of file Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/DispatchOperationHandler.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/DispatchOperationHandler.java?rev=649197&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/DispatchOperationHandler.java (added) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/DispatchOperationHandler.java Thu Apr 17 10:37:44 2008 @@ -0,0 +1,86 @@ +/* + * 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.axis2.jaxws.client.dispatch; + +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.axis2.AxisFault; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.AxisOperation; +import org.apache.axis2.description.AxisService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/* + * In JAX-WS Dispatch clients we don't know what actual operation we are calling + * until the message is converted to a SOAP envelope. So let's try to find the real + * operation based on the first element in the body in order to send the right WSA + * action. + * + * This handler should be installed in OutFlow chain. + */ +public class DispatchOperationHandler extends org.apache.axis2.handlers.AbstractHandler { + + private static final Log LOG = LogFactory.getLog(DispatchOperationHandler.class); + + private boolean isAnonymousOperation(AxisOperation op) { + return (ServiceClient.ANON_OUT_IN_OP.equals(op.getName()) || + ServiceClient.ANON_OUT_ONLY_OP.equals(op.getName())); + } + + private QName getFirstBodyElement(SOAPEnvelope envelope) { + SOAPBody body = envelope.getBody(); + if (body != null) { + OMElement firstElement = body.getFirstElement(); + if (firstElement != null) { + return firstElement.getQName(); + } + } + return null; + } + + private AxisOperation findRealOperationAction(MessageContext msgContext) { + AxisOperation axisOperation = null; + QName firstBodyElement = getFirstBodyElement(msgContext.getEnvelope()); + if (firstBodyElement != null) { + AxisService service = msgContext.getAxisService(); + axisOperation = service.getOperationByMessageElementQName(firstBodyElement); + } + return axisOperation; + } + + public InvocationResponse invoke(MessageContext msgContext) throws AxisFault { + AxisOperation op = msgContext.getAxisOperation(); + if (!msgContext.isServerSide() && op != null && isAnonymousOperation(op)) { + op = findRealOperationAction(msgContext); + if (op != null) { + msgContext.setAxisOperation(op); + if (LOG.isDebugEnabled()) { + LOG.debug("Anonymous operation detected. Replaced with real operation: " + op); + } + } + } + return InvocationResponse.CONTINUE; + } +} Propchange: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/dispatch/DispatchOperationHandler.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org For additional commands, e-mail: axis-cvs-help@ws.apache.org