[jbossws-commits] JBossWS SVN: r2023 - in trunk: jbossws-core/src/main/java/org/jboss/ws/core/jaxws/handler and 2 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Mon Jan 22 10:56:24 EST 2007


Author: thomas.diesler at jboss.com
Date: 2007-01-22 10:56:24 -0500 (Mon, 22 Jan 2007)
New Revision: 2023

Added:
   trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/jsr181/handlerchain/HandlerChainClient.java
Removed:
   trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/jsr181/handlerchain/HandlerChainClient.java
Modified:
   trunk/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/WebServiceRefHandler.java
   trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java
   trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java
Log:
Resolve @HandlerChain.file relative to declaring class

Modified: trunk/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/WebServiceRefHandler.java
===================================================================
--- trunk/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/WebServiceRefHandler.java	2007-01-22 15:47:57 UTC (rev 2022)
+++ trunk/integration-jboss50/src/main/java/org/jboss/ws/integration/jboss50/WebServiceRefHandler.java	2007-01-22 15:56:24 UTC (rev 2023)
@@ -27,6 +27,8 @@
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -140,9 +142,35 @@
             usRef.setWsdlLocation(wsref.wsdlLocation());
 
          // Set the handlerChain from @HandlerChain on the annotated element
+         String handlerChain = usRef.getHandlerChain();
          HandlerChain anHandlerChain = anElement.getAnnotation(HandlerChain.class);
-         if (usRef.getHandlerChain() == null && anHandlerChain != null && anHandlerChain.file().length() > 0)
-            usRef.setHandlerChain(anHandlerChain.file());
+         if (handlerChain == null && anHandlerChain != null && anHandlerChain.file().length() > 0)
+            handlerChain = anHandlerChain.file();
+         
+         // Resolve path to handler chain
+         if (handlerChain != null)
+         {
+            try
+            {
+               new URL(handlerChain);
+            }
+            catch (MalformedURLException ex)
+            {
+               Class declaringClass = null;
+               if (anElement instanceof Field)
+                  declaringClass = ((Field)anElement).getDeclaringClass();
+               else if (anElement instanceof Method)
+                  declaringClass = ((Method)anElement).getDeclaringClass();
+               else if (anElement instanceof Class)
+                  declaringClass = (Class)anElement;
+               
+               handlerChain = declaringClass.getPackage().getName().replace('.', '/') + "/" + handlerChain;
+               VirtualFile vfHandlerChain = vfsRoot.findChild(handlerChain);
+               if (vfHandlerChain == null)
+                  throw new IllegalStateException("Cannot find handler chain: " + handlerChain);
+            }
+            usRef.setHandlerChain(handlerChain);
+         }
 
          Util.rebind(encCtx, encName, new ServiceReferenceable(serviceClassName, targetClassName, usRef));
       }

Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java	2007-01-22 15:47:57 UTC (rev 2022)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/core/jaxws/handler/LogicalMessageImpl.java	2007-01-22 15:56:24 UTC (rev 2023)
@@ -23,6 +23,8 @@
 
 // $Id$
 
+import java.io.BufferedReader;
+import java.io.IOException;
 import java.io.StringReader;
 import java.util.Iterator;
 
@@ -35,8 +37,11 @@
 import javax.xml.ws.LogicalMessage;
 import javax.xml.ws.WebServiceException;
 
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.jaxws.client.ServiceObjectFactory;
 import org.jboss.ws.core.soap.SOAPBodyImpl;
 import org.jboss.ws.core.soap.SOAPContentElement;
+import org.jboss.ws.core.utils.DOMUtils;
 
 /**
  * The LogicalMessageContext interface extends MessageContext to provide access to a the 
@@ -47,7 +52,11 @@
  */
 public class LogicalMessageImpl implements LogicalMessage
 {
+   // provide logging
+   private static final Logger log = Logger.getLogger(LogicalMessageImpl.class);
+   
    private SOAPBodyImpl soapBody;
+   private boolean setPayloadBodyChild;
 
    public LogicalMessageImpl(SOAPMessage soapMessage)
    {
@@ -64,18 +73,12 @@
    public Source getPayload()
    {
       Source source = soapBody.getPayload();
+      setPayloadBodyChild = false;
       if (source == null)
       {
          SOAPContentElement soapElement = (SOAPContentElement)soapBody.getChildElements().next();
-         if (soapElement.isDOMValid())
-         {
-            source = new DOMSource(soapElement);
-         }
-         else
-         {
-            String xmlPayload = soapElement.getXMLFragment();
-            source = new StreamSource(new StringReader(xmlPayload));
-         }
+         source = soapElement.getPayload();
+         setPayloadBodyChild = true;
       }
       return source;
    }
@@ -83,6 +86,11 @@
    public void setPayload(Source source)
    {
       soapBody.setPayload(source);
+      if (setPayloadBodyChild)
+      {
+         SOAPContentElement soapElement = (SOAPContentElement)soapBody.getChildElements().next();
+         soapElement.setPayload(source);
+      }
    }
 
    public Object getPayload(JAXBContext jaxbContext)

Modified: trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java
===================================================================
--- trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java	2007-01-22 15:47:57 UTC (rev 2022)
+++ trunk/jbossws-core/src/main/java/org/jboss/ws/core/soap/SOAPContentElement.java	2007-01-22 15:56:24 UTC (rev 2023)
@@ -38,6 +38,11 @@
 import javax.xml.soap.Name;
 import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPException;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 
 import org.jboss.logging.Logger;
 import org.jboss.ws.Constants;
@@ -160,7 +165,39 @@
    {
       return xmlFragment != null;
    }
+   
+   /** Get the payload as source. 
+    */
+   public Source getPayload()
+   {
+      // expand to DOM, so the source is repeatedly readable
+      expandToDOM();
+      return new DOMSource(this);
+   }
 
+   /** Set the payload as source 
+    */
+   public void setPayload(Source source)
+   {
+      try
+      {
+         TransformerFactory tf = TransformerFactory.newInstance();
+         ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+         tf.newTransformer().transform(source, new StreamResult(baos));
+         String xmlFragment = new String(baos.toByteArray());
+         if (xmlFragment.startsWith("<?xml"))
+         {
+            int index = xmlFragment.indexOf(">");
+            xmlFragment = xmlFragment.substring(index + 1);
+         }
+         setXMLFragment(xmlFragment);
+      }
+      catch (TransformerException ex)
+      {
+         WSException.rethrow(ex);
+      }
+   }
+
    public String getXMLFragment()
    {
       // Serialize the valueContent

Deleted: trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/jsr181/handlerchain/HandlerChainClient.java
===================================================================
--- trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/jsr181/handlerchain/HandlerChainClient.java	2007-01-22 15:47:57 UTC (rev 2022)
+++ trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/jsr181/handlerchain/HandlerChainClient.java	2007-01-22 15:56:24 UTC (rev 2023)
@@ -1,94 +0,0 @@
-/*
- * 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.jsr181.handlerchain;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jws.HandlerChain;
-import javax.xml.ws.Service;
-import javax.xml.ws.WebServiceRef;
-
-import org.jboss.logging.Logger;
-
-public class HandlerChainClient
-{
-   // provide logging
-   private static final Logger log = Logger.getLogger(HandlerChainClient.class);
-   
-   @WebServiceRef(name = "Service1")
-   @HandlerChain(file = "jaxws-handlers.xml") 
-   static Service service1;
-
-   // Service2 should have no client side handler chain
-   @WebServiceRef(name = "Service2")
-   static Service service2;
-
-   @WebServiceRef(name = "Service3")
-   static Service service3;
-
-   public static Map<String, String> testResult = new HashMap<String, String>();
-
-   public static void main(String[] args) throws Exception
-   {
-      String testName = args[0];
-      String reqStr = args[1];
-      
-      HandlerChainClient client = new HandlerChainClient();
-      Method method = HandlerChainClient.class.getMethod(testName, new Class[] { String.class });
-      try
-      {
-         String retStr = (String)method.invoke(client, reqStr);
-         testResult.put(testName, retStr);
-      }
-      catch (InvocationTargetException ex)
-      {
-         log.error("Invocation error", ex);
-         testResult.put(testName, ex.getTargetException().toString());
-      }
-      catch (Exception ex)
-      {
-         log.error("Error", ex);
-         testResult.put(testName, ex.toString());
-      }
-   }
-
-   public String testService1(String reqStr) throws Exception
-   {
-      Endpoint port = service1.getPort(Endpoint.class);
-      return port.echo(reqStr);
-   }
-
-   public String testService2(String reqStr) throws Exception
-   {
-      Endpoint port = service2.getPort(Endpoint.class);
-      return port.echo(reqStr);
-   }
-
-   public String testService3(String reqStr) throws Exception
-   {
-      Endpoint port = service3.getPort(Endpoint.class);
-      return port.echo(reqStr);
-   }
-}

Added: trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/jsr181/handlerchain/HandlerChainClient.java
===================================================================
--- trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/jsr181/handlerchain/HandlerChainClient.java	                        (rev 0)
+++ trunk/jbossws-tests/src/main/java/org/jboss/test/ws/jaxws/jsr181/handlerchain/HandlerChainClient.java	2007-01-22 15:56:24 UTC (rev 2023)
@@ -0,0 +1,94 @@
+/*
+ * 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.jsr181.handlerchain;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jws.HandlerChain;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceRef;
+
+import org.jboss.logging.Logger;
+
+public class HandlerChainClient
+{
+   // provide logging
+   private static final Logger log = Logger.getLogger(HandlerChainClient.class);
+   
+   @WebServiceRef(name = "Service1")
+   @HandlerChain(file = "jaxws-handlers.xml") 
+   static Service service1;
+
+   // Service2 should have no client side handler chain
+   @WebServiceRef(name = "Service2")
+   static Service service2;
+
+   @WebServiceRef(name = "Service3")
+   static Service service3;
+
+   public static Map<String, String> testResult = new HashMap<String, String>();
+
+   public static void main(String[] args) throws Exception
+   {
+      String testName = args[0];
+      String reqStr = args[1];
+      
+      HandlerChainClient client = new HandlerChainClient();
+      Method method = HandlerChainClient.class.getMethod(testName, new Class[] { String.class });
+      try
+      {
+         String retStr = (String)method.invoke(client, reqStr);
+         testResult.put(testName, retStr);
+      }
+      catch (InvocationTargetException ex)
+      {
+         log.error("Invocation error", ex);
+         testResult.put(testName, ex.getTargetException().toString());
+      }
+      catch (Exception ex)
+      {
+         log.error("Error", ex);
+         testResult.put(testName, ex.toString());
+      }
+   }
+
+   public String testService1(String reqStr) throws Exception
+   {
+      Endpoint port = service1.getPort(Endpoint.class);
+      return port.echo(reqStr);
+   }
+
+   public String testService2(String reqStr) throws Exception
+   {
+      Endpoint port = service2.getPort(Endpoint.class);
+      return port.echo(reqStr);
+   }
+
+   public String testService3(String reqStr) throws Exception
+   {
+      Endpoint port = service3.getPort(Endpoint.class);
+      return port.echo(reqStr);
+   }
+}




More information about the jbossws-commits mailing list