axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinth...@apache.org
Subject svn commit: r486025 - /webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
Date Tue, 12 Dec 2006 05:00:39 GMT
Author: chinthaka
Date: Mon Dec 11 21:00:39 2006
New Revision: 486025

URL: http://svn.apache.org/viewvc?view=rev&rev=486025
Log:
Copying SOAP and HTTP Headers to the fault message context, from the processing context.

Modified:
    webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java

Modified: webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java?view=diff&rev=486025&r1=486024&r2=486025
==============================================================================
--- webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
(original)
+++ webservices/axis2/branches/java/WSDL_2_0/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
Mon Dec 11 21:00:39 2006
@@ -19,24 +19,17 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Map;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.soap.SOAP11Constants;
-import org.apache.axiom.soap.SOAP12Constants;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFault;
-import org.apache.axiom.soap.SOAPFaultCode;
-import org.apache.axiom.soap.SOAPFaultDetail;
-import org.apache.axiom.soap.SOAPFaultNode;
-import org.apache.axiom.soap.SOAPFaultReason;
-import org.apache.axiom.soap.SOAPFaultRole;
-import org.apache.axiom.soap.SOAPProcessingException;
+import org.apache.axiom.soap.*;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
+import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.addressing.AddressingHelper;
 import org.apache.axis2.addressing.EndpointReference;
@@ -54,7 +47,7 @@
 import org.apache.axis2.wsdl.WSDLConstants;
 
 public class MessageContextBuilder {
-    
+
     /**
      * Creates a new 'response' message context based on a 'request' message context
      * Only deals with properties/fields that are the same for both 'normal' and fault responses.
@@ -68,7 +61,7 @@
         newmsgCtx.setTransportOut(inMessageContext.getTransportOut());
         newmsgCtx.setMessageID(UUIDGenerator.getUUID());
         newmsgCtx.addRelatesTo(new RelatesTo(inMessageContext.getOptions().getMessageId()));
-        
+
         newmsgCtx.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,
                 inMessageContext.getProperty(AddressingConstants.WS_ADDRESSING_VERSION));
         newmsgCtx.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES,
@@ -80,28 +73,28 @@
         newmsgCtx.setDoingREST(inMessageContext.isDoingREST());
 
         newmsgCtx.setOperationContext(inMessageContext.getOperationContext());
-        
+
         ServiceContext serviceContext = inMessageContext.getServiceContext();
         if (serviceContext != null) {
             newmsgCtx.setServiceContext(serviceContext);
         }
-        
+
         newmsgCtx.setProperty(MessageContext.TRANSPORT_OUT,
                 inMessageContext.getProperty(MessageContext.TRANSPORT_OUT));
         newmsgCtx.setProperty(Constants.OUT_TRANSPORT_INFO,
                 inMessageContext.getProperty(Constants.OUT_TRANSPORT_INFO));
-        
+
         return newmsgCtx;
     }
-    
+
     /**
      * Creates a MessageContext for use with a non-fault response based on an request MessageContext
      */
     public static MessageContext createOutMessageContext(MessageContext inMessageContext)
throws AxisFault {
-        
+
         // Create a basic response MessageContext with basic fields copied
-        MessageContext newmsgCtx = createResponseMessageContext(inMessageContext); 
-        
+        MessageContext newmsgCtx = createResponseMessageContext(inMessageContext);
+
         // Simple response so set To to value of inbound ReplyTo
         newmsgCtx.setTo(inMessageContext.getReplyTo());
 
@@ -120,18 +113,18 @@
                         Constants.SERVICE_GROUP_ID, Constants.AXIS2_NAMESPACE_PREFIX), serviceGroupContextId);
             }
         } else {
-            newmsgCtx.setReplyTo(new EndpointReference(AddressingConstants.Final.WSA_NONE_URI));
           
+            newmsgCtx.setReplyTo(new EndpointReference(AddressingConstants.Final.WSA_NONE_URI));
         }
-        
+
         // Set wsa:Action for response message
         // Use specified value if available
         AxisOperation ao = inMessageContext.getAxisOperation();
-        if ((ao!=null) && (ao.getOutputAction() != null)) {
+        if ((ao != null) && (ao.getOutputAction() != null)) {
             newmsgCtx.setWSAAction(ao.getOutputAction());
         } else { // If not, simply copy the request value. Almost always invalid.
             newmsgCtx.setWSAAction(inMessageContext.getWSAAction());
         }
-        
+
         newmsgCtx.setAxisMessage(ao.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE));
 
         newmsgCtx.setDoingMTOM(inMessageContext.isDoingMTOM());
@@ -140,7 +133,7 @@
 
         // Ensure transport settings match the scheme for the To EPR
         setupCorrectTransportOut(newmsgCtx);
-        
+
         return newmsgCtx;
     }
 
@@ -158,27 +151,28 @@
 
         // Create a basic response MessageContext with basic fields copied
         MessageContext faultContext = createResponseMessageContext(processingContext);
-        
+
         // Register the fault message context
-        if (processingContext.getAxisOperation() != null && processingContext.getOperationContext()
!= null) {
+        if (processingContext.getAxisOperation() != null && processingContext.getOperationContext()
!= null)
+        {
             processingContext.getAxisOperation().addFaultMessageContext(faultContext, processingContext.getOperationContext());
         }
 
         faultContext.setProcessingFault(true);
         faultContext.setServerSide(true);
-        
+
         // Not worth setting up the session information on a fault flow
         faultContext.setReplyTo(new EndpointReference(AddressingConstants.Final.WSA_NONE_URI));
 
         // Set wsa:Action for response message
         // Use specified value if available
         AxisOperation op = processingContext.getAxisOperation();
-        if(op != null && op.getFaultAction()!=null){
+        if (op != null && op.getFaultAction() != null) {
             faultContext.setWSAAction(op.getFaultAction());
-        }else{ //If, for some reason there is no value set, should use a sensible action.
+        } else { //If, for some reason there is no value set, should use a sensible action.
             faultContext.setWSAAction(Final.WSA_SOAP_FAULT_ACTION);
         }
-        
+
         // there are some information  that the fault thrower wants to pass to the fault
path.
         // Means that the fault is a ws-addressing one hence use the ws-addressing fault
action.
         Object faultInfoForHeaders = processingContext.getProperty(Constants.FAULT_INFORMATION_FOR_HEADERS);
@@ -196,7 +190,7 @@
         } else {
             faultContext.setTo(processingContext.getReplyTo());
         }
-        
+
         // do Target Resolution
         faultContext.getConfigurationContext().getAxisConfiguration().getTargetResolverChain().resolveTarget(faultContext);
 
@@ -206,14 +200,27 @@
         SOAPEnvelope envelope = createFaultEnvelope(processingContext, e);
         faultContext.setEnvelope(envelope);
 
+        //get the SOAP headers, user is trying to send in the fault
+        List soapHeadersList = (List) processingContext.getProperty(SOAPConstants.HEADER_LOCAL_NAME);
+        if (soapHeadersList != null) {
+            SOAPHeader soapHeaderElement = envelope.getHeader();
+            for (int i = 0; i < soapHeadersList.size(); i++) {
+                OMElement soapHeaderBlock = (OMElement) soapHeadersList.get(i);
+                soapHeaderElement.addChild(soapHeaderBlock);
+            }
+        }
+
+        // now add HTTP Headers
+        faultContext.setProperty(HTTPConstants.HTTP_HEADERS, processingContext.getProperty(HTTPConstants.HTTP_HEADERS));
+
         return faultContext;
     }
-    
+
     /**
      * Ensure that if the scheme of the To EPR for the response is different than the
      * transport used for the request that the correct TransportOut is available
      */
-    private static void setupCorrectTransportOut(MessageContext context) throws AxisFault{
+    private static void setupCorrectTransportOut(MessageContext context) throws AxisFault
{
         // Determine that we have the correct transport available.
         TransportOutDescription transportOut = context.getTransportOut();
 
@@ -240,7 +247,7 @@
             throw new AxisFault(urise);
         }
     }
-    
+
     /**
      * Information to create the SOAPFault can be extracted from different places.
      * 1. Those information may have been put in to the message context by some handler.
When someone
@@ -270,7 +277,6 @@
      * -- EC
      *
      * @param context
-     * @param fault
      * @param e
      */
     private static SOAPEnvelope createFaultEnvelope(MessageContext context, Throwable e)
{
@@ -283,7 +289,7 @@
             envelope = OMAbstractFactory.getSOAP12Factory().getDefaultFaultEnvelope();
         }
         SOAPFault fault = envelope.getBody().getFault();
-        
+
         SOAPProcessingException soapException = null;
         AxisFault axisFault = null;
 
@@ -319,7 +325,8 @@
         } else if (axisFault != null) {
 
             Map faultElementsMap = axisFault.getFaultElements();
-            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)
!= null) {
+            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)
!= null)
+            {
                 fault.setCode((SOAPFaultCode) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));
             } else {
                 QName faultCodeQName = axisFault.getFaultCode();
@@ -356,7 +363,8 @@
             message = soapException.getMessage();
         } else if (axisFault != null) {
             Map faultElementsMap = axisFault.getFaultElements();
-            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)
!= null) {
+            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)
!= null)
+            {
                 fault.setReason((SOAPFaultReason) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));
             } else {
                 message = axisFault.getReason();
@@ -381,7 +389,8 @@
             fault.getRole().setText((String) faultRole);
         } else if (axisFault != null) {
             Map faultElementsMap = axisFault.getFaultElements();
-            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME)
!= null) {
+            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME)
!= null)
+            {
                 fault.setRole((SOAPFaultRole) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));
             }
         }
@@ -391,7 +400,8 @@
             fault.getNode().setText((String) faultNode);
         } else if (axisFault != null) {
             Map faultElementsMap = axisFault.getFaultElements();
-            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME)
!= null) {
+            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME)
!= null)
+            {
                 fault.setNode((SOAPFaultNode) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));
             }
         }
@@ -401,14 +411,14 @@
         boolean sendStacktraceDetailsWithFaults = false;
         OperationContext oc = context.getOperationContext();
         Object flagFromContext = null;
-        if(oc!=null){
+        if (oc != null) {
             flagFromContext = context.getOperationContext().getProperty(Constants.Configuration.SEND_STACKTRACE_DETAILS_WITH_FAULTS);
         }
-        if(flagFromContext!=null){
+        if (flagFromContext != null) {
             sendStacktraceDetailsWithFaults = JavaUtils.isTrue(flagFromContext);
-        }else{
+        } else {
             Parameter param = context.getParameter(Constants.Configuration.SEND_STACKTRACE_DETAILS_WITH_FAULTS);
-            sendStacktraceDetailsWithFaults = JavaUtils.isTrue(param.getValue());    
+            sendStacktraceDetailsWithFaults = JavaUtils.isTrue(param.getValue());
         }
 
         Object faultDetail = context.getProperty(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME);
@@ -416,7 +426,8 @@
             fault.setDetail((SOAPFaultDetail) faultDetail);
         } else if (axisFault != null) {
             Map faultElementsMap = axisFault.getFaultElements();
-            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)
!= null) {
+            if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)
!= null)
+            {
                 fault.setDetail((SOAPFaultDetail) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
             } else {
                 OMElement detail = axisFault.getDetail();
@@ -436,7 +447,7 @@
 
         return envelope;
     }
-    
+
     /**
      * By the time the exception comes here it can be wrapped by so many levels. This will
crip down
      * to the root cause and get the initial error depending on the property
@@ -454,7 +465,7 @@
         }
         return throwable.getMessage();
     }
-    
+
     private static String getSenderFaultCode(OMNamespace soapNamespace) {
         return SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapNamespace.getNamespaceURI())
                 ? SOAP12Constants.SOAP_DEFAULT_NAMESPACE_PREFIX + ":"



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


Mime
View raw message