Author: thomas.diesler(a)jboss.com
Date: 2007-03-31 13:33:18 -0400 (Sat, 31 Mar 2007)
New Revision: 2739
Added:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.java
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/provider-handlers.xml
Modified:
trunk/build/version.properties
trunk/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSProviderMetaDataBuilder.java
trunk/jbossws-tests/ant-import/build-samples-jaxws.xml
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/ProviderBeanPayload.java
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/ProviderPayloadTestCase.java
Log:
Add support for logical handlers on Provider
Modified: trunk/build/version.properties
===================================================================
--- trunk/build/version.properties 2007-03-31 16:40:31 UTC (rev 2738)
+++ trunk/build/version.properties 2007-03-31 17:33:18 UTC (rev 2739)
@@ -28,7 +28,7 @@
jboss-remoting=2.2.0.Alpha7
# JBossAS-5.0
-jboss-jbossxb-jboss50=2.0.0.CR1
+jboss-jbossxb-jboss50=2.0.0.CR2
jboss-microcontainer-jboss50=2.0.0.Beta3
jboss-remoting-jboss50=2.2.0.Alpha7
Modified:
trunk/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSProviderMetaDataBuilder.java
===================================================================
---
trunk/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSProviderMetaDataBuilder.java 2007-03-31
16:40:31 UTC (rev 2738)
+++
trunk/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSProviderMetaDataBuilder.java 2007-03-31
17:33:18 UTC (rev 2739)
@@ -126,6 +126,9 @@
serviceMetaData.setWsdlLocation(wsdlURL);
}
+ // process handler chain
+ processHandlerChain(sepMetaData, sepClass);
+
// process config
processEndpointConfig(udi, sepClass, linkName, sepMetaData);
Modified: trunk/jbossws-tests/ant-import/build-samples-jaxws.xml
===================================================================
--- trunk/jbossws-tests/ant-import/build-samples-jaxws.xml 2007-03-31 16:40:31 UTC (rev
2738)
+++ trunk/jbossws-tests/ant-import/build-samples-jaxws.xml 2007-03-31 17:33:18 UTC (rev
2739)
@@ -176,6 +176,8 @@
<war
warfile="${tests.output.dir}/libs/jaxws-samples-provider-payload.war"
webxml="${tests.output.dir}/resources/jaxws/samples/provider/payload/WEB-INF/web.xml">
<classes dir="${tests.output.dir}/classes">
<include
name="org/jboss/test/ws/jaxws/samples/provider/ProviderBeanPayload.class"/>
+ <include
name="org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.class"/>
+ <include
name="org/jboss/test/ws/jaxws/samples/provider/provider-handlers.xml"/>
</classes>
<webinf
dir="${tests.output.dir}/resources/jaxws/samples/provider/shared">
<include name="wsdl/Provider.wsdl"/>
Added:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.java
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.java
(rev 0)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.java 2007-03-31
17:33:18 UTC (rev 2739)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.samples.provider;
+
+// $Id$
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.LogicalMessageContext;
+import javax.xml.ws.handler.MessageContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.jaxws.handler.GenericLogicalHandler;
+import org.jboss.ws.core.utils.DOMUtils;
+import org.w3c.dom.Element;
+
+/**
+ * A jaxws logical handler
+ *
+ * @author Thomas.Diesler(a)jboss.org
+ * @since 24-Nov-2005
+ */
+public class LogicalSourceHandler extends GenericLogicalHandler
+{
+ // provide logging
+ private static final Logger log = Logger.getLogger(LogicalSourceHandler.class);
+
+ @Override
+ public boolean handleOutbound(MessageContext msgContext)
+ {
+ return appendHandlerName(msgContext, "Outbound");
+ }
+
+ @Override
+ public boolean handleInbound(MessageContext msgContext)
+ {
+ return appendHandlerName(msgContext, "Inbound");
+ }
+
+ public boolean appendHandlerName(MessageContext msgContext, String direction)
+ {
+ try
+ {
+ // Get the payload as Source
+ LogicalMessageContext logicalContext = (LogicalMessageContext)msgContext;
+ Source source = logicalContext.getMessage().getPayload();
+ TransformerFactory tf = TransformerFactory.newInstance();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+ tf.newTransformer().transform(source, new StreamResult(baos));
+
+ // Parse the payload and extract the value
+ Element root = DOMUtils.parse(new ByteArrayInputStream(baos.toByteArray()));
+
+ String oldValue = DOMUtils.getTextContent(root);
+ String newValue = oldValue + ":" + direction + getHandlerName();
+ root.setTextContent(newValue);
+
+ log.debug("oldValue: " + oldValue);
+ log.debug("newValue: " + newValue);
+
+ // Set the updated payload
+ source = new DOMSource(root);
+ logicalContext.getMessage().setPayload(source);
+
+ return true;
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ throw new WebServiceException(ex);
+ }
+ }
+}
Property changes on:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/LogicalSourceHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/ProviderBeanPayload.java
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/ProviderBeanPayload.java 2007-03-31
16:40:31 UTC (rev 2738)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/ProviderBeanPayload.java 2007-03-31
17:33:18 UTC (rev 2739)
@@ -27,6 +27,7 @@
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
+import javax.jws.HandlerChain;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@@ -43,8 +44,10 @@
* @author Thomas.Diesler(a)jboss.org
* @since 29-Jun-2006
*/
+
+@HandlerChain(file = "provider-handlers.xml")
@WebServiceProvider(serviceName = "ProviderService", portName =
"ProviderPort", targetNamespace = "http://org.jboss.ws/provider",
wsdlLocation = "WEB-INF/wsdl/Provider.wsdl")
-// @ServiceMode(value = Service.Mode.PAYLOAD) in absence PAYLOAD is implicit
+// @ServiceMode(value = Service.Mode.PAYLOAD) - PAYLOAD is implicit
public class ProviderBeanPayload implements Provider<Source>
{
public Source invoke(Source req)
@@ -60,7 +63,7 @@
transformer.transform(req, streamResult);
String xmlReq = streamResult.getOutputStream().toString();
- String expReq = "<ns1:somePayload
xmlns:ns1=\"http://org.jboss.ws/provider\"/>";
+ String expReq = "<ns1:somePayload
xmlns:ns1=\"http://org.jboss.ws/provider\">Hello:InboundLogicalHandler</ns1:somePayload>";
if (!expReq.equals(xmlReq))
throw new WebServiceException("Unexpected payload: " + xmlReq);
Modified:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/ProviderPayloadTestCase.java
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/ProviderPayloadTestCase.java 2007-03-31
16:40:31 UTC (rev 2738)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/ProviderPayloadTestCase.java 2007-03-31
17:33:18 UTC (rev 2739)
@@ -33,6 +33,7 @@
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
@@ -58,9 +59,12 @@
*/
public class ProviderPayloadTestCase extends JBossWSTest
{
- private String msgString =
- "<ns1:somePayload
xmlns:ns1='http://org.jboss.ws/provider'/>";
+ private String reqString =
+ "<ns1:somePayload
xmlns:ns1='http://org.jboss.ws/provider'>Hello</ns1:somePayload>";
+ private String resString =
+ "<ns1:somePayload
xmlns:ns1='http://org.jboss.ws/provider'>Hello:InboundLogicalHandler:OutboundLogicalHandler</ns1:somePayload>";
+
public static Test suite()
{
return JBossWSTestSetup.newTestSetup(ProviderPayloadTestCase.class,
"jaxws-samples-provider-payload.war");
@@ -77,12 +81,36 @@
public void testProviderDispatch() throws Exception
{
Dispatch<Source> dispatch = createDispatch("ProviderEndpoint");
- Source resPayload = dispatch.invoke(new DOMSource(DOMUtils.parse(msgString)));
+ Source resPayload = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString)));
Element docElement = getElementFromSource(resPayload);
- assertEquals(DOMUtils.parse(msgString), docElement);
+ assertEquals(DOMUtils.parse(resString), docElement);
}
+ public void testProviderMessage() throws Exception
+ {
+ String reqEnvStr =
+ "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
+ " <env:Body>" + reqString + "</env:Body>" +
+ "</env:Envelope>";
+
+ String resEnvString =
+ "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
+ " <env:Header/>" +
+ " <env:Body>" + resString + "</env:Body>" +
+ "</env:Envelope>";
+
+ MessageFactory msgFactory = MessageFactory.newInstance();
+ SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
+ SOAPMessage reqMsg = msgFactory.createMessage(null, new
ByteArrayInputStream(reqEnvStr.getBytes()));
+
+ URL epURL = new URL("http://" + getServerHost() +
":8080/jaxws-samples-provider-payload");
+ SOAPMessage resMsg = con.call(reqMsg, epURL);
+ SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
+
+ assertEquals(DOMUtils.parse(resEnvString), resEnv);
+ }
+
private Dispatch<Source> createDispatch(String target) throws
MalformedURLException, JAXBException
{
String targetNS = "http://org.jboss.ws/provider";
@@ -96,25 +124,4 @@
Dispatch<Source> dispatch = service.createDispatch(portName, Source.class,
Mode.PAYLOAD);
return dispatch;
}
-
- public void testProviderMessage() throws Exception
- {
- String reqString =
- "<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
- " <env:Body>" +
- " <ns1:somePayload
xmlns:ns1='http://org.jboss.ws/provider'/>" +
- " </env:Body>" +
- "</env:Envelope>";
-
- MessageFactory msgFactory = MessageFactory.newInstance();
- SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
- SOAPMessage reqMsg = msgFactory.createMessage(null, new
ByteArrayInputStream(reqString.getBytes()));
- SOAPEnvelope reqEnv = reqMsg.getSOAPPart().getEnvelope();
-
- URL epURL = new URL("http://" + getServerHost() +
":8080/jaxws-samples-provider-payload");
- SOAPMessage resMsg = con.call(reqMsg, epURL);
- SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
-
- assertEquals(reqEnv, resEnv);
- }
}
Added:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/provider-handlers.xml
===================================================================
---
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/provider-handlers.xml
(rev 0)
+++
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/provider-handlers.xml 2007-03-31
17:33:18 UTC (rev 2739)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<handler-chains
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:ns1="http://org.jboss.ws/jaxws/samples/logicalhandler"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
javaee_web_services_1_2.xsd">
+
+ <handler-chain>
+ <handler>
+ <handler-name> LogicalHandler </handler-name>
+ <handler-class> org.jboss.test.ws.jaxws.samples.provider.LogicalSourceHandler
</handler-class>
+ </handler>
+ </handler-chain>
+
+</handler-chains>
\ No newline at end of file
Property changes on:
trunk/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/provider/provider-handlers.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF