Author: dims Date: Wed Mar 5 11:03:10 2008 New Revision: 633977 URL: http://svn.apache.org/viewvc?rev=633977&view=rev Log: Test case to ensure that certain message context properties mandated by the jaxws spec are populated.
PS: javax.xml.ws.handler.MessageContext.WSDL_DESCRIPTION is not populated correctly. Need to fix. Added: webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/wsdl/MessageContext.wsdl webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/META-INF/ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/META-INF/MessageContext.wsdl webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContext.java webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContextService.java webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java Modified: webservices/axis2/trunk/java/modules/jaxws-integration/pom.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=633977&r1=633976&r2=633977&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/pom.xml (original) +++ webservices/axis2/trunk/java/modules/jaxws-integration/pom.xml Wed Mar 5 11:03:10 2008 @@ -341,6 +341,13 @@ <classpath location="${compiled.classes.dir}"/> <arg line="-d ${schema.generated.src.dir} -quiet -wsdl ${wsdl.source.dir}/AnyType.wsdl"/> </java> + <echo>Generating java from MessageContext.wsdl for message context + properties support</echo> + <java classname="com.sun.tools.xjc.Driver" fork="true"> + <classpath refid="maven.runtime.classpath"/> + <classpath location="${compiled.classes.dir}"/> + <arg line="-d ${schema.generated.src.dir} -quiet -wsdl ${wsdl.source.dir}/MessageContext.wsdl"/> + </java> <echo>Generating java from WSDLMultiTests.wsdl</echo> <java classname="com.sun.tools.xjc.Driver" fork="true"> <classpath refid="maven.runtime.classpath"/> @@ -984,6 +991,22 @@ /> <delete dir="target/test-classes/servicejars/AnyTypeMessageService"/> + <copy toDir="target/test-classes/servicejars/MessageContextService/"> + <fileset dir="target/test-classes"> + <include name="org/apache/axis2/jaxws/context/**"/> + <exclude name="org/apache/axis2/jaxws/context/META-INF/services.xml"/> + </fileset> + <fileset dir="test/org/apache/axis2/jaxws/context"> + <include name="META-INF/**"/> + <exclude name="META-INF/services.xml"/> + </fileset> + </copy> + + <zip destfile="target/test-classes/servicejars/MessageContextService.jar" + basedir="${pom.basedir}/target/test-classes/servicejars/MessageContextService" + /> + <delete dir="target/test-classes/servicejars/MessageContextService"/> + <copy toDir="target/test-classes/servicejars/PolymorphicShapeService/"> <fileset dir="target/test-classes"> <include name="org/apache/axis2/jaxws/polymorphic/shape/**"/> @@ -1075,7 +1098,8 @@ <argLine>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006</argLine>--> <includes> - <!-- Possibly non-server tests --> + + <!-- Possibly non-server tests --> <include>**/MultiRedirectionCatalogTest.java</include> <include>**/DispatchSoapActionTest.java</include> <include>**/ProxySoapActionTest.java</include> @@ -1086,6 +1110,7 @@ <include>**/JAXBContextTest.java</include> <!-- Possible server tests --> + <include>**/MessageContextTests.java</include> <include>**/StringProviderTests.java</include> <include>**/SoapFaultProviderTests.java</include> <include>**/StringMessageProviderTests.java</include> Added: webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/wsdl/MessageContext.wsdl URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/wsdl/MessageContext.wsdl?rev=633977&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/wsdl/MessageContext.wsdl (added) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test-resources/wsdl/MessageContext.wsdl Wed Mar 5 11:03:10 2008 @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<definitions xmlns:tns="http://context.jaxws.axis2.apache.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/" + targetNamespace="http://context.jaxws.axis2.apache.org/" name="MessageContextService"> + <types> + <xs:schema xmlns:tns="http://context.jaxws.axis2.apache.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://context.jaxws.axis2.apache.org/" version="1.0"> + <!-- read the value of a property --> + <xs:element name="isPropertyPresent"> + <xs:complexType> + <xs:sequence> + <xs:element name="propertyName" type="xs:string"/> + <xs:element name="value" type="xs:string"/> + <xs:element name="type" type="xs:string"/> + <xs:element name="isFound" type="xs:boolean"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="isPropertyPresentResponse"> + <xs:complexType> + <xs:sequence> + <xs:element name="propertyName" type="xs:string"/> + <xs:element name="value" type="xs:string"/> + <xs:element name="type" type="xs:string"/> + <xs:element name="isFound" type="xs:boolean"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:schema> + </types> + <message name="isPropertyPresent"> + <part name="parameters" element="tns:isPropertyPresent"/> + </message> + <message name="isPropertyPresentResponse"> + <part name="parameters" element="tns:isPropertyPresentResponse"/> + </message> + <portType name="MessageContext"> + <operation name="isPropertyPresent"> + <input message="tns:isPropertyPresent"/> + <output message="tns:isPropertyPresentResponse"/> + </operation> + </portType> + <binding name="MessageContextPortBinding" type="tns:MessageContext"> + <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + <operation name="isPropertyPresent"> + <soap:operation/> + <input> + <soap:body use="literal"/> + </input> + <output> + <soap:body use="literal"/> + </output> + </operation> + </binding> + <service name="MessageContextService"> + <port name="MessageContextPort" binding="tns:MessageContextPortBinding"> + <soap:address location="http://localhost:6060/axis2/services/MessageContextService"/> + </port> + </service> +</definitions> Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/META-INF/MessageContext.wsdl URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/META-INF/MessageContext.wsdl?rev=633977&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/META-INF/MessageContext.wsdl (added) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/META-INF/MessageContext.wsdl Wed Mar 5 11:03:10 2008 @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<definitions xmlns:tns="http://context.jaxws.axis2.apache.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/" + targetNamespace="http://context.jaxws.axis2.apache.org/" name="MessageContextService"> + <types> + <xs:schema xmlns:tns="http://context.jaxws.axis2.apache.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://context.jaxws.axis2.apache.org/" version="1.0"> + <!-- read the value of a property --> + <xs:element name="isPropertyPresent"> + <xs:complexType> + <xs:sequence> + <xs:element name="propertyName" type="xs:string"/> + <xs:element name="value" type="xs:string"/> + <xs:element name="type" type="xs:string"/> + <xs:element name="isFound" type="xs:boolean"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="isPropertyPresentResponse"> + <xs:complexType> + <xs:sequence> + <xs:element name="propertyName" type="xs:string"/> + <xs:element name="value" type="xs:string"/> + <xs:element name="type" type="xs:string"/> + <xs:element name="isFound" type="xs:boolean"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:schema> + </types> + <message name="isPropertyPresent"> + <part name="parameters" element="tns:isPropertyPresent"/> + </message> + <message name="isPropertyPresentResponse"> + <part name="parameters" element="tns:isPropertyPresentResponse"/> + </message> + <portType name="MessageContext"> + <operation name="isPropertyPresent"> + <input message="tns:isPropertyPresent"/> + <output message="tns:isPropertyPresentResponse"/> + </operation> + </portType> + <binding name="MessageContextPortBinding" type="tns:MessageContext"> + <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + <operation name="isPropertyPresent"> + <soap:operation/> + <input> + <soap:body use="literal"/> + </input> + <output> + <soap:body use="literal"/> + </output> + </operation> + </binding> + <service name="MessageContextService"> + <port name="MessageContextPort" binding="tns:MessageContextPortBinding"> + <soap:address location="http://localhost:6060/axis2/services/MessageContextService"/> + </port> + </service> +</definitions> Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java?rev=633977&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java (added) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java Wed Mar 5 11:03:10 2008 @@ -0,0 +1,39 @@ +package org.apache.axis2.jaxws.context; + +import org.apache.axis2.jaxws.context.sei.MessageContext; + +import javax.annotation.Resource; +import javax.jws.WebService; +import javax.xml.ws.Holder; +import javax.xml.ws.WebServiceContext; + [EMAIL PROTECTED](serviceName="MessageContextService", + portName="MessageContextPort", + targetNamespace = "http://context.jaxws.axis2.apache.org/", + endpointInterface = "org.apache.axis2.jaxws.context.sei.MessageContext") +public class MessageContextImpl implements MessageContext { + + @Resource + WebServiceContext ctxt; + + public void isPropertyPresent( + Holder<String> propertyName, + Holder<String> value, + Holder<String> type, + Holder<Boolean> isFound) { + System.out.println(">> isPropertyPresent(" + propertyName.value + ")"); + javax.xml.ws.handler.MessageContext msgCtxt = ctxt.getMessageContext(); + if (msgCtxt != null) { + isFound.value = msgCtxt.containsKey(propertyName.value); + Object val = msgCtxt.get(propertyName.value); + System.out.println("msgCtxt.containsKey=" + isFound.value); + System.out.println("msgCtxt.get=" + val); + + if (val != null) { + type.value = val.getClass().getName(); + value.value = val.toString(); + } + } + System.out.println("<< isPropertyPresent()"); + } +} \ No newline at end of file Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContext.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContext.java?rev=633977&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContext.java (added) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContext.java Wed Mar 5 11:03:10 2008 @@ -0,0 +1,35 @@ +package org.apache.axis2.jaxws.context.sei; + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; +import javax.xml.ws.Holder; +import javax.xml.ws.RequestWrapper; +import javax.xml.ws.ResponseWrapper; + + [EMAIL PROTECTED](name = "MessageContext", + portName="MessageContextPort", + targetNamespace = "http://context.jaxws.axis2.apache.org/", + wsdlLocation = "META-INF/MessageContext.wsdl") +public interface MessageContext { + /** + * @param value + * @param type + * @param propertyName + * @param isFound + */ + @WebMethod + @RequestWrapper(localName = "isPropertyPresent", targetNamespace = "http://context.jaxws.axis2.apache.org/", className = "org.apache.axis2.jaxws.context.sei.IsPropertyPresent") + @ResponseWrapper(localName = "isPropertyPresentResponse", targetNamespace = "http://context.jaxws.axis2.apache.org/", className = "org.apache.axis2.jaxws.context.sei.IsPropertyPresentResponse") + public void isPropertyPresent( + @WebParam(name = "propertyName", targetNamespace = "", mode = WebParam.Mode.INOUT) + Holder<String> propertyName, + @WebParam(name = "value", targetNamespace = "", mode = WebParam.Mode.INOUT) + Holder<String> value, + @WebParam(name = "type", targetNamespace = "", mode = WebParam.Mode.INOUT) + Holder<String> type, + @WebParam(name = "isFound", targetNamespace = "", mode = WebParam.Mode.INOUT) + Holder<Boolean> isFound); + +} Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContextService.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContextService.java?rev=633977&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContextService.java (added) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/sei/MessageContextService.java Wed Mar 5 11:03:10 2008 @@ -0,0 +1,67 @@ +package org.apache.axis2.jaxws.context.sei; + +import javax.xml.namespace.QName; +import javax.xml.ws.Service; +import javax.xml.ws.WebEndpoint; +import javax.xml.ws.WebServiceClient; +import javax.xml.ws.WebServiceFeature; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Logger; + + [EMAIL PROTECTED](name = "MessageContextService", + targetNamespace = "http://context.jaxws.axis2.apache.org/", + wsdlLocation = "MessageContext.wsdl") +public class MessageContextService + extends Service { + + private final static URL MESSAGECONTEXTSERVICE_WSDL_LOCATION; + private final static Logger logger = Logger.getLogger(org.apache.axis2.jaxws.context.sei.MessageContextService.class.getName()); + + private static String wsdlLocation = "/test/org/apache/axis2/jaxws/context/META-INF/MessageContext.wsdl"; + + static { + URL url = null; + try { + try { + String baseDir = new File(System.getProperty("basedir", ".")).getCanonicalPath(); + wsdlLocation = new File(baseDir + wsdlLocation).getAbsolutePath(); + } catch (Exception e) { + e.printStackTrace(); + } + File file = new File(wsdlLocation); + url = file.toURL(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + MESSAGECONTEXTSERVICE_WSDL_LOCATION = url; + } + + public MessageContextService(URL wsdlLocation, QName serviceName) { + super(wsdlLocation, serviceName); + } + + public MessageContextService() { + super(MESSAGECONTEXTSERVICE_WSDL_LOCATION, new QName("http://context.jaxws.axis2.apache.org/", "MessageContextService")); + } + + /** + * @return returns MessageContext + */ + @WebEndpoint(name = "MessageContextPort") + public MessageContext getMessageContextPort() { + return super.getPort(new QName("http://context.jaxws.axis2.apache.org/", "MessageContextPort"), MessageContext.class); + } + + /** + * @param features A list of [EMAIL PROTECTED] javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values. + * @return returns MessageContext + */ + @WebEndpoint(name = "MessageContextPort") + public MessageContext getMessageContextPort(WebServiceFeature... features) { + return super.getPort(new QName("http://context.jaxws.axis2.apache.org/", "MessageContextPort"), MessageContext.class, features); + } + +} Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java?rev=633977&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java (added) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java Wed Mar 5 11:03:10 2008 @@ -0,0 +1,109 @@ +/* + * 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.context.tests; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.apache.axis2.jaxws.context.sei.MessageContext; +import org.apache.axis2.jaxws.context.sei.MessageContextService; +import org.apache.axis2.jaxws.framework.AbstractTestCase; + +import javax.xml.namespace.QName; +import javax.xml.ws.BindingProvider; +import javax.xml.ws.Holder; +import javax.xml.ws.WebServiceClient; + +public class MessageContextTests extends AbstractTestCase { + + static final WebServiceClient wsc = MessageContextService.class.getAnnotation(WebServiceClient.class); + + String axisEndpoint = "http://localhost:6060/axis2/services/MessageContextService.MessageContextPort"; + + public static Test suite() { + return getTestSetup(new TestSuite(MessageContextTests.class)); + } + + public void testWSCtxt_WSDL_SERVICE_read() { + String type_expected = QName.class.getName(); + String value_expected = "{" + wsc.targetNamespace() + "}" + wsc.name(); + runTest(javax.xml.ws.handler.MessageContext.WSDL_SERVICE, type_expected, value_expected, false); + } + + public void testWSCtxt_WSDL_PORT_read() { + String type_expected = QName.class.getName(); + String value_expected = "{" + wsc.targetNamespace() + "}MessageContextPort"; + runTest(javax.xml.ws.handler.MessageContext.WSDL_PORT, type_expected, value_expected, false); + } + + public void testWSCtxt_WSDL_OPERATION_read() { + String type_expected = QName.class.getName(); + String value_expected = "isPropertyPresent"; + runTest(javax.xml.ws.handler.MessageContext.WSDL_OPERATION, type_expected, value_expected, false); + } + + public void testWSCtxt_WSDL_INTERFACE_read() { + String type_expected = QName.class.getName(); + String value_expected = "{" + wsc.targetNamespace() + "}MessageContext"; + runTest(javax.xml.ws.handler.MessageContext.WSDL_INTERFACE, type_expected, value_expected, false); + } + +// FIXME: Please fix this test, it does not work. +// public void testWSCtxt_WSDL_DESCRIPTION_read() { +// String type_expected = java.net.URI.class.getName(); +// String value_expected = "META-INF/MessageContext.wsdl"; +// runTest(javax.xml.ws.handler.MessageContext.WSDL_DESCRIPTION, type_expected, value_expected, false); +// } + + private void runTest(String propName, String exType, String exValue, boolean isValueFullySpecified) { + MessageContext port = getPort(); + + Holder<String> type = new Holder<String>(); + Holder<String> value = new Holder<String>(); + Holder<Boolean> isFound = new Holder<Boolean>(); + Holder<String> propertyName = new Holder<String>(propName); + + port.isPropertyPresent(propertyName, value, type, isFound); + + System.out.println("Property = " + propName + " found=" + isFound.value); + System.out.println("Value = " + value.value + "/" + exValue); + System.out.println("Type = " + type.value + "/" + exType); + + assertTrue("WebServiceContext did not expose " + propertyName.value, isFound.value); + + if (exType != null) + assertTrue("Type of " + propertyName.value + " does not match [" + type.value + ", " + exType + "]", + type.value != null && type.value.indexOf(exType) > -1); + + if (exValue != null) { + if (isValueFullySpecified) { + assertEquals("Value of " + propertyName.value + " does not match", exValue, value.value); + } else { + assertTrue("Value of " + propertyName.value + " does not contain " + exValue, value.value.indexOf(exValue) != -1); + } + } + } + + public MessageContext getPort() { + MessageContextService service = new MessageContextService(); + MessageContext port = service.getMessageContextPort(); + BindingProvider p = (BindingProvider) port; + p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, axisEndpoint); + return port; + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]