ws-wsrf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject svn commit: r292841 - in /webservices/wsrf/trunk/src/java/org/apache/ws/resource: handler/ResourceHandler.java handler/addressing/ handler/addressing/WSAddressingHandler.java impl/AbstractResourceHome.java impl/ResourceContextImpl.java
Date Fri, 30 Sep 2005 19:45:21 GMT
Author: scamp
Date: Fri Sep 30 12:45:17 2005
New Revision: 292841

URL: http://svn.apache.org/viewcvs?rev=292841&view=rev
Log:
Built the WS-Addressing Handler

Added:
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/addressing/
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/addressing/WSAddressingHandler.java
Modified:
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java
    webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceContextImpl.java

Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java?rev=292841&r1=292840&r2=292841&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/ResourceHandler.java Fri
Sep 30 12:45:17 2005
@@ -21,6 +21,7 @@
 import org.apache.ws.Soap1_1Constants;
 import org.apache.ws.resource.ResourceContext;
 import org.apache.ws.resource.ResourceContextException;
+import org.apache.ws.resource.handler.addressing.WSAddressingHandler;
 import org.apache.ws.resource.faults.FaultException;
 import org.apache.ws.resource.i18n.Keys;
 import org.apache.ws.resource.i18n.MessagesImpl;
@@ -81,7 +82,7 @@
    /**
     * DOCUMENT_ME
     */
-   private static final String WSRF_RESPONSE_XMLOBJECT_LIST = "WSRF_RESPONSE_XMLOBJECT_LIST";
+   public static final String WSRF_RESPONSE_XMLOBJECT_LIST = "WSRF_RESPONSE_XMLOBJECT_LIST";
 
    /**
     * DOCUMENT_ME
@@ -96,15 +97,10 @@
    /** DOCUMENT_ME */
    public static final String HANDLER_OPT_VALIDATE_REQUEST_XML = "validateRequestXml";
 
-   public static final String CONTEXT_PROP_WSA_NAMESPACE_URI = "wsa.namespace.uri";
-
-   public static final String CONTEXT_PROP_WSA_RESPONSE_ACTION = "wsa.response.action";
-   public static final String CONTEXT_PROP_WSA_RESPONSE_DESTINATION = "wsa.response.destination";
-
-   static
-   {
-      ExceptionUtils.addCauseMethodName( "getLinkedCause" ); // for JAXRPCException
-   }
+    static
+    {
+       ExceptionUtils.addCauseMethodName( "getLinkedCause" ); // for JAXRPCException
+    }
 
    private Map m_handlerOptions;
 
@@ -262,19 +258,19 @@
            header = responseEnvelope.addHeader();
         }
 
-        String wsaAction = (String) msgContext.getProperty( CONTEXT_PROP_WSA_RESPONSE_ACTION
);
+        String wsaAction = (String) msgContext.getProperty( WSAddressingHandler.CONTEXT_PROP_WSA_RESPONSE_ACTION
);
         if ( wsaAction == null )
         {
-           wsaAction = (String) msgContext.getProperty( CONTEXT_PROP_WSA_NAMESPACE_URI )
+ "/anonymous";
+           wsaAction = (String) msgContext.getProperty( WSAddressingHandler.CONTEXT_PROP_WSA_NAMESPACE_URI
) + "/anonymous";
         }
-        SOAPHeaderElement actionHeaderElem = header.addHeaderElement( NameUtils.createName(
"Action", "wsa", (String)msgContext.getProperty( CONTEXT_PROP_WSA_NAMESPACE_URI ) ) );
+        SOAPHeaderElement actionHeaderElem = header.addHeaderElement( NameUtils.createName(
"Action", "wsa", (String)msgContext.getProperty( WSAddressingHandler.CONTEXT_PROP_WSA_NAMESPACE_URI
) ) );
         actionHeaderElem.setValue( wsaAction );
-        String wsaTo = (String) msgContext.getProperty( CONTEXT_PROP_WSA_RESPONSE_DESTINATION
);
+        String wsaTo = (String) msgContext.getProperty( WSAddressingHandler.CONTEXT_PROP_WSA_RESPONSE_DESTINATION
);
         if ( wsaTo == null )
         {
-           wsaTo = (String) msgContext.getProperty( CONTEXT_PROP_WSA_NAMESPACE_URI ) + "/anonymous";
+           wsaTo = (String) msgContext.getProperty( WSAddressingHandler.CONTEXT_PROP_WSA_NAMESPACE_URI
) + "/anonymous";
         }
-        SOAPHeaderElement toHeaderElem = header.addHeaderElement( NameUtils.createName( "To",
"wsa", (String)msgContext.getProperty( CONTEXT_PROP_WSA_NAMESPACE_URI ) ) );
+        SOAPHeaderElement toHeaderElem = header.addHeaderElement( NameUtils.createName( "To",
"wsa", (String)msgContext.getProperty( WSAddressingHandler.CONTEXT_PROP_WSA_NAMESPACE_URI
) ) );
         toHeaderElem.setValue( wsaTo );
     }
 

Added: webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/addressing/WSAddressingHandler.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/addressing/WSAddressingHandler.java?rev=292841&view=auto
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/addressing/WSAddressingHandler.java
(added)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/handler/addressing/WSAddressingHandler.java
Fri Sep 30 12:45:17 2005
@@ -0,0 +1,167 @@
+package org.apache.ws.resource.handler.addressing;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ws.Soap1_1Constants;
+import org.apache.ws.addressing.AddressingUtils;
+import org.apache.ws.resource.faults.FaultException;
+import org.apache.ws.resource.i18n.Keys;
+import org.apache.ws.resource.i18n.MessagesImpl;
+import org.apache.ws.util.NameUtils;
+import org.apache.ws.util.i18n.Messages;
+
+import javax.xml.namespace.QName;
+import javax.xml.rpc.handler.GenericHandler;
+import javax.xml.rpc.handler.MessageContext;
+import javax.xml.rpc.handler.soap.SOAPMessageContext;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+
+/**
+ * WS-Addressing JAX-RPC Handler
+ *
+ * @author Sal Campana
+ */
+public class WSAddressingHandler extends GenericHandler
+{
+    private static final Log LOG = LogFactory.getLog(WSAddressingHandler.class.getName());
+    private static final Messages MSG = MessagesImpl.getInstance();
+    public static final String CONTEXT_PROP_WSA_NAMESPACE_URI = "wsa.namespace.uri";
+    public static final String CONTEXT_PROP_WSA_RESPONSE_ACTION = "wsa.response.action";
+    public static final String CONTEXT_PROP_WSA_RESPONSE_DESTINATION = "wsa.response.destination";
+    public static final String CONTEXT_PROP_WSA_REQUEST_DESTINATION = "wsa.request.destination";
+    public static final String CONTEXT_PROP_WSA_REQUEST_ACTION = "wsa.request.action";
+
+    public QName[] getHeaders()
+    {
+        return new QName[0];
+    }
+
+    /**
+     * Checks for the required WS-Addressing Headers and adds them to the MessageContext.
+     *
+     * @param messageContext
+     * @return always true
+     */
+    public boolean handleRequest(MessageContext messageContext)
+    {
+        SOAPMessageContext soapMsgContext = (SOAPMessageContext) messageContext;
+
+        String addressingAction = getAddressingAction(soapMsgContext);
+        String addressingTo = getAddressingTo(soapMsgContext);
+        String addressingNamespaceURI = getAddressingNamespaceURI(soapMsgContext);
+
+        soapMsgContext.setProperty(CONTEXT_PROP_WSA_NAMESPACE_URI, addressingNamespaceURI);
+        soapMsgContext.setProperty(CONTEXT_PROP_WSA_REQUEST_ACTION, addressingAction);
+        soapMsgContext.setProperty(CONTEXT_PROP_WSA_REQUEST_DESTINATION, addressingTo);
+        return true;
+    }
+
+    /**
+     * @param messageContext
+     * @return always true
+     */
+    public boolean handleResponse(MessageContext messageContext)
+    {
+        LOG.debug(MSG.getMessage(Keys.HANDLING_RESPONSE));
+
+        try
+        {
+            SOAPHeader header = ((SOAPMessageContext) messageContext).getMessage().getSOAPHeader();
+
+            //wsa:Action
+            String wsaAction = (String) messageContext.getProperty(CONTEXT_PROP_WSA_RESPONSE_ACTION);
 //how would this ever be null?
+            if (wsaAction == null)
+            {
+                wsaAction = (String) messageContext.getProperty(CONTEXT_PROP_WSA_NAMESPACE_URI)
+ "/anonymous";
+            }
+
+            SOAPHeaderElement actionHeaderElem = header.addHeaderElement(NameUtils.createName("Action",
"wsa", (String) messageContext.getProperty(CONTEXT_PROP_WSA_NAMESPACE_URI)));
+            actionHeaderElem.setValue(wsaAction);
+
+            //wsa:To
+            String wsaTo = (String) messageContext.getProperty(CONTEXT_PROP_WSA_RESPONSE_DESTINATION);
+            if (wsaTo == null)
+            {
+                wsaTo = (String) messageContext.getProperty(CONTEXT_PROP_WSA_NAMESPACE_URI)
+ "/anonymous";
+            }
+            SOAPHeaderElement toHeaderElem = header.addHeaderElement(NameUtils.createName("To",
"wsa", (String) messageContext.getProperty(CONTEXT_PROP_WSA_NAMESPACE_URI)));
+            toHeaderElem.setValue(wsaTo);
+
+        }
+        catch (SOAPException e)
+        {
+            LOG.error(MSG.getMessage(Keys.INTERNAL_SERVER_ERROR), e);
+            throw new FaultException(Soap1_1Constants.FAULT_SERVER, "An exception occurred
while adding the required WS-Addressing fields to the response.");
+        }
+
+        return true;
+    }
+
+    protected String getAddressingAction(SOAPMessageContext msgContext)
+    {
+        SOAPHeaderElement actionHeaderElem = AddressingUtils.getHeaderElement(getSOAPHeader(msgContext),
new QName(getAddressingNamespaceURI(msgContext), "Action"));
+        if (actionHeaderElem == null)
+        {
+            LOG.debug(MSG.getMessage(Keys.NO_WSA_ACTION));
+            throw new FaultException(Soap1_1Constants.FAULT_CLIENT,
+                                     "A WS-Addressing Action SOAP header element is required
by this endpoint.");
+        }
+        String action = actionHeaderElem.getValue();
+        try
+        {
+            new URI(action);
+        }
+        catch (URISyntaxException urise)
+        {
+            LOG.debug(MSG.getMessage(Keys.INVALID_WSA_ACTION, action));
+            throw new FaultException(Soap1_1Constants.FAULT_CLIENT,
+                                     "The WS-Addressing Action specified in the SOAP header
is not a valid URI.");
+        }
+        LOG.debug(MSG.getMessage(Keys.FOUND_WSA_ACTION, action));
+        return action;
+    }
+
+    private SOAPHeader getSOAPHeader(SOAPMessageContext msgContext)
+    {
+        try
+        {
+            return msgContext.getMessage().getSOAPHeader();
+        }
+        catch (SOAPException soape)
+        {
+            throw new RuntimeException("Failed to extract header from SOAP message.", soape);
+        }
+    }
+
+    private String getAddressingNamespaceURI(SOAPMessageContext msgContext)
+    {
+        String wsaNsURI = (String) msgContext.getProperty(CONTEXT_PROP_WSA_NAMESPACE_URI);
+        if (wsaNsURI == null)
+        {
+            wsaNsURI = AddressingUtils.getAddressingNamespaceURI(getSOAPHeader(msgContext));
+            msgContext.setProperty(CONTEXT_PROP_WSA_NAMESPACE_URI, wsaNsURI);
+        }
+        return wsaNsURI;
+    }
+
+    private String getAddressingTo(SOAPMessageContext msgContext)
+    {
+        SOAPHeaderElement toHeaderElem = AddressingUtils.getHeaderElement(getSOAPHeader(msgContext),
new QName(getAddressingNamespaceURI(msgContext), "To"));
+        String addressingTo;
+        if (toHeaderElem == null)
+        {
+            LOG.debug(MSG.getMessage(Keys.NO_WSA_TO));
+            throw new FaultException(Soap1_1Constants.FAULT_CLIENT,
+                                     "A WS-Addressing To SOAP header element is required
by this endpoint.");
+        }
+
+        addressingTo = toHeaderElem.getValue();
+
+        return addressingTo;
+    }
+}

Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java?rev=292841&r1=292840&r2=292841&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java
(original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/AbstractResourceHome.java
Fri Sep 30 12:45:17 2005
@@ -210,9 +210,12 @@
 
         XmlBeansEndpointReference xBeansEPR =
                 new XmlBeansEndpointReference( endpointAddress, wsAddressingURI );
-        XmlObject resourceIdRefParam = XmlBeanUtils.createElement( m_resourceIdRefParamName
);
-        XmlBeanUtils.setValue( resourceIdRefParam, resourceId.toString(  ) );
-        xBeansEPR.addReferenceParameter( resourceIdRefParam );
+        if (resourceId != null)
+        {
+            XmlObject resourceIdRefParam = XmlBeanUtils.createElement( m_resourceIdRefParamName
);
+            XmlBeanUtils.setValue( resourceIdRefParam, resourceId.toString(  ) );
+            xBeansEPR.addReferenceParameter( resourceIdRefParam );
+        }
         xBeansEPR.setPortTypeQName( getPortType() );
         xBeansEPR.setServicePortName( getServicePortName() );
         xBeansEPR.setServiceQName( getServiceName() );

Modified: webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceContextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceContextImpl.java?rev=292841&r1=292840&r2=292841&view=diff
==============================================================================
--- webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceContextImpl.java (original)
+++ webservices/wsrf/trunk/src/java/org/apache/ws/resource/impl/ResourceContextImpl.java Fri
Sep 30 12:45:17 2005
@@ -26,7 +26,7 @@
 import org.apache.ws.resource.ResourceHome;
 import org.apache.ws.resource.WsrfRuntime;
 import org.apache.ws.resource.faults.FaultException;
-import org.apache.ws.resource.handler.ResourceHandler;
+import org.apache.ws.resource.handler.addressing.WSAddressingHandler;
 import org.apache.ws.resource.i18n.Keys;
 import org.apache.ws.resource.i18n.MessagesImpl;
 import org.apache.ws.util.i18n.Messages;
@@ -190,7 +190,7 @@
    {
       if ( action != null )
       {
-          m_msgContext.setProperty( ResourceHandler.CONTEXT_PROP_WSA_RESPONSE_ACTION, action.toString()
);
+          m_msgContext.setProperty( WSAddressingHandler.CONTEXT_PROP_WSA_RESPONSE_ACTION,
action.toString() );
       }
    }
 
@@ -358,11 +358,11 @@
     private String getAddressingNamespaceURI( SOAPMessageContext msgContext )
     {
 
-        String wsaNsURI = (String) msgContext.getProperty( ResourceHandler.CONTEXT_PROP_WSA_NAMESPACE_URI
);
+        String wsaNsURI = (String) msgContext.getProperty( WSAddressingHandler.CONTEXT_PROP_WSA_NAMESPACE_URI
);
         if ( wsaNsURI == null )
         {
             wsaNsURI = AddressingUtils.getAddressingNamespaceURI( getSOAPHeader( msgContext
) );
-            msgContext.setProperty( ResourceHandler.CONTEXT_PROP_WSA_NAMESPACE_URI, wsaNsURI
);
+            msgContext.setProperty( WSAddressingHandler.CONTEXT_PROP_WSA_NAMESPACE_URI, wsaNsURI
);
         }
         return wsaNsURI;
     }



Mime
View raw message