Author: richard.opalka(a)jboss.com
Date: 2010-04-13 06:23:10 -0400 (Tue, 13 Apr 2010)
New Revision: 11978
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/addressing/jaxws/WSAddressingServerHandler.java
Log:
[JBWS-2991] final optimization of Addressing server handler
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/addressing/jaxws/WSAddressingServerHandler.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/addressing/jaxws/WSAddressingServerHandler.java 2010-04-13
10:11:40 UTC (rev 11977)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/extensions/addressing/jaxws/WSAddressingServerHandler.java 2010-04-13
10:23:10 UTC (rev 11978)
@@ -21,17 +21,12 @@
*/
package org.jboss.ws.extensions.addressing.jaxws;
-import org.jboss.logging.Logger;
-import org.jboss.ws.core.CommonMessageContext;
-import org.jboss.ws.core.soap.SOAPFaultImpl;
-import org.jboss.ws.extensions.addressing.AddressingConstantsImpl;
-import org.jboss.ws.extensions.addressing.metadata.AddressingOpMetaExt;
-import org.jboss.ws.metadata.umdm.FaultMetaData;
-import org.jboss.ws.metadata.umdm.OperationMetaData;
-import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
-import org.jboss.wsf.common.addressing.AddressingConstants;
-import org.jboss.wsf.common.handler.GenericSOAPHandler;
-import org.w3c.dom.Element;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
import javax.xml.namespace.QName;
import javax.xml.soap.Detail;
@@ -49,12 +44,16 @@
import javax.xml.ws.soap.AddressingFeature;
import javax.xml.ws.soap.SOAPFaultException;
-import java.net.URISyntaxException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
+import org.jboss.logging.Logger;
+import org.jboss.ws.core.CommonMessageContext;
+import org.jboss.ws.core.soap.SOAPFaultImpl;
+import org.jboss.ws.extensions.addressing.AddressingConstantsImpl;
+import org.jboss.ws.extensions.addressing.metadata.AddressingOpMetaExt;
+import org.jboss.ws.metadata.umdm.FaultMetaData;
+import org.jboss.ws.metadata.umdm.OperationMetaData;
+import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
+import org.jboss.wsf.common.handler.GenericSOAPHandler;
+import org.w3c.dom.Element;
/**
* A server side handler that reads/writes the addressing properties
@@ -67,233 +66,218 @@
@SuppressWarnings("unchecked")
public class WSAddressingServerHandler extends GenericSOAPHandler
{
- // Provide logging
- private static Logger log = Logger.getLogger(WSAddressingServerHandler.class);
+ // Provide logging
+ private static Logger log = Logger.getLogger(WSAddressingServerHandler.class);
- private static AddressingBuilder ADDR_BUILDER;
- private static AddressingConstantsImpl ADDR_CONSTANTS;
- private static Set<QName> HEADERS = new HashSet<QName>();
+ private static AddressingBuilder ADDR_BUILDER;
- static
- {
- ADDR_CONSTANTS = new AddressingConstantsImpl();
- ADDR_BUILDER = AddressingBuilder.getAddressingBuilder();
+ private static AddressingConstantsImpl ADDR_CONSTANTS;
- HEADERS.add( ADDR_CONSTANTS.getActionQName());
- HEADERS.add( ADDR_CONSTANTS.getToQName());
- }
+ private static Set<QName> HEADERS = new HashSet<QName>();
- public Set getHeaders()
- {
- return Collections.unmodifiableSet(HEADERS);
- }
+ static
+ {
+ ADDR_CONSTANTS = new AddressingConstantsImpl();
+ ADDR_BUILDER = AddressingBuilder.getAddressingBuilder();
- protected boolean handleInbound(MessageContext msgContext)
- {
- if(log.isDebugEnabled()) log.debug("handleInbound");
+ HEADERS.add(ADDR_CONSTANTS.getActionQName());
+ HEADERS.add(ADDR_CONSTANTS.getToQName());
+ }
-// if (!this.isAddressingEnabled(msgContext))
-// {
-// try
-// {
-// SOAPFault fault = new SOAPFaultImpl();
-//
fault.setFaultCode(AddressingConstants.Core.Faults.MESSAGEADDRESSINGHEADERREQUIRED_QNAME);
-// fault.setFaultString("A required header representing a Message
Addressing Property is not present");
-// throw new SOAPFaultException(fault);
-// }
-// catch (SOAPException e)
-// {
-// throw new WebServiceException(e);
-// }
-// }
+ public Set getHeaders()
+ {
+ return Collections.unmodifiableSet(HEADERS);
+ }
- SOAPAddressingProperties addrProps =
(SOAPAddressingProperties)ADDR_BUILDER.newAddressingProperties();
- SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
- CommonMessageContext commonMsgContext = (CommonMessageContext)msgContext;
- if (this.isAddressingRequired(msgContext))
- {
- try
- {
- soapMessage.setProperty("isRequired", true);
- }
- catch (Exception e)
- {
- //ignore
- }
-
- }
- addrProps.readHeaders(soapMessage);
- if (addrProps.getAction() != null)
- {
- msgContext.put(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND,
addrProps);
- msgContext.setScope(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND,
Scope.APPLICATION);
- msgContext.put(MessageContext.REFERENCE_PARAMETERS,
convertToElementList(addrProps.getReferenceParameters().getElements()));
- msgContext.setScope(MessageContext.REFERENCE_PARAMETERS, Scope.APPLICATION);
+ protected boolean handleInbound(MessageContext msgContext)
+ {
+ if (log.isDebugEnabled())
+ log.debug("handleInbound");
- //check if soap action matches wsa action
- String[] soapActions =
commonMsgContext.getMessageAbstraction().getMimeHeaders().getHeader("SOAPAction");
- if (soapActions != null && soapActions.length > 0)
- {
- String soapAction = soapActions[0];
- if (!soapAction.equals("\"\"") &&
addrProps.getAction() != null)
- {
- String wsaAction = addrProps.getAction().getURI().toString();
- // R1109 The value of the SOAPAction HTTP header field in a HTTP request
MESSAGE MUST be a quoted string.
- if (!soapAction.equals(wsaAction) &&
!soapAction.equals("\"" + wsaAction + "\""))
- {
- try
- {
- SOAPFault fault = new SOAPFaultImpl();
- fault.setFaultCode(new QName(ADDR_CONSTANTS.getNamespaceURI(),
"ActionMismatch"));
- fault.setFaultString("Mismatch between soap action:" +
soapAction + " and wsa action:\""
- + addrProps.getAction().getURI() + "\"");
- Detail detail = fault.addDetail();
- detail.addDetailEntry(new QName(ADDR_CONSTANTS.getNamespaceURI(),
"ProblemAction"));
- throw new SOAPFaultException(fault);
- }
- catch (SOAPException e)
- {
- throw new WebServiceException(e);
- }
- }
- }
- }
- }
- return true;
- }
-
- private static List<Element> convertToElementList(List<Object> objects)
- {
- if (objects == null) return null;
- List<Element> elements = new LinkedList<Element>();
- for (Object o : objects)
- {
- if (o instanceof Element)
- {
- elements.add((Element)o);
- }
- }
- return elements;
- }
+ SOAPAddressingProperties addrProps = (SOAPAddressingProperties)
ADDR_BUILDER.newAddressingProperties();
+ SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
+ CommonMessageContext commonMsgContext = (CommonMessageContext) msgContext;
+ if (this.isAddressingRequired(msgContext))
+ {
+ try
+ {
+ soapMessage.setProperty("isRequired", true);
+ }
+ catch (Exception e)
+ {
+ //ignore
+ }
- protected boolean handleOutbound(MessageContext msgContext)
- {
- if(log.isDebugEnabled()) log.debug("handleOutbound");
- final boolean isAddressingEnabled = this.isAddressingEnabled(msgContext);
- final boolean isAddressingRequest = this.isAddressingRequest(msgContext);
-
- if (isAddressingEnabled && isAddressingRequest)
- {
- handleResponseOrFault(msgContext, false);
- }
- return true;
- }
+ }
+ addrProps.readHeaders(soapMessage);
+ if (addrProps.getAction() != null)
+ {
+ msgContext.put(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND,
addrProps);
+ msgContext.setScope(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND,
Scope.APPLICATION);
+ msgContext.put(MessageContext.REFERENCE_PARAMETERS,
convertToElementList(addrProps.getReferenceParameters()
+ .getElements()));
+ msgContext.setScope(MessageContext.REFERENCE_PARAMETERS, Scope.APPLICATION);
- /**
- * Get a SOAPAddressingProperties object from the message context
- * and write the adressing headers
- */
- public boolean handleFault(MessageContext msgContext)
- {
- if(log.isDebugEnabled()) log.debug("handleFault");
- final boolean isAddressingEnabled = this.isAddressingEnabled(msgContext);
- final boolean isAddressingRequest = this.isAddressingRequest(msgContext);
+ //check if soap action matches wsa action
+ String[] soapActions =
commonMsgContext.getMessageAbstraction().getMimeHeaders().getHeader("SOAPAction");
+ if (soapActions != null && soapActions.length > 0)
+ {
+ String soapAction = soapActions[0];
+ if (!soapAction.equals("\"\"") &&
addrProps.getAction() != null)
+ {
+ String wsaAction = addrProps.getAction().getURI().toString();
+ // R1109 The value of the SOAPAction HTTP header field in a HTTP request
MESSAGE MUST be a quoted string.
+ if (!soapAction.equals(wsaAction) &&
!soapAction.equals("\"" + wsaAction + "\""))
+ {
+ try
+ {
+ SOAPFault fault = new SOAPFaultImpl();
+ fault.setFaultCode(new QName(ADDR_CONSTANTS.getNamespaceURI(),
"ActionMismatch"));
+ fault.setFaultString("Mismatch between soap action:" +
soapAction + " and wsa action:\""
+ + addrProps.getAction().getURI() + "\"");
+ Detail detail = fault.addDetail();
+ detail.addDetailEntry(new QName(ADDR_CONSTANTS.getNamespaceURI(),
"ProblemAction"));
+ throw new SOAPFaultException(fault);
+ }
+ catch (SOAPException e)
+ {
+ throw new WebServiceException(e);
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
- if (isAddressingEnabled && isAddressingRequest)
- {
- handleResponseOrFault(msgContext, true);
- }
-
- return true;
- }
+ private static List<Element> convertToElementList(List<Object> objects)
+ {
+ if (objects == null)
+ return null;
+ List<Element> elements = new LinkedList<Element>();
+ for (Object o : objects)
+ {
+ if (o instanceof Element)
+ {
+ elements.add((Element) o);
+ }
+ }
+ return elements;
+ }
- private void handleResponseOrFault(MessageContext msgContext, boolean isFault)
- {
- SOAPAddressingBuilder builder =
(SOAPAddressingBuilder)SOAPAddressingBuilder.getAddressingBuilder();
- SOAPMessage soapMessage = ((SOAPMessageContext)msgContext).getMessage();
+ protected boolean handleOutbound(MessageContext msgContext)
+ {
+ if (log.isDebugEnabled())
+ log.debug("handleOutbound");
- SOAPAddressingProperties inProps =
(SOAPAddressingProperties)msgContext.get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND);
- SOAPAddressingProperties outProps =
(SOAPAddressingProperties)msgContext.get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND);
+ if (this.isAddressingRequest(msgContext))
+ {
+ handleResponseOrFault(msgContext, false);
+ }
+ return true;
+ }
- if (outProps == null)
- {
- // create new response properties
- outProps = (SOAPAddressingProperties)builder.newAddressingProperties();
- msgContext.put(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND, outProps);
- msgContext.setScope(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND,
Scope.APPLICATION);
- }
+ /**
+ * Get a SOAPAddressingProperties object from the message context
+ * and write the adressing headers
+ */
+ public boolean handleFault(MessageContext msgContext)
+ {
+ if (log.isDebugEnabled())
+ log.debug("handleFault");
+ if (this.isAddressingRequest(msgContext))
+ {
+ handleResponseOrFault(msgContext, true);
+ }
- if (inProps != null) outProps.initializeAsReply(inProps, isFault);
+ return true;
+ }
- try
- {
- // supply the response action
- CommonMessageContext commonCtx = (CommonMessageContext)msgContext;
- OperationMetaData operationMD = commonCtx.getOperationMetaData();
-
- AddressingOpMetaExt addressingMD =
(AddressingOpMetaExt)operationMD.getExtension(ADDR_CONSTANTS.getNamespaceURI());
-
- if (addressingMD == null)
- throw new IllegalStateException("Addressing meta data not
available");
+ private void handleResponseOrFault(MessageContext msgContext, boolean isFault)
+ {
+ SOAPAddressingBuilder builder = (SOAPAddressingBuilder)
SOAPAddressingBuilder.getAddressingBuilder();
+ SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
- if (!isFault && !operationMD.isOneWay())
- {
- outProps.setAction(ADDR_BUILDER.newURI(addressingMD.getOutboundAction()));
- }
- else if (isFault)
- {
- Throwable exception = commonCtx.getCurrentException();
- String faultAction = getFaultAction(operationMD, addressingMD, exception);
+ SOAPAddressingProperties inProps = (SOAPAddressingProperties) msgContext
+ .get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND);
+ SOAPAddressingProperties outProps = (SOAPAddressingProperties) msgContext
+ .get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND);
- outProps.setAction(ADDR_BUILDER.newURI(faultAction));
- }
+ if (outProps == null)
+ {
+ // create new response properties
+ outProps = (SOAPAddressingProperties) builder.newAddressingProperties();
+ msgContext.put(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND,
outProps);
+ msgContext.setScope(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_OUTBOUND,
Scope.APPLICATION);
+ }
- }
- catch (URISyntaxException e)
- {
- log.error("Error setting response action", e);
- }
+ if (inProps != null)
+ outProps.initializeAsReply(inProps, isFault);
- outProps.writeHeaders(soapMessage);
- }
+ try
+ {
+ // supply the response action
+ CommonMessageContext commonCtx = (CommonMessageContext) msgContext;
+ OperationMetaData operationMD = commonCtx.getOperationMetaData();
- private String getFaultAction(final OperationMetaData operationMD, final
AddressingOpMetaExt addressingMD, final Throwable exception)
- {
- final FaultMetaData faultMD = operationMD.getFaultMetaData(exception.getClass());
-
- if (faultMD != null)
- {
- final String beanName = faultMD.getFaultBeanName();
- return addressingMD.getFaultAction(beanName);
- }
+ AddressingOpMetaExt addressingMD = (AddressingOpMetaExt)
operationMD.getExtension(ADDR_CONSTANTS
+ .getNamespaceURI());
- return ADDR_CONSTANTS.getDefaultFaultAction();
- }
+ if (addressingMD == null)
+ throw new IllegalStateException("Addressing meta data not
available");
- private boolean isAddressingRequired(final MessageContext msgContext)
- {
- final AddressingFeature addrFeature = this.getAddressingFeature(msgContext);
-
- return addrFeature != null && addrFeature.isEnabled() &&
addrFeature.isRequired();
- }
-
- private boolean isAddressingEnabled(final MessageContext msgContext)
- {
- final AddressingFeature addrFeature = this.getAddressingFeature(msgContext);
-
- return addrFeature != null && addrFeature.isEnabled();
- }
-
- private AddressingFeature getAddressingFeature(final MessageContext msgContext)
- {
- final CommonMessageContext commonMsgContext = (CommonMessageContext)msgContext;
- final ServerEndpointMetaData serverMetaData =
(ServerEndpointMetaData)commonMsgContext.getEndpointMetaData();
-
- return serverMetaData.getFeature(AddressingFeature.class);
- }
-
- private boolean isAddressingRequest(final MessageContext msgContext)
- {
- return msgContext.get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND) != null;
- }
+ if (!isFault && !operationMD.isOneWay())
+ {
+ outProps.setAction(ADDR_BUILDER.newURI(addressingMD.getOutboundAction()));
+ }
+ else if (isFault)
+ {
+ Throwable exception = commonCtx.getCurrentException();
+ String faultAction = getFaultAction(operationMD, addressingMD, exception);
+
+ outProps.setAction(ADDR_BUILDER.newURI(faultAction));
+ }
+
+ }
+ catch (URISyntaxException e)
+ {
+ log.error("Error setting response action", e);
+ }
+
+ outProps.writeHeaders(soapMessage);
+ }
+
+ private String getFaultAction(final OperationMetaData operationMD, final
AddressingOpMetaExt addressingMD,
+ final Throwable exception)
+ {
+ final FaultMetaData faultMD = operationMD.getFaultMetaData(exception.getClass());
+
+ if (faultMD != null)
+ {
+ final String beanName = faultMD.getFaultBeanName();
+ return addressingMD.getFaultAction(beanName);
+ }
+
+ return ADDR_CONSTANTS.getDefaultFaultAction();
+ }
+
+ private boolean isAddressingRequired(final MessageContext msgContext)
+ {
+ final AddressingFeature addrFeature = this.getAddressingFeature(msgContext);
+
+ return addrFeature != null && addrFeature.isEnabled() &&
addrFeature.isRequired();
+ }
+
+ private AddressingFeature getAddressingFeature(final MessageContext msgContext)
+ {
+ final CommonMessageContext commonMsgContext = (CommonMessageContext) msgContext;
+ final ServerEndpointMetaData serverMetaData = (ServerEndpointMetaData)
commonMsgContext.getEndpointMetaData();
+
+ return serverMetaData.getFeature(AddressingFeature.class);
+ }
+
+ private boolean isAddressingRequest(final MessageContext msgContext)
+ {
+ return msgContext.get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND) !=
null;
+ }
}
Show replies by date