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 da...@apache.org on 2006/09/17 12:51:15 UTC
svn commit: r447044 -
/webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
Author: davidillsley
Date: Sun Sep 17 03:51:15 2006
New Revision: 447044
URL: http://svn.apache.org/viewvc?view=rev&rev=447044
Log:
Revert previous commit - r447031 - as it broke the unit tests on another platform (linux).
Will investigate and commit a better fix later.
Modified:
webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
Modified: webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java?view=diff&rev=447044&r1=447043&r2=447044
==============================================================================
--- webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java (original)
+++ webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java Sun Sep 17 03:51:15 2006
@@ -16,12 +16,6 @@
package org.apache.axis2.handlers.addressing;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
@@ -34,35 +28,68 @@
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
+import org.apache.axis2.util.JavaUtils;
import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.addressing.FinalFaultsHelper;
import org.apache.axis2.addressing.RelatesTo;
import org.apache.axis2.client.Options;
import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.util.JavaUtils;
-import org.apache.axis2.util.Utils;
+import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.wsdl.WSDLConstants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
public class AddressingOutHandler extends AddressingHandler {
-
- private static final Log log = LogFactory.getLog(AddressingOutHandler.class);
-
+
public void invoke(MessageContext msgContext) throws AxisFault {
SOAPFactory factory = (SOAPFactory)msgContext.getEnvelope().getOMFactory();
- if (isAddressingDisabled(msgContext)) {
+ OMNamespace addressingNamespaceObject;
+ String namespace = addressingNamespace;
+
+ // it should be able to disable addressing by some one.
+ Object property = msgContext.getProperty(DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
+ if (property == null && msgContext.getOperationContext() != null) {
+ // check in the IN message context, if available
+ MessageContext inMsgCtxt = msgContext.getOperationContext().getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ if (inMsgCtxt != null) {
+ property = inMsgCtxt.getProperty(DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
+ }
+ }
+ if (property != null && JavaUtils.isTrueExplicitly(property)) {
log.debug("Addressing is disabled .....");
return;
}
- String namespace = getAddressingNamespaceInUse(msgContext);
-
- OMNamespace addressingNamespaceObject = factory.createOMNamespace(namespace, WSA_DEFAULT_PREFIX);
+
+ Object addressingVersionFromCurrentMsgCtxt = msgContext.getProperty(WS_ADDRESSING_VERSION);
+ if (addressingVersionFromCurrentMsgCtxt != null) {
+ // since we support only two addressing versions I can avoid multiple ifs here.
+ // see that if message context property holds something other than Final.WSA_NAMESPACE
+ // we always defaults to Submission.WSA_NAMESPACE. Hope this is fine.
+ namespace = Final.WSA_NAMESPACE.equals(addressingVersionFromCurrentMsgCtxt)
+ ? Final.WSA_NAMESPACE : Submission.WSA_NAMESPACE;
+ } else if (msgContext.getOperationContext() != null)
+ { // check for a IN message context, else default to WSA Final
+ MessageContext inMessageContext = msgContext.getOperationContext()
+ .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ if (inMessageContext != null) {
+ namespace =
+ (String) inMessageContext.getProperty(
+ WS_ADDRESSING_VERSION);
+ }
+ }
+
+ if (namespace == null || "".equals(namespace)) {
+ namespace = Final.WSA_NAMESPACE;
+ }
+ addressingNamespaceObject = factory.createOMNamespace(
+ namespace, WSA_DEFAULT_PREFIX);
String anonymousURI = namespace.equals(Final.WSA_NAMESPACE) ? Final.WSA_ANONYMOUS_URL : Submission.WSA_ANONYMOUS_URL;
String relationshipType = namespace.equals(Final.WSA_NAMESPACE) ? Final.WSA_DEFAULT_RELATIONSHIP_TYPE : Submission.WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE;
@@ -73,6 +100,7 @@
// if there is no soap header in the envelope being processed, add one.
if (soapHeader == null) {
+// SOAPFactory soapFac = msgContext.isSOAP11() ? OMAbstractFactory.getSOAP11Factory() : OMAbstractFactory.getSOAP12Factory();
soapHeader = factory.createSOAPHeader(envelope);
}
@@ -85,7 +113,11 @@
// what if there are addressing headers already in the message. Do you replace that or not?
// Lets have a parameter to control that. The default behavior is you won't replace addressing
// headers if there are any (this was the case so far).
- boolean replaceHeaders = Utils.isExplicitlyTrue(msgContext, REPLACE_ADDRESSING_HEADERS);
+ Object replaceHeadersParam = msgContext.getProperty(REPLACE_ADDRESSING_HEADERS);
+ boolean replaceHeaders = false;
+ if (replaceHeadersParam != null) {
+ replaceHeaders = JavaUtils.isTrueExplicitly(replaceHeadersParam);
+ }
// processing WSA To
processToEPR(messageContextOptions, envelope, addressingNamespaceObject, namespace, replaceHeaders);
@@ -100,7 +132,7 @@
processFaultToEPR(messageContextOptions, envelope, addressingNamespaceObject, namespace, replaceHeaders);
String messageID = messageContextOptions.getMessageId();
- if (messageID != null && !shouldAddNewHeader(WSA_MESSAGE_ID, envelope,
+ if (messageID != null && !isAddressingHeaderAlreadyAvailable(WSA_MESSAGE_ID, envelope,
addressingNamespaceObject, replaceHeaders)) {//optional
processStringInfo(messageID, WSA_MESSAGE_ID, envelope, addressingNamespaceObject);
}
@@ -117,57 +149,6 @@
// We are done, cleanup the references
addressingNamespaceObject = null;
}
-
- private boolean isAddressingDisabled(MessageContext msgContext) throws AxisFault{
- // it should be able to disable addressing by some one.
- Object property = msgContext.getProperty(DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
- if (property == null && msgContext.getOperationContext() != null) {
- // check in the IN message context, if available
- MessageContext inMsgCtxt = msgContext.getOperationContext().getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
- if (inMsgCtxt != null) {
- property = inMsgCtxt.getProperty(DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
- }
- }
- if (property != null && JavaUtils.isTrueExplicitly(property)) {
- if(log.isDebugEnabled()){
- log.debug("Addressing is disabled .....");
- }
- return true;
- }
-
- return false;
- }
-
- private String getAddressingNamespaceInUse(MessageContext msgContext) throws AxisFault{
- String namespace = addressingNamespace;
- Object addressingVersionFromCurrentMsgCtxt = msgContext.getProperty(WS_ADDRESSING_VERSION);
- if (addressingVersionFromCurrentMsgCtxt != null) {
- // since we support only two addressing versions I can avoid multiple ifs here.
- // see that if message context property holds something other than Final.WSA_NAMESPACE
- // we always defaults to Submission.WSA_NAMESPACE. Hope this is fine.
- namespace = Final.WSA_NAMESPACE.equals(addressingVersionFromCurrentMsgCtxt)
- ? Final.WSA_NAMESPACE : Submission.WSA_NAMESPACE;
- } else if (msgContext.getOperationContext() != null)
- { // check for a IN message context, else default to WSA Final
- MessageContext inMessageContext = msgContext.getOperationContext()
- .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
- if (inMessageContext != null) {
- namespace =
- (String) inMessageContext.getProperty(
- WS_ADDRESSING_VERSION);
- }
- }
-
- if (namespace == null || "".equals(namespace)) {
- namespace = Final.WSA_NAMESPACE;
- }
-
- if(log.isDebugEnabled()){
- log.debug("getAddressingNamespaceInUse: Addressing namespace is use is: "+namespace);
- }
-
- return namespace;
- }
private void processWSAAction(Options messageContextOptions, SOAPEnvelope envelope,
MessageContext msgCtxt, OMNamespace addressingNamespaceObject, boolean replaceHeaders) {
@@ -177,7 +158,7 @@
action = msgCtxt.getAxisOperation().getOutputAction();
}
}
- if (action != null && !shouldAddNewHeader(WSA_ACTION, envelope,
+ if (action != null && !isAddressingHeaderAlreadyAvailable(WSA_ACTION, envelope,
addressingNamespaceObject, replaceHeaders)) {
processStringInfo(action, WSA_ACTION, envelope, addressingNamespaceObject);
}
@@ -190,24 +171,18 @@
// Add detail as a wsa:FaultDetail header
SOAPHeaderBlock faultDetail = envelope.getHeader().addHeaderBlock(Final.FAULT_HEADER_DETAIL, addressingNamespaceObject);
faultDetail.addChild(detailElement);
- if(log.isTraceEnabled()){
- log.trace("processFaultsInfoIfPresent: isSOAP11()=true Added FaultDetail header element.");
- }
}else{
// Add detail to the Fault in the SOAP Body
SOAPFault fault = envelope.getBody().getFault();
if (fault != null && fault.getDetail() != null) {
fault.getDetail().addDetailEntry(detailElement);
- if(log.isTraceEnabled()){
- log.trace("processFaultsInfoIfPresent: isSOAP11()=false Added Detail to fault in body.");
- }
}
}
}
}
private void processRelatesTo(SOAPEnvelope envelope, Options messageContextOptions, OMNamespace addressingNamespaceObject, String replyRelationshipType, boolean replaceHeaders) {
- if (!shouldAddNewHeader(WSA_RELATES_TO, envelope, addressingNamespaceObject,replaceHeaders))
+ if (!isAddressingHeaderAlreadyAvailable(WSA_RELATES_TO, envelope, addressingNamespaceObject,replaceHeaders))
{
RelatesTo[] relatesTo = messageContextOptions.getRelationships();
@@ -253,50 +228,42 @@
}
private void processReplyTo(SOAPEnvelope envelope, Options messageContextOptions, MessageContext msgContext, OMNamespace addressingNamespaceObject, String namespace, String anonymousURI, boolean replaceHeaders) {
- if (!shouldAddNewHeader(WSA_REPLY_TO, envelope, addressingNamespaceObject, replaceHeaders))
+ EndpointReference epr = null;
+ if (!isAddressingHeaderAlreadyAvailable(WSA_REPLY_TO, envelope, addressingNamespaceObject, replaceHeaders))
{
- // If SOAP Session support is enabled, use if appropriate
- EndpointReference epr = processReplyToForSOAPSessionScopeSupport(msgContext);
- if(epr == null){
- epr = new EndpointReference(anonymousURI);
- }
+ epr = messageContextOptions.getReplyTo();
+ if(msgContext.isServerSide()){
+ if (epr == null) {//optional
+ ServiceContext serviceContext = msgContext.getServiceContext();
+ if (serviceContext != null &&
+ serviceContext.getMyEPR() != null) {
+ epr = serviceContext.getMyEPR();
+ } else {
+ // setting anonymous URI. Defaulting to Final.
+ epr = new EndpointReference(anonymousURI);
+ }
+ } else if ("".equals(epr.getAddress())) {
+ ServiceContext serviceContext = msgContext.getServiceContext();
+ if (serviceContext != null &&
+ serviceContext.getMyEPR() != null) {
+ epr.setAddress(serviceContext.getMyEPR().getAddress());
+ } else {
+ // setting anonymous URI. Defaulting to Final.
+ epr.setAddress(anonymousURI);
+ }
+ }
+ }else{
+ if(epr == null){
+ epr = new EndpointReference(anonymousURI);
+ }
+ }
addToSOAPHeader(epr, AddressingConstants.WSA_REPLY_TO, envelope, addressingNamespaceObject, namespace, replaceHeaders);
}
}
-
- /**
- * Process the ReplyTo EPR from the messageContext and if one does not exist and this is an
- * outbound response message from a service with SOAP Session Scope, set it appropriately
- * including the relevant reference parameter. Brief function description of this at
- * http://www.developer.com/services/article.php/3620661
- *
- * @param msgContext
- * @return an EndpointReference representing the ws-addressing [reply endpoint]
- */
- private EndpointReference processReplyToForSOAPSessionScopeSupport(MessageContext msgContext) {
- EndpointReference epr = msgContext.getReplyTo();
- AxisService axisService = msgContext.getAxisService();
- if(log.isTraceEnabled()){
- log.trace("processReplyToForSOAPSessionScopeSupport: ReplyTo: "+epr+" AxisService: "+axisService.getName());
- }
- if (epr == null || "".equals(epr.getAddress())) {// If ReplyTo EPR not set
- // If is response message and SOAP Session scope is enabled for this message
- if (msgContext.isServerSide() && (axisService != null)
- && Constants.SCOPE_SOAP_SESSION.equals(axisService.getScope())) {
- if(log.isTraceEnabled()){
- log.trace("processReplyToForSOAPSessionScopeSupport: isServerSide=true and SOAP Session Scope enabled");
- }
- if (msgContext.getServiceContext() != null) {
- epr = msgContext.getServiceContext().getMyEPR();
- }
- }
- }
- return epr;
- }
private void processToEPR(Options messageContextOptions, SOAPEnvelope envelope, OMNamespace addressingNamespaceObject, String namespace, boolean replaceHeaders) {
EndpointReference epr = messageContextOptions.getTo();
- if (epr != null && !shouldAddNewHeader(WSA_TO, envelope, addressingNamespaceObject, replaceHeaders))
+ if (epr != null && !isAddressingHeaderAlreadyAvailable(WSA_TO, envelope, addressingNamespaceObject, replaceHeaders))
{
Map referenceParameters = null;
String address = "";
@@ -328,7 +295,7 @@
protected void addToSOAPHeader(EndpointReference epr,
String type,
SOAPEnvelope envelope, OMNamespace addressingNamespaceObject, String namespace, boolean replaceHeaders) {
- if (epr == null || shouldAddNewHeader(type, envelope, addressingNamespaceObject,replaceHeaders))
+ if (epr == null || isAddressingHeaderAlreadyAvailable(type, envelope, addressingNamespaceObject,replaceHeaders))
{
return;
}
@@ -393,15 +360,14 @@
* @param referenceInformation
*/
private void processReferenceInformation(Map referenceInformation, OMElement parent, String namespace) {
+
+ boolean processingWSAFinal = Final.WSA_NAMESPACE.equals(namespace);
if (referenceInformation != null && parent != null) {
Iterator iterator = referenceInformation.keySet().iterator();
while (iterator.hasNext()) {
QName key = (QName) iterator.next();
OMElement omElement = (OMElement) referenceInformation.get(key);
parent.addChild(ElementHelper.importOMElement(omElement, parent.getOMFactory()));
- if(log.isTraceEnabled()){
- log.trace("processReferenceInformation: Added ReferenceParameter: "+omElement);
- }
}
}
}
@@ -441,18 +407,14 @@
* @param replaceHeaders - determines whether we replace the existing headers or not, if they present
* @return false - if one can add new headers, true - if one should not touch them.
*/
- private boolean shouldAddNewHeader(String name, SOAPEnvelope envelope, OMNamespace addressingNamespaceObject, boolean replaceHeaders) {
+ private boolean isAddressingHeaderAlreadyAvailable(String name, SOAPEnvelope envelope, OMNamespace addressingNamespaceObject, boolean replaceHeaders) {
OMElement addressingHeader = envelope.getHeader().getFirstChildWithName(new QName(addressingNamespaceObject.getNamespaceURI(), name, addressingNamespaceObject.getPrefix()));
- if(log.isTraceEnabled()){
- log.trace("isAddressingHeaderAlreadyAvailable: replaceHeaders="+replaceHeaders+" addressingHeader="+addressingHeader);
- }
-
if (addressingHeader != null && replaceHeaders) {
addressingHeader.detach();
return false;
}
-
+
return addressingHeader != null;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org