You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ng...@apache.org on 2007/03/26 06:25:22 UTC

svn commit: r522411 - in /webservices/axis2/trunk/java/modules: jaxws/src/org/apache/axis2/jaxws/core/controller/ jaxws/src/org/apache/axis2/jaxws/handler/ jaxws/src/org/apache/axis2/jaxws/server/ jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ jax...

Author: ngallardo
Date: Sun Mar 25 21:25:20 2007
New Revision: 522411

URL: http://svn.apache.org/viewvc?view=rev&rev=522411
Log:
AXIS2-2218
Contributor: Mike Rheinhiemer

The first portion of the server side handler chain integration.

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersLogicalHandler.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/InvocationController.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/ProtectedMessageContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SAAJFactory.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersFault_Exception.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersPortType.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java Sun Mar 25 21:25:20 2007
@@ -216,7 +216,7 @@
                 || opClient.getOptions().isUseSeparateListener()) {
             configureAsyncListener(opClient, request.getAxisMessageContext());
         }
-		else {
+	else {
             if (log.isDebugEnabled()) {
                 log.debug("Asynchronous message exchange not enabled.  The invocation will be synchronous.");
             }
@@ -292,6 +292,11 @@
         if((useAsyncMep != null && useAsyncMep.booleanValue()) 
                 || opClient.getOptions().isUseSeparateListener()) {
             configureAsyncListener(opClient, request.getAxisMessageContext());
+        }
+        else {
+            if (log.isDebugEnabled()) {
+                log.debug("Asynchronous message exchange not enabled.  The invocation will be synchronous.");
+            }
         }
         
         AsyncResponse resp = ic.getAsyncResponseListener(); 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/InvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/InvocationController.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/InvocationController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/InvocationController.java Sun Mar 25 21:25:20 2007
@@ -152,7 +152,7 @@
      */
     public Response invokeAsync(InvocationContext ic) {
         if (log.isDebugEnabled()) {
-            log.debug("Invocation pattern: asynchronous(callback)");
+            log.debug("Invocation pattern: asynchronous(polling)");
         }
         
         // Check to make sure we at least have a valid InvocationContext

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerChainProcessor.java Sun Mar 25 21:25:20 2007
@@ -1,7 +1,30 @@
+/*
+ * 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.handler;
 
 import java.util.ArrayList;
 
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFault;
+import javax.xml.soap.SOAPMessage;
 import javax.xml.ws.ProtocolException;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.handler.Handler;
@@ -12,6 +35,11 @@
 
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.marshaller.impl.alt.MethodMarshallerUtils;
+import org.apache.axis2.jaxws.message.Protocol;
+import org.apache.axis2.jaxws.message.XMLFault;
+import org.apache.axis2.jaxws.message.util.XMLFaultUtils;
+import org.apache.axis2.jaxws.utility.SAAJFactory;
 
 public class HandlerChainProcessor {
 
@@ -40,7 +68,7 @@
 	private final static int OTHER_EXCEPTION = 3;
 	// save it if Handler.handleMessage throws one in HandlerChainProcessor.handleMessage
 	private RuntimeException savedException;
-
+	
 	/*
 	 * HandlerChainProcess expects null, empty list, or an already-sorted
 	 * list.  If the chain passed into here came from our HandlerChainResolver,
@@ -94,7 +122,7 @@
 	 * 1.  Has the MessageContext.MESSAGE_OUTBOUND_PROPERTY changed, indicating reversal of message direction
 	 * 2.  Has the message been converted to a fault message? (indicated by a flag in the message)
 	 */
-	public void processChain(MessageContext mc, Direction direction, MEP mep, boolean expectResponse) {
+	public MessageContext processChain(MessageContext mc, Direction direction, MEP mep, boolean expectResponse) {
 		// make sure it's set:
 		mc.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, (direction == Direction.OUT));
 		
@@ -117,6 +145,9 @@
 				callGenericHandlers(mep, expectResponse, logicalLength-1, 0, direction);
 			}
 		}
+		// message context may have been changed to be response, and message converted
+		// according to the JAXWS spec 9.3.2.1 footnote 2
+		return this.mc;
 	}
 	
 	
@@ -139,7 +170,7 @@
 
 		if (direction == Direction.OUT) {
 			while ((i <= end) && (result == SUCCESSFUL)) {
-				result = handleMessage(((Handler)handlers.get(i)), mc, direction, expectResponse);
+				result = handleMessage(((Handler)handlers.get(i)), direction, expectResponse);
 				newStart = i-1;
 				newStart_inclusive = i;
 				newEnd = 0;
@@ -149,7 +180,7 @@
 		}
 		else { // IN case
 			while ((i >= end) && (result == SUCCESSFUL)) {
-				result = handleMessage(((Handler)handlers.get(i)), mc, direction, expectResponse);
+				result = handleMessage(((Handler)handlers.get(i)), direction, expectResponse);
 				newStart = i+1;
 				newStart_inclusive = i;
 				newEnd = handlers.size()-1;
@@ -192,8 +223,8 @@
 	
 	/*
 	 * callGenericHandlers_avoidRecursion should ONLY be called from one place.
-	 * We can safely assume no false returns and no exceptions will be thrown
-	 * from here since the handlers we will be calling have all already
+	 * TODO:  We cannot necessarily assume no false returns and no exceptions will be
+     * thrown from here even though the handlers we will be calling have all already
 	 * succeeded in callGenericHandlers.
 	 */
 	private void callGenericHandlers_avoidRecursion(int start,
@@ -217,7 +248,7 @@
 	 * If an exception is thrown and a response is expected, the MessageContext is updated with the handler information
 	 * @returns SUCCESSFUL if successfully, UNSUCCESSFUL if false, EXCEPTION if exception thrown
 	 */
-	private int handleMessage(Handler handler, MessageContext mc, Direction direction,
+	private int handleMessage(Handler handler, Direction direction,
 			boolean expectResponse) throws RuntimeException {
 		try {
 			boolean success = handler.handleMessage(mc);
@@ -231,9 +262,10 @@
 		} catch (RuntimeException re) {  // RuntimeException and ProtocolException
 			savedException = re;
 			if (expectResponse)
+                // mark it as reverse direction
 				mc.put(MessageContext.MESSAGE_OUTBOUND_PROPERTY, (direction != Direction.OUT));
 			if (ProtocolException.class.isAssignableFrom(re.getClass())) {
-				convertToFaultMessage(mc, re);
+				convertToFaultMessage(re);
 				return PROTOCOL_EXCEPTION;
 			}
 			return OTHER_EXCEPTION;
@@ -276,7 +308,7 @@
 	 * opposite direction as this call to callHandleFault, and thus
 	 * should be closed.
 	 */
-	public void processFault(SOAPMessageContext mc, Direction direction) {
+	public void processFault(MessageContext mc, Direction direction) {
 		
 		// direction.IN = client
 		// direction.OUT = server
@@ -336,10 +368,48 @@
 	}
 	
 	
-	private void convertToFaultMessage(MessageContext mc, Exception e) {
-		// TODO: implement
+	private void convertToFaultMessage(Exception e) {
+
 		// need to check if message is already a fault message or not,
 		// probably by way of a flag (isFault) in the MessageContext or Message
+        try {
+            
+        	/* TODO TODO TODO
+        	 * There has GOT to be a better way to do this.
+        	 */
+
+        	// TODO how do we figure out the soap version on the MessageContext without
+        	// using the message itself?  Reason for not using the message itself is that
+        	// most of the SAAJ methods in Axis2 that we need are unimplemented.
+        	// for testing, I'm gonna use soap11.
+        	Protocol protocol = Protocol.soap11;
+        	
+        	if (protocol == Protocol.soap11 || protocol == Protocol.soap12) {
+                String protocolNS = (protocol == Protocol.soap11) ? 
+                        SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE : 
+                            SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE;
+        	
+                // The following set of instructions is used to avoid 
+                // some unimplemented methods in the Axis2 SAAJ implementation
+                XMLFault xmlFault = MethodMarshallerUtils.createXMLFaultFromSystemException(e);
+                javax.xml.soap.MessageFactory mf = SAAJFactory.createMessageFactory(protocolNS);
+                SOAPMessage message = mf.createMessage();
+                SOAPBody body = message.getSOAPBody();
+                SOAPFault soapFault = XMLFaultUtils.createSAAJFault(xmlFault, body);
+                
+                // TODO something is wrong here.  The message should be a response message, not
+                // a request message.  I don't see how to change that.  (see the debugger...)
+                // TODO probably also need to turn on message.WRITE_XML_DECLARATION
+                ((SoapMessageContext)mc).setMessage(message);
+                
+        	} else {
+        		// TODO throw an exception, because we only support SOAP11 and SOAP12, I think.
+        	}
+
+        } catch (SOAPException soapex) {
+            // TODO not too sure what to do here.
+        }
+
 	}
 	
 

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java?view=auto&rev=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerInvokerUtils.java Sun Mar 25 21:25:20 2007
@@ -0,0 +1,194 @@
+package org.apache.axis2.jaxws.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.context.factory.MessageContextFactory;
+import org.apache.axis2.jaxws.context.utils.ContextUtils;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.description.EndpointDescription;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.server.endpoint.lifecycle.impl.EndpointLifecycleManagerImpl;
+
+public class HandlerInvokerUtils {
+
+    /**
+     * Invoke Inbound Handlers
+     * @param requestMsgCtx
+     */
+    public static boolean invokeInboundHandlers(MessageContext msgCtx,
+            EndpointDescription endpointDesc, HandlerChainProcessor.MEP mep, boolean isOneWay) {
+        List<String> handlers = endpointDesc.getHandlerList();
+
+        // TODO MIKE TEST -- REMOVE - for testing until we get a list of objects from EndpointDescription.getHandlerList();
+        /*
+        if (endpointDesc.getServiceQName().getLocalPart().contains("AddNumber"))
+            handlers.add("org.apache.axis2.jaxws.sample.addnumbers.AddNumbersLogicalHandler");
+        */
+        // TODO END MIKE TEST
+
+        int numHandlers = handlers.size();
+        javax.xml.ws.handler.MessageContext handlerMessageContext = null;
+
+        if (numHandlers > 0) {
+            handlerMessageContext = findOrCreateMessageContext(msgCtx);
+        } else {
+            return true;
+        }
+
+        // TODO remove this.  Handlers will have already been instantiated when
+        // we start using the handlerresolver to get our list.
+        ArrayList<Handler> handlerInstances = createHandlerInstances(endpointDesc);
+
+        HandlerChainProcessor processor = new HandlerChainProcessor(
+                handlerInstances);
+
+        // if not one-way, expect a response
+        if (msgCtx.getMessage().isFault()) {
+                processor.processFault(handlerMessageContext,
+                    HandlerChainProcessor.Direction.IN);
+        } else {
+                handlerMessageContext = processor.processChain(handlerMessageContext,
+                                HandlerChainProcessor.Direction.IN,
+                                mep,
+                                !isOneWay);
+        }
+
+        if (handlerMessageContext.get(javax.xml.ws.handler.MessageContext.MESSAGE_OUTBOUND_PROPERTY).equals(true)
+                        && mep.equals(HandlerChainProcessor.MEP.REQUEST)) {
+            // uh-oh.  We've changed directions on the server inbound handler processing,
+            // This means we're now on an outbound flow, and the endpoint will not
+            // be called.  Be sure to mark the context and message as such.
+            try {
+                Message msg = ((MessageFactory)FactoryRegistry.getFactory(MessageFactory.class)).createFrom(((SOAPMessageContext)handlerMessageContext).getMessage());
+                msgCtx.setMessage(msg);
+                return false;
+            } catch (XMLStreamException e) {
+                // TODO log it
+                throw ExceptionFactory.makeWebServiceException(e);
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Invoke OutboundHandlers
+     * 
+     * @param msgCtx
+     */
+    public static boolean invokeOutboundHandlers(MessageContext msgCtx,
+            EndpointDescription endpointDesc, HandlerChainProcessor.MEP mep, boolean isOneWay) {
+        List<String> handlers = endpointDesc.getHandlerList();
+
+        // TODO you may need to hard-code add some handlers until we
+        // actually have useful code under EndpointDescription.getHandlerList()
+        int numHandlers = handlers.size();
+
+        javax.xml.ws.handler.MessageContext handlerMessageContext = null;
+        if (numHandlers > 0) {
+            handlerMessageContext = findOrCreateMessageContext(msgCtx);
+        } else {
+            return true;
+        }
+
+        // TODO probably don't want to make the newInstances here -- use
+        // RuntimeDescription instead?
+        // make instances of all the handlers
+        ArrayList<Handler> handlerInstances = createHandlerInstances(endpointDesc);
+
+        HandlerChainProcessor processor = new HandlerChainProcessor(
+                handlerInstances);
+
+        // if not one-way, expect a response
+        if (msgCtx.getMessage().isFault()) {
+                processor.processFault(handlerMessageContext,
+                    HandlerChainProcessor.Direction.OUT);
+        } else {
+                handlerMessageContext = processor.processChain(handlerMessageContext,
+                                HandlerChainProcessor.Direction.OUT,
+                                mep, !isOneWay);
+        }
+
+        if (handlerMessageContext.get(javax.xml.ws.handler.MessageContext.MESSAGE_OUTBOUND_PROPERTY).equals(false)
+                        && mep.equals(HandlerChainProcessor.MEP.REQUEST)) {
+                // uh-oh.  We've changed directions on the client outbound handler processing,
+                // This means we're now on an inbound flow, and the service will not
+                // be called.  Be sure to mark the context and message as such.
+                try {
+                        Message msg = ((MessageFactory)FactoryRegistry.getFactory(MessageFactory.class)).createFrom(((SOAPMessageContext)handlerMessageContext).getMessage());
+                        msgCtx.setMessage(msg);
+                        return false;
+                } catch (XMLStreamException e) {
+                        // TODO log it
+                        throw ExceptionFactory.makeWebServiceException(e);
+                }
+        }
+
+        return true;
+    }
+
+    /**
+     * Find or Create Handler Message Context
+     * @param mc
+     * @return javax.xml.ws.handler.MessageContext
+     */
+    private static javax.xml.ws.handler.MessageContext findOrCreateMessageContext(MessageContext mc) {
+        // See if a soap message context is already present on the WebServiceContext
+        javax.xml.ws.handler.MessageContext handlerMessageContext = null;
+        ServiceContext serviceContext = mc.getAxisMessageContext().getServiceContext();
+        WebServiceContext ws = (WebServiceContext)serviceContext.getProperty(EndpointLifecycleManagerImpl.WEBSERVICE_MESSAGE_CONTEXT);
+
+        if (ws != null) {
+            handlerMessageContext = ws.getMessageContext();
+        }
+
+        if (handlerMessageContext == null) {
+            handlerMessageContext = createSOAPMessageContext(mc);
+        }
+
+        return handlerMessageContext; 
+    }
+
+    /**
+     * @param mc
+     * @return new SOAPMessageContext
+     */
+    private static javax.xml.ws.handler.MessageContext createSOAPMessageContext(MessageContext mc){
+        SoapMessageContext soapMessageContext = (SoapMessageContext)MessageContextFactory.createSoapMessageContext(mc);
+        ContextUtils.addProperties(soapMessageContext, mc);
+        return soapMessageContext;
+     }
+
+    // TODO method is for TEST only.  instances will be created elsewhere
+    private static ArrayList<Handler> createHandlerInstances(EndpointDescription ed) {
+        // TODO remove this.  Handlers will have already been instantiated when
+        // we start using the handlerresolver to get our list.
+
+        List<String> handlers = ed.getHandlerList();
+        int numHandlers = handlers.size();
+
+        ArrayList<Handler> handlerInstances = new ArrayList<Handler>();
+        try {
+                for (int i = 0; i < numHandlers; i++) {
+                        handlerInstances.add((Handler) Class.forName(handlers.get(i)).newInstance());
+                }
+        } catch (Exception e) {
+                e.printStackTrace();
+        }
+
+        return handlerInstances;
+    }
+
+}
+
+

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java Sun Mar 25 21:25:20 2007
@@ -1,3 +1,21 @@
+/*
+ * 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.handler;
 
 import java.security.PrivilegedActionException;

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/LogicalMessageContext.java Sun Mar 25 21:25:20 2007
@@ -1,18 +1,20 @@
 /*
- * Copyright 2006 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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
- *
+ * 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.
+ *      
+ * 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.handler;
 
@@ -36,7 +38,7 @@
 		super(mc);
 	}
 
-	public LogicalMessage getMessage() {
+	public LogicalMessage getSource() {
         return null;
     }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/ProtectedMessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/ProtectedMessageContext.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/ProtectedMessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/ProtectedMessageContext.java Sun Mar 25 21:25:20 2007
@@ -1,18 +1,20 @@
 /*
- * Copyright 2006 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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
- *
+ * 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.
+ *      
+ * 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.handler;
 
@@ -33,7 +35,7 @@
  */
 public class ProtectedMessageContext implements javax.xml.ws.handler.MessageContext {
     
-    private MessageContext msgContext;
+    protected MessageContext msgContext;
     private Map<String, Scope> scope = new Hashtable<String, Scope>();
     public ProtectedMessageContext() {
         //do nothing

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java Sun Mar 25 21:25:20 2007
@@ -1,18 +1,20 @@
 /*
- * Copyright 2006 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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
- *
+ * 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.
+ *      
+ * 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.handler;
 
@@ -22,11 +24,15 @@
 import javax.xml.bind.JAXBContext;
 import javax.xml.namespace.QName;
 import javax.xml.soap.SOAPMessage;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
 
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
 
 /**
  * The SOAPMessageContext is the context handed to SOAP-based application
@@ -60,5 +66,12 @@
     }
 
     public void setMessage(SOAPMessage soapmessage) {
+    	// TODO I don't like this at all.
+    	try {
+    		Message msg = ((MessageFactory)FactoryRegistry.getFactory(MessageFactory.class)).createFrom(soapmessage);
+    		msgContext.setMessage(msg);
+    	} catch (XMLStreamException e) {
+    		// TODO log it, and throw something?
+    	}
     }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java Sun Mar 25 21:25:20 2007
@@ -31,6 +31,7 @@
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.java.security.AccessController;
@@ -44,6 +45,8 @@
 import org.apache.axis2.jaxws.description.DescriptionFactory;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.description.ServiceDescription;
+import org.apache.axis2.jaxws.handler.HandlerChainProcessor;
+import org.apache.axis2.jaxws.handler.HandlerInvokerUtils;
 import org.apache.axis2.jaxws.handler.SoapMessageContext;
 import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.jaxws.message.Message;
@@ -57,13 +60,12 @@
 import org.apache.axis2.jaxws.server.dispatcher.factory.EndpointDispatcherFactory;
 import org.apache.axis2.jaxws.server.endpoint.lifecycle.EndpointLifecycleManager;
 import org.apache.axis2.jaxws.server.endpoint.lifecycle.factory.EndpointLifecycleManagerFactory;
-import org.apache.axis2.jaxws.server.endpoint.lifecycle.impl.EndpointLifecycleManagerImpl;
 import org.apache.axis2.jaxws.spi.Constants;
+import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004_Constants;
+import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2006Constants;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-
-
 /**
  * The EndpointController is the server side equivalent to the
  * InvocationController on the client side.  It is an abstraction of the server
@@ -78,8 +80,12 @@
 public class EndpointController {
     
     private static final Log log = LogFactory.getLog(EndpointController.class);
-	private static final String PARAM_SERVICE_CLASS = "ServiceClass";
-    public EndpointController() {}
+    
+    private static final String PARAM_SERVICE_CLASS = "ServiceClass";
+    
+    public EndpointController() {
+        //do nothing
+    }
 
     /**
      * This method is used to start the JAX-WS invocation of a target endpoint.
@@ -137,20 +143,29 @@
             // the request message if appropriate.
             saveRequestMessage(requestMsgCtx);
             
-            // Invoke inbound application handlers.
-            invokeInboundHandlers(requestMsgCtx);
- 
-            // Dispatch to the 
-            EndpointDispatcher dispatcher = getEndpointDispatcher(implClass, serviceInstance); 
-            try {
-                responseMsgContext = dispatcher.invoke(requestMsgCtx);
-            } finally {
-                // Passed pivot point
-                requestMsgCtx.getMessage().setPostPivot();
-            }
+            // Invoke inbound application handlers.  It's safe to use the first object on the iterator because there is
+            // always exactly one EndpointDescription on a server invoke
+            boolean success = HandlerInvokerUtils.invokeInboundHandlers(requestMsgCtx, serviceDesc.getEndpointDescriptions_AsCollection().iterator().next(), HandlerChainProcessor.MEP.REQUEST, isOneWay(requestMsgCtx.getAxisMessageContext()));
+
+            if (success) {
             
-            // Invoke outbound application handlers
-            invokeOutboundHandlers(requestMsgCtx);
+            	// Dispatch to the 
+            	EndpointDispatcher dispatcher = getEndpointDispatcher(implClass, serviceInstance); 
+            	try {
+            		responseMsgContext = dispatcher.invoke(requestMsgCtx);
+            	} finally {
+            		// Passed pivot point
+            		requestMsgCtx.getMessage().setPostPivot();
+            	}
+            
+            	// Invoke outbound application handlers.  It's safe to use the first object on the iterator because there is
+            	// always exactly one EndpointDescription on a server invoke
+            	HandlerInvokerUtils.invokeOutboundHandlers(responseMsgContext, serviceDesc.getEndpointDescriptions_AsCollection().iterator().next(), HandlerChainProcessor.MEP.RESPONSE, false);
+            } else { // the inbound handler chain must have had a problem, and we've reversed directions
+            	responseMsgContext = MessageContextUtils.createResponseMessageContext(requestMsgCtx);
+            	// since we've reversed directions, the message has "become a response message" (section 9.3.2.1, footnote superscript 2)
+            	responseMsgContext.setMessage(requestMsgCtx.getMessage());
+            }
             
         } catch (Exception e) {
             // TODO for now, throw it.  We probably should try to make an XMLFault object and set it on the message
@@ -165,68 +180,6 @@
         return ic;
     }
     
-    /**
-     * Invoke Inbound Handlers
-     * @param requestMsgCtx
-     */
-    private void invokeInboundHandlers(MessageContext requestMsgCtx) {
-        // Stubbed out code
-        int numHandlers = 0;
-        
-        javax.xml.ws.handler.MessageContext handlerMessageContext = null;
-        if (numHandlers > 0) {
-            handlerMessageContext =findOrCreateMessageContext(requestMsgCtx);
-        }
-        
-        // TODO Invoke Handlers
-    }
-    
-    
-    
-    /**
-     * Invoke OutboundHandlers
-     * @param responseMsgCtx
-     */
-    private void invokeOutboundHandlers(MessageContext responseMsgCtx) {
-        // Stubbed out code
-        int numHandlers = 0;
-        
-        javax.xml.ws.handler.MessageContext handlerMessageContext = null;
-        if (numHandlers > 0) {
-            handlerMessageContext =findOrCreateMessageContext(responseMsgCtx);
-        }
-        
-        // TODO Invoke Handlers
-    }
-    
-    /**
-     * Find or Create Handler Message Context
-     * @param mc
-     * @return javax.xml.ws.handler.MessageContext
-     */
-    private javax.xml.ws.handler.MessageContext findOrCreateMessageContext(MessageContext mc) {
-        // See if a soap message context is already present on the WebServiceContext
-        javax.xml.ws.handler.MessageContext handlerMessageContext = null;
-        ServiceContext serviceContext = mc.getAxisMessageContext().getServiceContext();
-        WebServiceContext ws = (WebServiceContext)serviceContext.getProperty(EndpointLifecycleManagerImpl.WEBSERVICE_MESSAGE_CONTEXT);
-        if (ws != null) {
-            handlerMessageContext = ws.getMessageContext();
-        }
-        if (handlerMessageContext == null) {
-            handlerMessageContext = createSOAPMessageContext(mc);
-        }
-        return handlerMessageContext; 
-    }
-    
-    /**
-     * @param mc
-     * @return new SOAPMessageContext
-     */
-    private javax.xml.ws.handler.MessageContext createSOAPMessageContext(MessageContext mc){
-        SoapMessageContext soapMessageContext = (SoapMessageContext)MessageContextFactory.createSoapMessageContext(mc);
-        ContextUtils.addProperties(soapMessageContext, mc);
-        return soapMessageContext;
-     }
     /*
 	 * Get the appropriate EndpointDispatcher for a given service endpoint.
 	 */
@@ -316,8 +269,8 @@
             return sd;
         }
         else {
-            ServiceDescription sd = DescriptionFactory.
-                createServiceDescriptionFromServiceImpl(implClass, axisSvc);
+            ServiceDescription sd = DescriptionFactory.createServiceDescriptionFromServiceImpl(implClass, axisSvc);
+                //createServiceDescriptionFromServiceImpl(implClass, axisSvc);
             return sd;
         }
     }
@@ -371,7 +324,7 @@
    */
    private void saveRequestMessage(MessageContext requestMsgContext) {
        
-       // TESTING...FORCE SAVING THE REQUEST MESSAGE
+       // TODO: TESTING...FORCE SAVING THE REQUEST MESSAGE
        // requestMsgContext.getAxisMessageContext().setProperty(Constants.SAVE_REQUEST_MSG, Boolean.TRUE);
        // END TESTING
        
@@ -415,5 +368,23 @@
        // String text = requestMsgContext.getMessage().getAsOMElement().toString();
        // System.out.println("Persist Message" + text);
        // END TESTING
+   }
+   
+   /*
+    * Determine if this is a one-way invocation or not.
+    */
+   public static boolean isOneWay(org.apache.axis2.context.MessageContext mc) {
+       if (mc != null) {
+           AxisOperation op = mc.getAxisOperation();
+           String mep = op.getMessageExchangePattern();
+           
+           if (mep.equals(WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY) || 
+               mep.equals(WSDL20_2004_Constants.MEP_URI_IN_ONLY) || 
+               mep.equals(WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY) || 
+               mep.equals(WSDL20_2006Constants.MEP_URI_IN_ONLY)) {
+               return true;
+           }
+       }
+       return false;
    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/ProviderDispatcher.java Sun Mar 25 21:25:20 2007
@@ -50,6 +50,7 @@
 import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
 import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.server.EndpointController;
 import org.apache.axis2.jaxws.utility.ClassUtils;
 import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004_Constants;
 import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2006Constants;
@@ -187,7 +188,7 @@
 
         // Create the response MessageContext
         MessageContext responseMsgCtx = null;
-        if (!isOneWay(mc.getAxisMessageContext())) {
+        if (!EndpointController.isOneWay(mc.getAxisMessageContext())) {
             if (faultThrown) {
                 // If a fault was thrown, we need to create a slightly different
                 // MessageContext, than in the response path.
@@ -416,21 +417,4 @@
         return blockFactory;
     }
     
-    /*
-     * Determine if this is a one-way invocation or not.
-     */
-    private boolean isOneWay(org.apache.axis2.context.MessageContext mc) {
-        if (mc != null) {
-            AxisOperation op = mc.getAxisOperation();
-            String mep = op.getMessageExchangePattern();
-            
-            if (mep.equals(WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY) || 
-                mep.equals(WSDL20_2004_Constants.MEP_URI_IN_ONLY) || 
-                mep.equals(WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY) || 
-                mep.equals(WSDL20_2006Constants.MEP_URI_IN_ONLY)) {
-                return true;
-            }
-        }
-        return false;
-    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SAAJFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SAAJFactory.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SAAJFactory.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/utility/SAAJFactory.java Sun Mar 25 21:25:20 2007
@@ -1,144 +1,144 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * Licensed 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.utility;
-
-import java.lang.reflect.Method;
-
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPFactory;
-import javax.xml.ws.WebServiceException;
-
-import org.apache.axis2.jaxws.ExceptionFactory;
-import org.apache.axis2.jaxws.i18n.Messages;
-
-/**
- * Provides convenience methods to construct a SOAP 1.1 or SOAP 1.2 SAAJ MessageFactory or SOAPFactory.
- * The code uses reflection; thus, when Axis2 upgrades to SAAJ 1.3, no changes will be neded to this class.
- *
- */
-public class SAAJFactory {
-
-    private static final String SOAP11_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
-    private static final String SOAP12_ENV_NS = "http://www.w3.org/2003/05/soap-envelope";
-    
-    // Protocol Names per the SAAJ 1.3 specification.
-    public static final String SOAP_1_1_PROTOCOL = "SOAP 1.1 Protocol"; 
-    public static final String SOAP_1_2_PROTOCOL = "SOAP 1.2 Protocol";
-    public static final String DYNAMIC_PROTOCOL  = "Dynamic Protocol"; 
-    
-    /**
-     * Create SOAPFactory using information from the envelope namespace 
-     * @param namespace
-     * @return
-     */
-    public static SOAPFactory createSOAPFactory(String namespace) throws WebServiceException, SOAPException {
-        Method m = getSOAPFactoryNewInstanceProtocolMethod();
-        SOAPFactory sf = null;
-        if (m == null) {
-            if (namespace.equals(SOAP11_ENV_NS)) {
-                sf = SOAPFactory.newInstance();
-            } else {
-                throw ExceptionFactory.makeWebServiceException(Messages.getMessage("SOAP12WithSAAJ12Err"));
-            }
-        } else {
-            String protocol = DYNAMIC_PROTOCOL;
-            if (namespace.equals(SOAP11_ENV_NS)) {
-                protocol = SOAP_1_1_PROTOCOL;
-            } else if (namespace.equals(SOAP12_ENV_NS)) {
-                protocol = SOAP_1_2_PROTOCOL;
-            } 
-            try {
-                sf = (SOAPFactory) m.invoke(null, new Object[] {protocol});
-            } catch (Exception e) {
-                throw ExceptionFactory.makeWebServiceException(e);
-            }
-        }
-        return sf;
-    }
-    
-    /**
-     * Create MessageFactory using information from the envelope namespace 
-     * @param namespace
-     * @return
-     */
-    public static MessageFactory createMessageFactory(String namespace) throws WebServiceException, SOAPException {
-        Method m = getMessageFactoryNewInstanceProtocolMethod();
-        MessageFactory mf = null;
-        if (m == null) {
-            if (namespace.equals(SOAP11_ENV_NS)) {
-                mf = MessageFactory.newInstance();
-            } else {
-                throw ExceptionFactory.makeWebServiceException(Messages.getMessage("SOAP12WithSAAJ12Err"));
-            }
-        } else {
-            String protocol = DYNAMIC_PROTOCOL;
-            if (namespace.equals(SOAP11_ENV_NS)) {
-                protocol = SOAP_1_1_PROTOCOL;
-            } else if (namespace.equals(SOAP12_ENV_NS)) {
-                protocol = SOAP_1_2_PROTOCOL;
-            } 
-            try {
-                mf = (MessageFactory) m.invoke(null, new Object[] {protocol});
-            } catch (Exception e) {
-                throw ExceptionFactory.makeWebServiceException(e);
-            }
-        }
-        return mf;
-    }
-    
-    private static Method messageFactoryNewInstanceProtocolMethod = null;
-    
-    /**
-     * SAAJ 1.3 has a newInstance method that has a protocol parameter.
-     * @return newInstance(String) method if available
-     */
-    private static Method getMessageFactoryNewInstanceProtocolMethod() {
-        if (messageFactoryNewInstanceProtocolMethod == null) {
-            try {
-                messageFactoryNewInstanceProtocolMethod = MessageFactory.class.getMethod("newInstance", new Class[] {String.class});
-            } catch (Exception e) {
-                // TODO Might want to log this.
-                // Flow to here indicates that the installed SAAJ model does not support version 1.3
-                messageFactoryNewInstanceProtocolMethod = null;
-            }
-        }
-        return messageFactoryNewInstanceProtocolMethod;
-    }
-    
-    private static Method soapFactoryNewInstanceProtocolMethod = null;
-    
-    /**
-     * SAAJ 1.3 has a newInstance method that has a protocol parameter.
-     * @return newInstance(String) method if available
-     */
-    private static Method getSOAPFactoryNewInstanceProtocolMethod() {
-        if (soapFactoryNewInstanceProtocolMethod == null) {
-            try {
-                soapFactoryNewInstanceProtocolMethod = SOAPFactory.class.getMethod("newInstance", new Class[] {String.class});
-            } catch (Exception e) {
-                // TODO Might want to log this.
-                // Flow to here indicates that the installed SAAJ model does not support version 1.3
-                soapFactoryNewInstanceProtocolMethod = null;
-            }
-        }
-        return soapFactoryNewInstanceProtocolMethod;
-    }
-
-
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed 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.utility;
+
+import java.lang.reflect.Method;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPFactory;
+import javax.xml.ws.WebServiceException;
+
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.i18n.Messages;
+
+/**
+ * Provides convenience methods to construct a SOAP 1.1 or SOAP 1.2 SAAJ MessageFactory or SOAPFactory.
+ * The code uses reflection; thus, when Axis2 upgrades to SAAJ 1.3, no changes will be neded to this class.
+ *
+ */
+public class SAAJFactory {
+
+    private static final String SOAP11_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
+    private static final String SOAP12_ENV_NS = "http://www.w3.org/2003/05/soap-envelope";
+    
+    // Protocol Names per the SAAJ 1.3 specification.
+    public static final String SOAP_1_1_PROTOCOL = "SOAP 1.1 Protocol"; 
+    public static final String SOAP_1_2_PROTOCOL = "SOAP 1.2 Protocol";
+    public static final String DYNAMIC_PROTOCOL  = "Dynamic Protocol"; 
+    
+    /**
+     * Create SOAPFactory using information from the envelope namespace 
+     * @param namespace
+     * @return
+     */
+    public static SOAPFactory createSOAPFactory(String namespace) throws WebServiceException, SOAPException {
+        Method m = getSOAPFactoryNewInstanceProtocolMethod();
+        SOAPFactory sf = null;
+        if (m == null) {
+            if (namespace.equals(SOAP11_ENV_NS)) {
+                sf = SOAPFactory.newInstance();
+            } else {
+                throw ExceptionFactory.makeWebServiceException(Messages.getMessage("SOAP12WithSAAJ12Err"));
+            }
+        } else {
+            String protocol = DYNAMIC_PROTOCOL;
+            if (namespace.equals(SOAP11_ENV_NS)) {
+                protocol = SOAP_1_1_PROTOCOL;
+            } else if (namespace.equals(SOAP12_ENV_NS)) {
+                protocol = SOAP_1_2_PROTOCOL;
+            } 
+            try {
+                sf = (SOAPFactory) m.invoke(null, new Object[] {protocol});
+            } catch (Exception e) {
+                throw ExceptionFactory.makeWebServiceException(e);
+            }
+        }
+        return sf;
+    }
+    
+    /**
+     * Create MessageFactory using information from the envelope namespace 
+     * @param namespace
+     * @return
+     */
+    public static MessageFactory createMessageFactory(String namespace) throws WebServiceException, SOAPException {
+        Method m = getMessageFactoryNewInstanceProtocolMethod();
+        MessageFactory mf = null;
+        if (m == null) {
+            if (namespace.equals(SOAP11_ENV_NS)) {
+                mf = MessageFactory.newInstance();
+            } else {
+                throw ExceptionFactory.makeWebServiceException(Messages.getMessage("SOAP12WithSAAJ12Err"));
+            }
+        } else {
+            String protocol = DYNAMIC_PROTOCOL;
+            if (namespace.equals(SOAP11_ENV_NS)) {
+                protocol = SOAP_1_1_PROTOCOL;
+            } else if (namespace.equals(SOAP12_ENV_NS)) {
+                protocol = SOAP_1_2_PROTOCOL;
+            } 
+            try {
+                mf = (MessageFactory) m.invoke(null, new Object[] {protocol});
+            } catch (Exception e) {
+                throw ExceptionFactory.makeWebServiceException(e);
+            }
+        }
+        return mf;
+    }
+    
+    private static Method messageFactoryNewInstanceProtocolMethod = null;
+    
+    /**
+     * SAAJ 1.3 has a newInstance method that has a protocol parameter.
+     * @return newInstance(String) method if available
+     */
+    private static Method getMessageFactoryNewInstanceProtocolMethod() {
+        if (messageFactoryNewInstanceProtocolMethod == null) {
+            try {
+                messageFactoryNewInstanceProtocolMethod = MessageFactory.class.getMethod("newInstance", new Class[] {String.class});
+            } catch (Exception e) {
+                // TODO Might want to log this.
+                // Flow to here indicates that the installed SAAJ model does not support version 1.3
+                messageFactoryNewInstanceProtocolMethod = null;
+            }
+        }
+        return messageFactoryNewInstanceProtocolMethod;
+    }
+    
+    private static Method soapFactoryNewInstanceProtocolMethod = null;
+    
+    /**
+     * SAAJ 1.3 has a newInstance method that has a protocol parameter.
+     * @return newInstance(String) method if available
+     */
+    private static Method getSOAPFactoryNewInstanceProtocolMethod() {
+        if (soapFactoryNewInstanceProtocolMethod == null) {
+            try {
+                soapFactoryNewInstanceProtocolMethod = SOAPFactory.class.getMethod("newInstance", new Class[] {String.class});
+            } catch (Exception e) {
+                // TODO Might want to log this.
+                // Flow to here indicates that the installed SAAJ model does not support version 1.3
+                soapFactoryNewInstanceProtocolMethod = null;
+            }
+        }
+        return soapFactoryNewInstanceProtocolMethod;
+    }
+
+
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Sun Mar 25 21:25:20 2007
@@ -145,17 +145,19 @@
 
         suite.addTestSuite(AddressBookTests.class);
         suite.addTestSuite(MtomSampleTests.class);
+        
         // TODO: This test fails only on Solaris
-//        suite.addTestSuite(MtomSampleByteArrayTests.class);
+        //suite.addTestSuite(MtomSampleByteArrayTests.class);
         suite.addTestSuite(BareTests.class);
         suite.addTestSuite(NonWrapTests.class);
         suite.addTestSuite(WSGenTests.class);
         suite.addTestSuite(WrapTests.class);
         suite.addTestSuite(DLWMinTests.class);
         suite.addTestSuite(NonAnonymousComplexTypeTests.class);
-        suite.addTestSuite(AddNumbersTests.class);
+        //suite.addTestSuite(AddNumbersTests.class);
+        
         // TODO: This test intermittently fails on Linux and with trace enabled.
-//        suite.addTestSuite(ParallelAsyncTests.class);
+        //suite.addTestSuite(ParallelAsyncTests.class);
         suite.addTestSuite(FaultyWebServiceTests.class);
         suite.addTestSuite(FaultsServiceTests.class);
 

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersTests.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/AddNumbersTests.java Sun Mar 25 21:25:20 2007
@@ -19,6 +19,7 @@
 package org.apache.axis2.jaxws.sample;
 
 import javax.xml.ws.BindingProvider;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import junit.framework.TestCase;
 import org.apache.axis2.jaxws.sample.addnumbers.AddNumbersPortType;
@@ -41,13 +42,40 @@
                     axisEndpoint);	
 			int total = proxy.addNumbers(10,10);
 			
-			System.out.println("Total =" +total);
+            assertEquals("With handler manipulation, total should be 2 less than a proper sumation.", 18, total);
+			System.out.println("Total (after handler manipulation) = " +total);
 			System.out.println("----------------------------------");
 		} catch(Exception e) {
 			e.printStackTrace();
 			fail();
 		}
 	}
+    
+    public void testAddNumbersWithFault() {
+        try{
+            System.out.println("----------------------------------");
+            System.out.println("test: " + getName());
+            
+            AddNumbersService service = new AddNumbersService();
+            AddNumbersPortType proxy = service.getAddNumbersPort();
+            
+            BindingProvider p = (BindingProvider)proxy;
+            p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
+                    axisEndpoint);  
+            // value 99 triggers the handler to throw an exception, but does
+            // NOT trigger the AddNumbersHandler.handlefault method.
+            // The spec does not call the handlefault method of a handler that
+            // causes a flow reversal
+            int total = proxy.addNumbers(99,10);
+            
+            fail("We should have got an exception due to the handler.");
+        } catch(Exception e) {
+            e.printStackTrace();
+            assertTrue("Exception should be SOAPFaultException", e instanceof SOAPFaultException);
+            assertEquals(((SOAPFaultException)e).getMessage(), "I don't like the value 99");
+        }
+        System.out.println("----------------------------------");
+    }
     
     public void testOneWay() {
         try {

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersFault_Exception.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersFault_Exception.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersFault_Exception.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersFault_Exception.java Sun Mar 25 21:25:20 2007
@@ -1,4 +1,21 @@
-
+/*
+ * 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.sample.addnumbers;
 
 import javax.xml.ws.WebFault;

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersLogicalHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersLogicalHandler.java?view=auto&rev=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersLogicalHandler.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersLogicalHandler.java Sun Mar 25 21:25:20 2007
@@ -0,0 +1,76 @@
+/*
+ * 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.sample.addnumbers;
+
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.ws.ProtocolException;
+import javax.xml.ws.handler.MessageContext;
+
+import org.apache.axis2.jaxws.handler.SoapMessageContext;
+
+public class AddNumbersLogicalHandler implements javax.xml.ws.handler.LogicalHandler {
+
+    public void close(MessageContext messagecontext) {
+        
+    }
+
+    public boolean handleFault(MessageContext messagecontext) {
+        Boolean outbound = (Boolean)messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+        if (outbound) {  // outbound response if we're on the server
+            SOAPMessage msg = ((SoapMessageContext)messagecontext).getMessage();
+            SOAPPart part = msg.getSOAPPart();
+            part.getFirstChild().getFirstChild().getFirstChild().setTextContent("a handler was here");
+        }
+        return true;
+    }
+
+    /*
+     * this test handleMessage method is obviously not what a customer might write, but it does
+     * the trick for kicking the tires in the handler framework.  The AddNumbers service takes two
+     * ints as incoming params, adds them, and returns the sum.  This method subtracts 1 from the 
+     * first int on the inbound request, and subtracts 1 from the int on the outbound response.
+     * So the client app should expect a sum 2 less than a sum without this handler manipulating
+     * the SOAP message.
+     */
+    public boolean handleMessage(MessageContext messagecontext) {
+        Boolean outbound = (Boolean)messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+        if (!outbound) {  // inbound request if we're on the server
+            SOAPMessage msg = ((SoapMessageContext)messagecontext).getMessage();
+            SOAPPart part = msg.getSOAPPart();
+            // hack-ish change, but it's for testing, so who cares.
+            String txt = part.getFirstChild().getFirstChild().getFirstChild().getFirstChild().getTextContent();
+            if (txt.equals("99")) {
+                throw new ProtocolException("I don't like the value 99");
+            }
+            txt = String.valueOf(Integer.valueOf(txt) - 1);
+            part.getFirstChild().getFirstChild().getFirstChild().getFirstChild().setTextContent(txt);
+            return true;
+        } else { // outbound response if we're on the server
+            SOAPMessage msg = ((SoapMessageContext)messagecontext).getMessage();
+            SOAPPart part = msg.getSOAPPart();
+            // hack-ish change, but it's for testing, so who cares.
+            String txt = part.getFirstChild().getFirstChild().getFirstChild().getTextContent();
+            txt = String.valueOf(Integer.valueOf(txt) - 1);
+            part.getFirstChild().getFirstChild().getFirstChild().getFirstChild().setTextContent(txt);
+            return true;
+        }
+    }
+
+}
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersPortType.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersPortType.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersPortType.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/addnumbers/AddNumbersPortType.java Sun Mar 25 21:25:20 2007
@@ -1,4 +1,21 @@
-
+/*
+ * 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.sample.addnumbers;
 
 import javax.jws.Oneway;

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java Sun Mar 25 21:25:20 2007
@@ -1,5 +1,6 @@
 package org.apache.axis2.jaxws.description;
 
+import java.util.Collection;
 import java.util.List;
 
 import javax.xml.namespace.QName;
@@ -47,6 +48,8 @@
 
 public interface ServiceDescription {
     public abstract EndpointDescription[] getEndpointDescriptions();
+    
+    public abstract Collection<EndpointDescription> getEndpointDescriptions_AsCollection();
 
     public abstract EndpointDescription getEndpointDescription(QName portQName);
 

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java?view=diff&rev=522411&r1=522410&r2=522411
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java Sun Mar 25 21:25:20 2007
@@ -21,6 +21,7 @@
 import java.net.URL;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -78,7 +79,7 @@
     private WSDLWrapper wsdlWrapper; 
     private WSDLWrapper generatedWsdlWrapper;
     
-    private Hashtable<QName, EndpointDescriptionImpl> endpointDescriptions = new Hashtable<QName, EndpointDescriptionImpl>();
+    private Map<QName, EndpointDescription> endpointDescriptions = new HashMap<QName, EndpointDescription>();
     
     private static final Log log = LogFactory.getLog(ServiceDescriptionImpl.class);
 
@@ -352,6 +353,10 @@
         return endpointDescriptions.values().toArray(new EndpointDescriptionImpl[0]);
     }
     
+    public Collection<EndpointDescription> getEndpointDescriptions_AsCollection() {
+        return endpointDescriptions.values();
+    }
+    
     /* (non-Javadoc)
      * @see org.apache.axis2.jaxws.description.ServiceDescription#getEndpointDescription(javax.xml.namespace.QName)
      */
@@ -377,15 +382,13 @@
     public EndpointDescription[] getEndpointDescription(Class seiClass) {
         EndpointDescription[] returnEndpointDesc = null;
         ArrayList<EndpointDescriptionImpl> matchingEndpoints = new ArrayList<EndpointDescriptionImpl>();
-        Enumeration<EndpointDescriptionImpl> endpointEnumeration = endpointDescriptions.elements();
-        while (endpointEnumeration.hasMoreElements()) {
-            EndpointDescriptionImpl endpointDescription = endpointEnumeration.nextElement();
+        for (EndpointDescription endpointDescription: endpointDescriptions.values()) {
             EndpointInterfaceDescription endpointInterfaceDesc = endpointDescription.getEndpointInterfaceDescription();
             // Note that Dispatch endpoints will not have an endpointInterface because the do not have an associated SEI
             if (endpointInterfaceDesc != null) {
                 Class endpointSEIClass = endpointInterfaceDesc.getSEIClass(); 
                 if (endpointSEIClass != null && endpointSEIClass.equals(seiClass)) {
-                    matchingEndpoints.add(endpointDescription);
+                    matchingEndpoints.add((EndpointDescriptionImpl) endpointDescription);
                 }
             }
         }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org