[jboss-svn-commits] JBL Code SVN: r34402 - in labs/jbossesb/trunk/product: samples/quickstarts/security_saml/src/org/jboss/soa/esb/samples/quickstart/securitysaml/webservice and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jul 30 03:55:43 EDT 2010
Author: mageshbk at jboss.com
Date: 2010-07-30 03:55:41 -0400 (Fri, 30 Jul 2010)
New Revision: 34402
Added:
labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractSOAPProcessor.java
labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/CXFSOAPProcessor.java
labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/NativeSOAPProcessor.java
Modified:
labs/jbossesb/trunk/product/samples/quickstarts/security_cert/src/org/jboss/soa/esb/samples/quickstart/securitycert/webservice/GoodbyeWorldWS.java
labs/jbossesb/trunk/product/samples/quickstarts/security_saml/src/org/jboss/soa/esb/samples/quickstart/securitysaml/webservice/GoodbyeWorldWS.java
labs/jbossesb/trunk/product/samples/quickstarts/webservice_producer/src/org/jboss/soa/esb/samples/quickstart/webserviceproducer/webservice/GoodbyeWorldWS.java
labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSWebserviceContractPublisher.java
labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java
labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java
labs/jbossesb/trunk/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/JBossWSAdapterContractPublisherUnitTest.java
Log:
[JBESB-3376] - Added support in SOAPProcessor to invoke CXF endpoints using Dispatch API.
Modified: labs/jbossesb/trunk/product/samples/quickstarts/security_cert/src/org/jboss/soa/esb/samples/quickstart/securitycert/webservice/GoodbyeWorldWS.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/security_cert/src/org/jboss/soa/esb/samples/quickstart/securitycert/webservice/GoodbyeWorldWS.java 2010-07-30 07:46:02 UTC (rev 34401)
+++ labs/jbossesb/trunk/product/samples/quickstarts/security_cert/src/org/jboss/soa/esb/samples/quickstart/securitycert/webservice/GoodbyeWorldWS.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -9,7 +9,6 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.Body;
import org.jboss.soa.esb.actions.ActionUtils;
-import org.jboss.soa.esb.actions.soap.SOAPProcessor;
/**
* @author
@@ -19,23 +18,12 @@
@WebMethod
public String sayGoodbye(@WebParam(name="message") String message) {
-
- Message esbMessage = SOAPProcessor.getMessage();
- if(esbMessage != null) {
- System.out.println("**** SOAPRequest perhaps mediated by ESB:\n" + esbMessage.getBody().get());
- // System.out.println("\n" + esbMessage.toString() + "\n");
- }
System.out.println("Web Service Parameter - message=" + message);
return "... Ah Goodbye then!!!! - " + message;
}
@WebMethod
public String sayAdios(String message) {
- Message esbMessage = SOAPProcessor.getMessage();
- if(esbMessage != null) {
- System.out.println("**** SOAPRequest perhaps mediated by ESB:\n" + esbMessage.getBody().get());
- // System.out.println("\n" + esbMessage.toString() + "\n");
- }
System.out.println("Web Service Parameter - message=" + message);
return "... Adios Amigo!!!! - " + message;
}
@@ -43,11 +31,6 @@
@WebMethod
@Oneway
public void sayGoodbyeWithoutResponse(@WebParam(name="message") String message) {
-
- Message esbMessage = SOAPProcessor.getMessage();
- if(esbMessage != null) {
- System.out.println("**** SOAPRequest perhaps mediated by ESB:\n" + esbMessage.getBody().get());
- }
System.out.println("Web Service Parameter - message=" + message);
}
Modified: labs/jbossesb/trunk/product/samples/quickstarts/security_saml/src/org/jboss/soa/esb/samples/quickstart/securitysaml/webservice/GoodbyeWorldWS.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/security_saml/src/org/jboss/soa/esb/samples/quickstart/securitysaml/webservice/GoodbyeWorldWS.java 2010-07-30 07:46:02 UTC (rev 34401)
+++ labs/jbossesb/trunk/product/samples/quickstarts/security_saml/src/org/jboss/soa/esb/samples/quickstart/securitysaml/webservice/GoodbyeWorldWS.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -10,7 +10,6 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.Body;
import org.jboss.soa.esb.actions.ActionUtils;
-import org.jboss.soa.esb.actions.soap.SOAPProcessor;
@HandlerChain(file="handlerchain.xml")
@WebService(name = "GoodbyeWorldWS", targetNamespace="http://security_saml/goodbyeworld")
@@ -18,18 +17,12 @@
@WebMethod
public String sayGoodbye(@WebParam(name="message") String message) {
- Message esbMessage = SOAPProcessor.getMessage();
System.out.println("Succesfully invoked WS!");
- System.out.println("SOAPRequest perhaps mediated by ESB:\n" + esbMessage.getBody().get());
return "... Ah Goodbye then!!!! - " + message;
}
@WebMethod
public String sayAdios(String message) {
- Message esbMessage = SOAPProcessor.getMessage();
- if(esbMessage != null) {
- System.out.println("**** SOAPRequest perhaps mediated by ESB:\n" + esbMessage.getBody().get());
- }
System.out.println("Web Service Parameter - message=" + message);
return "... Adios Amigo!!!! - " + message;
}
@@ -37,11 +30,6 @@
@WebMethod
@Oneway
public void sayGoodbyeWithoutResponse(@WebParam(name="message") String message) {
-
- Message esbMessage = SOAPProcessor.getMessage();
- if(esbMessage != null) {
- System.out.println("**** SOAPRequest perhaps mediated by ESB:\n" + esbMessage.getBody().get());
- }
System.out.println("Web Service Parameter - message=" + message);
}
Modified: labs/jbossesb/trunk/product/samples/quickstarts/webservice_producer/src/org/jboss/soa/esb/samples/quickstart/webserviceproducer/webservice/GoodbyeWorldWS.java
===================================================================
--- labs/jbossesb/trunk/product/samples/quickstarts/webservice_producer/src/org/jboss/soa/esb/samples/quickstart/webserviceproducer/webservice/GoodbyeWorldWS.java 2010-07-30 07:46:02 UTC (rev 34401)
+++ labs/jbossesb/trunk/product/samples/quickstarts/webservice_producer/src/org/jboss/soa/esb/samples/quickstart/webserviceproducer/webservice/GoodbyeWorldWS.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -9,7 +9,6 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.Body;
import org.jboss.soa.esb.actions.ActionUtils;
-import org.jboss.soa.esb.actions.soap.SOAPProcessor;
/**
* @author
@@ -20,23 +19,12 @@
@WebMethod
public String sayGoodbye(@WebParam(name="message") String message) {
-
- Message esbMessage = SOAPProcessor.getMessage();
- if(esbMessage != null) {
- System.out.println("**** SOAPRequest perhaps mediated by ESB:\n" + esbMessage.getBody().get());
- // System.out.println("\n" + esbMessage.toString() + "\n");
- }
System.out.println("Web Service Parameter - message=" + message);
return "... Ah Goodbye then!!!! - " + message;
}
@WebMethod
public String sayAdios(String message) {
- Message esbMessage = SOAPProcessor.getMessage();
- if(esbMessage != null) {
- System.out.println("**** SOAPRequest perhaps mediated by ESB:\n" + esbMessage.getBody().get());
- // System.out.println("\n" + esbMessage.toString() + "\n");
- }
System.out.println("Web Service Parameter - message=" + message);
return "... Adios Amigo!!!! - " + message;
}
@@ -44,11 +32,6 @@
@WebMethod
@Oneway
public void sayGoodbyeWithoutResponse(@WebParam(name="message") String message) {
-
- Message esbMessage = SOAPProcessor.getMessage();
- if(esbMessage != null) {
- System.out.println("**** SOAPRequest perhaps mediated by ESB:\n" + esbMessage.getBody().get());
- }
System.out.println("Web Service Parameter - message=" + message);
}
Added: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractSOAPProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractSOAPProcessor.java (rev 0)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/AbstractSOAPProcessor.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap;
+
+import java.io.UnsupportedEncodingException;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.MessagePayloadProxy;
+import org.jboss.soa.esb.message.ResponseStatus;
+import org.jboss.soa.esb.message.body.content.BytesBody;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @author <a href="mageshbk at jboss.com">Magesh Kumar B</a>
+ */
+public abstract class AbstractSOAPProcessor {
+
+ protected String jbossws_endpoint;
+ protected MessagePayloadProxy payloadProxy;
+ protected boolean httpResponseStatusEnabled;
+
+ /**
+ * Public constructor.
+ * @param config Configuration.
+ * @throws ConfigurationException "jbossws-endpoint" not specified.
+ */
+ public AbstractSOAPProcessor(ConfigTree config) throws ConfigurationException {
+ jbossws_endpoint = config.getRequiredAttribute(WebServiceUtils.JBOSSWS_ENDPOINT);
+ payloadProxy = new MessagePayloadProxy(config,
+ new String[] {BytesBody.BYTES_LOCATION, ActionUtils.POST_ACTION_DATA},
+ new String[] {ActionUtils.POST_ACTION_DATA});
+ httpResponseStatusEnabled = ResponseStatus.isHttpEnabled(config);
+ }
+
+ public abstract Message process(Message message) throws ActionProcessingException;
+
+ protected byte[] getSOAPMessagePayload(Message message) throws ActionProcessingException {
+ byte[] soapMessage;
+ Object messagePayload;
+
+ try {
+ messagePayload = payloadProxy.getPayload(message);
+ } catch (MessageDeliverException e) {
+ throw new ActionProcessingException(e);
+ }
+
+ if(messagePayload instanceof byte[]) {
+ soapMessage = (byte[])messagePayload;
+ } else if(messagePayload instanceof String) {
+ try {
+ soapMessage = ((String)messagePayload).getBytes("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new ActionProcessingException("Unable to decode SOAP message payload.", e);
+ }
+ } else {
+ throw new ActionProcessingException("Unable to decode SOAP message payload. Must be either a byte[] or java.lang.String.");
+ }
+ return soapMessage;
+ }
+}
Added: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/CXFSOAPProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/CXFSOAPProcessor.java (rev 0)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/CXFSOAPProcessor.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -0,0 +1,236 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+import java.util.Iterator;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Operation;
+import javax.wsdl.OperationType;
+import javax.wsdl.Port;
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.soap.AddressingFeature;
+
+import org.jboss.internal.soa.esb.webservice.addressing.AddressingConstants;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.Properties;
+import org.jboss.soa.esb.message.ResponseHeader;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.xml.sax.InputSource;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * JBossWS-CXF SOAP Processor.
+ *
+ * @author <a href="mageshbk at jboss.com">Magesh Kumar B</a>
+ */
+public class CXFSOAPProcessor extends AbstractSOAPProcessor {
+
+ Dispatch<SOAPMessage> dispatcher;
+ Port port;
+
+ public CXFSOAPProcessor(ConfigTree config) throws ConfigurationException {
+ super(config);
+ }
+
+ /**
+ * Process the SOAP message.
+ * <p/>
+ * Invokes the JBossWS-CXF endpoint over HTTP and writes the SOAP response back into the message payload.
+ * @param message The ESB Aware (normalized) SOAP request message.
+ * @return The SOAP response message.
+ * @throws ActionProcessingException
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ byte[] byteMessage;
+
+ if (dispatcher == null) {
+ Endpoint endpoint = WebServiceUtils.getServiceEndpoint(jbossws_endpoint);
+ if(endpoint == null) {
+ throw new ActionProcessingException("Unknown Service Endpoint '" + jbossws_endpoint + "'.");
+ }
+ try
+ {
+ String wsdlLocation = WebServiceUtils.getWsdlLocation(endpoint);
+ URL wsdlUrl = new URL(wsdlLocation);
+ Definition definition = new JBossWSDLReader().readWSDL(wsdlLocation);
+ javax.wsdl.Service wsdlService = (javax.wsdl.Service)definition.getServices().values().iterator().next();
+ QName serviceName = wsdlService.getQName();
+ port = (Port)wsdlService.getPorts().values().iterator().next();
+ QName portName = new QName(definition.getTargetNamespace(), port.getName());
+
+ Service service = Service.create(wsdlUrl, serviceName);
+ // CXF dispatcher will create duplicate WS-Addressing headers if not set to false
+ // As we are handling the SOAP MESSAGE from ESB clients directly we do not need to create it here
+ dispatcher = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE, new AddressingFeature(false, false));
+ }
+ catch (Exception e)
+ {
+ throw new ActionProcessingException(e);
+ }
+ }
+
+ byteMessage = getSOAPMessagePayload(message);
+ try {
+ MimeHeaders headers = new MimeHeaders();
+ final Properties properties = message.getProperties() ;
+ final String[] names = properties.getNames() ;
+ for(final String name: names)
+ {
+ final Object value = properties.getProperty(name) ;
+ if (value != null && value instanceof String)
+ {
+ if ("content-type".equals(name) && "application/octet-stream".equals(value))
+ continue;
+ else
+ headers.addHeader(name, (String)value);
+ }
+ }
+
+ SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(headers, new ByteArrayInputStream(byteMessage));
+ final Properties responseProperties = message.getProperties();
+
+ if (isMessageOneWay(soapMessage)) {
+ dispatcher.invokeOneWay(soapMessage);
+ //return empty response
+ responseProperties.setProperty("Content-Type", "text/xml");
+ payloadProxy.setPayload(message, "");
+ }
+ else {
+ SOAPMessage response = dispatcher.invoke(soapMessage);
+
+ final byte[] responseData = getSoapMessageBytes(response);
+ final String[] contentTypeHeader = response.getMimeHeaders().getHeader("Content-Type");
+ String contentType = null;
+ if (contentTypeHeader != null && contentTypeHeader.length > 0) {
+ contentType = response.getMimeHeaders().getHeader("Content-Type")[0];
+ }
+
+ if(contentType != null) {
+ responseProperties.setProperty("Content-Type", new ResponseHeader("Content-Type", contentType));
+ } else {
+ responseProperties.setProperty("Content-Type", new ResponseHeader("Content-Type", "text/xml"));
+ }
+
+ if ((contentType != null) && contentType.startsWith("multipart/")) {
+ payloadProxy.setPayload(message, responseData) ;
+ } else if (contentType != null) {
+ String charset = null;
+ if (contentType.indexOf("charset=") > 0) {
+ charset = contentType.substring(contentType.indexOf("charset=") + 8);
+ }
+ if (charset == null) {
+ payloadProxy.setPayload(message, new String(responseData));
+ } else {
+ payloadProxy.setPayload(message, new String(responseData, charset));
+ }
+ } else {
+ payloadProxy.setPayload(message, new String(responseData));
+ }
+ }
+ } catch (Exception ex) {
+ throw new ActionProcessingException("Cannot process SOAP request", ex);
+ }
+
+ return message;
+ }
+
+ /**
+ * Convert the SOAPMessage to bytes.
+ *
+ * @param soapMessage The SOAP message.
+ * @return bytes.
+ */
+ protected static byte[] getSoapMessageBytes(SOAPMessage soapMessage) throws ActionProcessingException
+ {
+ try
+ {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ soapMessage.writeTo(outputStream);
+ byte[] byteArray = outputStream.toByteArray();
+ return byteArray;
+ }
+ catch (Exception e)
+ {
+ throw new ActionProcessingException("Error in converting SOAPMessage into bytes");
+ }
+ }
+
+ /**
+ * Check if we are invoking a @Oneway annotated method.
+ *
+ * @param soapMessage The SOAP message.
+ * @return True if there is no response to be expected.
+ */
+ private boolean isMessageOneWay(SOAPMessage soapMessage) throws SOAPException
+ {
+ boolean isOneWay = false;
+ // Overloaded methods not supported
+ // Encrypted messages will be treated as request-response as it cannot be decrypted
+ Operation operation = port.getBinding().getPortType().getOperation(getOperationName(soapMessage), null, null);
+ if (operation != null)
+ isOneWay = operation.getStyle().equals(OperationType.ONE_WAY);
+ return isOneWay;
+ }
+
+ /**
+ * Retrives the operation name from the SOAP Envelope.
+ *
+ * @param soapMessage The SOAP message.
+ * @return The operation name.
+ */
+ private static String getOperationName(SOAPMessage soapMessage) throws SOAPException
+ {
+ String operationName = null;
+ SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
+ if (body != null)
+ {
+ Iterator<Node> nodes = body.getChildElements();
+ Node node = null;
+ while (nodes.hasNext())
+ {
+ node = nodes.next();
+ if (node instanceof Element)
+ {
+ operationName = node.getLocalName();
+ }
+ }
+ }
+ return operationName;
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSWebserviceContractPublisher.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSWebserviceContractPublisher.java 2010-07-30 07:46:02 UTC (rev 34401)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/JBossWSWebserviceContractPublisher.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -45,14 +45,14 @@
// Initialise the abstract base class first...
super.setActionConfig(actionConfig);
- endpointName = actionConfig.getProperties().getProperty(SOAPProcessor.JBOSSWS_ENDPOINT);
+ endpointName = actionConfig.getProperties().getProperty(WebServiceUtils.JBOSSWS_ENDPOINT);
if(endpointName == null) {
- throw new ConfigurationException("Property '" + SOAPProcessor.JBOSSWS_ENDPOINT + "' not specified.");
+ throw new ConfigurationException("Property '" + WebServiceUtils.JBOSSWS_ENDPOINT + "' not specified.");
}
}
public String getWsdlAddress() {
- Endpoint endpoint = SOAPProcessor.getServiceEndpoint(endpointName);
+ Endpoint endpoint = WebServiceUtils.getServiceEndpoint(endpointName);
if(endpoint != null) {
return endpoint.getAddress() + "?wsdl";
Added: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/NativeSOAPProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/NativeSOAPProcessor.java (rev 0)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/NativeSOAPProcessor.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions.soap;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorHttpServletRequest;
+import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorHttpServletResponse;
+import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorServletContext;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.Properties;
+import org.jboss.soa.esb.message.ResponseHeader;
+import org.jboss.soa.esb.message.ResponseStatus;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.invocation.RequestHandler;
+
+/**
+ * JBossWS-Native SOAP Processor.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @author <a href="mageshbk at jboss.com">Magesh Kumar B</a>
+ */
+public class NativeSOAPProcessor extends AbstractSOAPProcessor {
+
+ public NativeSOAPProcessor(ConfigTree config) throws ConfigurationException {
+ super(config);
+ }
+
+ /**
+ * Process the SOAP message.
+ * <p/>
+ * Invokes the JBossWS-Native endpoint internally and writes the SOAP response back into the message payload.
+ * @param message The ESB Aware (normalized) SOAP request message.
+ * @return The SOAP response message.
+ * @throws ActionProcessingException
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ Endpoint endpoint = WebServiceUtils.getServiceEndpoint(jbossws_endpoint);
+ byte[] soapMessage;
+
+ if(endpoint == null) {
+ throw new ActionProcessingException("Unknown Service Endpoint '" + jbossws_endpoint + "'.");
+ }
+
+ soapMessage = getSOAPMessagePayload(message);
+ try {
+ SOAPProcessor.setMessage(message);
+
+ RequestHandler requestHandler = endpoint.getRequestHandler();
+
+ final Map<String, List<String>> headers = new HashMap<String, List<String>>() ;
+ final Properties properties = message.getProperties() ;
+ final String[] names = properties.getNames() ;
+ for(final String name: names)
+ {
+ final Object value = properties.getProperty(name) ;
+ if (value != null)
+ {
+ final String normalisedName = name.toLowerCase() ;
+ final List<String> values = headers.get(normalisedName) ;
+ if (values == null)
+ {
+ final List<String> newValues = new ArrayList<String>() ;
+ newValues.add(value.toString()) ;
+ headers.put(normalisedName, newValues) ;
+ }
+ else
+ {
+ values.add(value.toString()) ;
+ }
+ }
+ }
+
+ final String requestContentType = getHeaderValue(headers, "content-type") ;
+ if ("application/octet-stream".equals(requestContentType))
+ {
+ headers.remove("content-type") ;
+ }
+ final String path = getHeaderValue(headers, "path") ;
+ final SOAPProcessorHttpServletRequest servletRequest = new SOAPProcessorHttpServletRequest(path, soapMessage, headers) ;
+ final SOAPProcessorHttpServletResponse servletResponse = new SOAPProcessorHttpServletResponse() ;
+ final SOAPProcessorServletContext servletContext = new SOAPProcessorServletContext() ;
+ requestHandler.handleHttpRequest(endpoint, servletRequest, servletResponse, servletContext) ;
+
+ // This may have been changed, make sure we get the current version.
+ message = SOAPProcessor.getMessage();
+ final Properties responseProperties = message.getProperties() ;
+ final String contentType = servletResponse.getContentType() ;
+ final Map<String, List<String>> responseHeaders = servletResponse.getHeaders() ;
+ // We deal with Content-Type below
+ // HTTP Headers *should* be case-insensitive but not with JBR
+ responseHeaders.remove("content-type") ;
+
+ for(Map.Entry<String, List<String>> header: responseHeaders.entrySet())
+ {
+ // We can only deal with the first value in the list.
+ // JBESB-2511
+ new ResponseHeader(header.getKey(), header.getValue().get(0)).setPropertyNameThis(properties);
+ }
+ // JBESB-2761
+ if (httpResponseStatusEnabled) {
+ ResponseStatus.setHttpProperties(properties, servletResponse.getStatus(), servletResponse.getStatusMessage());
+ }
+
+ final byte[] responseData = servletResponse.getContent() ;
+ if(contentType != null) {
+ responseProperties.setProperty("Content-Type", new ResponseHeader("Content-Type", contentType));
+ } else {
+ responseProperties.setProperty("Content-Type", new ResponseHeader("Content-Type", "text/xml"));
+ }
+
+ if ((contentType != null) && contentType.startsWith("multipart/")) {
+ payloadProxy.setPayload(message, responseData) ;
+ } else {
+ final String charset = servletResponse.getCharset() ;
+ if (charset == null) {
+ payloadProxy.setPayload(message, new String(responseData)) ;
+ } else {
+ payloadProxy.setPayload(message, new String(responseData, charset)) ;
+ }
+ }
+ } catch (Exception ex) {
+ throw new ActionProcessingException("Cannot process SOAP request", ex);
+ } finally {
+ SOAPProcessor.removeMessage();
+ }
+
+ return message;
+ }
+
+ private String getHeaderValue(final Map<String, List<String>> headers,
+ final String header)
+ {
+ final List<String> values = headers.get(header) ;
+ if (values != null)
+ {
+ return values.get(0) ;
+ }
+ return null ;
+ }
+}
Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java 2010-07-30 07:46:02 UTC (rev 34401)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/SOAPProcessor.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -19,37 +19,13 @@
*/
package org.jboss.soa.esb.actions.soap;
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.management.ObjectName;
-
import org.jboss.internal.soa.esb.publish.Publish;
+import org.jboss.internal.soa.esb.util.JBossDeployerUtil;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
import org.jboss.soa.esb.actions.ActionProcessingException;
-import org.jboss.soa.esb.actions.ActionUtils;
-import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorHttpServletRequest;
-import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorHttpServletResponse;
-import org.jboss.soa.esb.actions.soap.adapter.SOAPProcessorServletContext;
import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.message.MessagePayloadProxy;
-import org.jboss.soa.esb.message.Properties;
-import org.jboss.soa.esb.message.ResponseHeader;
-import org.jboss.soa.esb.message.ResponseStatus;
-import org.jboss.soa.esb.message.body.content.BytesBody;
-import org.jboss.wsf.spi.SPIProvider;
-import org.jboss.wsf.spi.SPIProviderResolver;
-import org.jboss.wsf.spi.deployment.Endpoint;
-import org.jboss.wsf.spi.invocation.RequestHandler;
-import org.jboss.wsf.spi.management.EndpointRegistry;
-import org.jboss.wsf.spi.management.EndpointRegistryFactory;
/**
* JBoss Webservices SOAP Processor.
@@ -106,16 +82,13 @@
* quickstarts.
*
* @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @author <a href="mageshbk at jboss.com">Magesh Kumar B</a>
*/
@Publish(JBossWSWebserviceContractPublisher.class)
public class SOAPProcessor extends AbstractActionPipelineProcessor {
- public static final String JBOSSWS_ENDPOINT = "jbossws-endpoint";
-
private static ThreadLocal<Message> messageTL = new ThreadLocal<Message>();
- private String jbossws_endpoint;
- private MessagePayloadProxy payloadProxy;
- private boolean httpResponseStatusEnabled;
+ private AbstractSOAPProcessor processor;
/**
* Public constructor.
@@ -123,11 +96,14 @@
* @throws ConfigurationException "jbossws-endpoint" not specified.
*/
public SOAPProcessor(ConfigTree config) throws ConfigurationException {
- jbossws_endpoint = config.getRequiredAttribute(JBOSSWS_ENDPOINT);
- payloadProxy = new MessagePayloadProxy(config,
- new String[] {BytesBody.BYTES_LOCATION, ActionUtils.POST_ACTION_DATA},
- new String[] {ActionUtils.POST_ACTION_DATA});
- httpResponseStatusEnabled = ResponseStatus.isHttpEnabled(config);
+ if (JBossDeployerUtil.getWSImpl().equals(JBossDeployerUtil.WSIMPL_NATIVE))
+ {
+ processor = new NativeSOAPProcessor(config);
+ }
+ else if (JBossDeployerUtil.getWSImpl().equals(JBossDeployerUtil.WSIMPL_CXF))
+ {
+ processor = new CXFSOAPProcessor(config);
+ }
}
/**
@@ -139,134 +115,9 @@
* @throws ActionProcessingException
*/
public Message process(Message message) throws ActionProcessingException {
- Endpoint endpoint = getServiceEndpoint(jbossws_endpoint);
- byte[] soapMessage;
-
- if(endpoint == null) {
- throw new ActionProcessingException("Unknown Service Endpoint '" + jbossws_endpoint + "'.");
- }
-
- soapMessage = getSOAPMessagePayload(message);
- try {
- messageTL.set(message);
-
- RequestHandler requestHandler = endpoint.getRequestHandler();
-
- final Map<String, List<String>> headers = new HashMap<String, List<String>>() ;
- final Properties properties = message.getProperties() ;
- final String[] names = properties.getNames() ;
- for(final String name: names)
- {
- final Object value = properties.getProperty(name) ;
- if (value != null)
- {
- final String normalisedName = name.toLowerCase() ;
- final List<String> values = headers.get(normalisedName) ;
- if (values == null)
- {
- final List<String> newValues = new ArrayList<String>() ;
- newValues.add(value.toString()) ;
- headers.put(normalisedName, newValues) ;
- }
- else
- {
- values.add(value.toString()) ;
- }
- }
- }
-
- final String requestContentType = getHeaderValue(headers, "content-type") ;
- if ("application/octet-stream".equals(requestContentType))
- {
- headers.remove("content-type") ;
- }
- final String path = getHeaderValue(headers, "path") ;
- final SOAPProcessorHttpServletRequest servletRequest = new SOAPProcessorHttpServletRequest(path, soapMessage, headers) ;
- final SOAPProcessorHttpServletResponse servletResponse = new SOAPProcessorHttpServletResponse() ;
- final SOAPProcessorServletContext servletContext = new SOAPProcessorServletContext() ;
- requestHandler.handleHttpRequest(endpoint, servletRequest, servletResponse, servletContext) ;
-
- // This may have been changed, make sure we get the current version.
- message = messageTL.get();
- final Properties responseProperties = message.getProperties() ;
- final String contentType = servletResponse.getContentType() ;
- final Map<String, List<String>> responseHeaders = servletResponse.getHeaders() ;
- // We deal with Content-Type below
- // HTTP Headers *should* be case-insensitive but not with JBR
- responseHeaders.remove("content-type") ;
-
- for(Map.Entry<String, List<String>> header: responseHeaders.entrySet())
- {
- // We can only deal with the first value in the list.
- // JBESB-2511
- new ResponseHeader(header.getKey(), header.getValue().get(0)).setPropertyNameThis(properties);
- }
- // JBESB-2761
- if (httpResponseStatusEnabled) {
- ResponseStatus.setHttpProperties(properties, servletResponse.getStatus(), servletResponse.getStatusMessage());
- }
-
- final byte[] responseData = servletResponse.getContent() ;
- if(contentType != null) {
- responseProperties.setProperty("Content-Type", new ResponseHeader("Content-Type", contentType));
- } else {
- responseProperties.setProperty("Content-Type", new ResponseHeader("Content-Type", "text/xml"));
- }
-
- if ((contentType != null) && contentType.startsWith("multipart/")) {
- payloadProxy.setPayload(message, responseData) ;
- } else {
- final String charset = servletResponse.getCharset() ;
- if (charset == null) {
- payloadProxy.setPayload(message, new String(responseData)) ;
- } else {
- payloadProxy.setPayload(message, new String(responseData, charset)) ;
- }
- }
- } catch (Exception ex) {
- throw new ActionProcessingException("Cannot process SOAP request", ex);
- } finally {
- messageTL.remove();
- }
-
- return message;
+ return processor.process(message);
}
- private String getHeaderValue(final Map<String, List<String>> headers,
- final String header)
- {
- final List<String> values = headers.get(header) ;
- if (values != null)
- {
- return values.get(0) ;
- }
- return null ;
- }
-
- private byte[] getSOAPMessagePayload(Message message) throws ActionProcessingException {
- byte[] soapMessage;
- Object messagePayload;
-
- try {
- messagePayload = payloadProxy.getPayload(message);
- } catch (MessageDeliverException e) {
- throw new ActionProcessingException(e);
- }
-
- if(messagePayload instanceof byte[]) {
- soapMessage = (byte[])messagePayload;
- } else if(messagePayload instanceof String) {
- try {
- soapMessage = ((String)messagePayload).getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new ActionProcessingException("Unable to decode SOAP message payload.", e);
- }
- } else {
- throw new ActionProcessingException("Unable to decode SOAP message payload. Must be either a byte[] or java.lang.String.");
- }
- return soapMessage;
- }
-
/**
* Set the {@link org.jboss.soa.esb.message.Message} instance for this invocation context.
* <p/>
@@ -283,30 +134,20 @@
* Get the {@link org.jboss.soa.esb.message.Message} instance for this invocation context.
*
* @return The message instance.
+ * @deprecated
*/
public static Message getMessage() {
- return messageTL.get();
+ Message message = messageTL.get();
+ if (message == null)
+ throw new RuntimeException("ESB message not found!");
+ return message;
}
/**
- * Get the Service Endpoint based on the endpoint name.
- * @param endpointName Service Endpoint name.
- * @return The service endpoint, or null if the endpoint is not found.
+ * Removes {@link org.jboss.soa.esb.message.Message} instance for this invocation context.
+ *
*/
- protected static Endpoint getServiceEndpoint(String endpointName) {
- SPIProvider spiProv = SPIProviderResolver.getInstance().getProvider();
- EndpointRegistryFactory factory = spiProv.getSPI(EndpointRegistryFactory.class);
- EndpointRegistry registry = factory.getEndpointRegistry();
- Set<ObjectName> objectNames = registry.getEndpoints();
-
- for (ObjectName objectName : objectNames) {
- String endpoint = objectName.getKeyProperty(Endpoint.SEPID_PROPERTY_ENDPOINT);
-
- if (endpoint != null && endpoint.equals(endpointName)) {
- return registry.getEndpoint(objectName);
- }
- }
-
- return null;
+ public static void removeMessage() {
+ messageTL.remove();
}
}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java 2010-07-30 07:46:02 UTC (rev 34401)
+++ labs/jbossesb/trunk/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/WebServiceUtils.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -53,6 +53,8 @@
*/
public class WebServiceUtils
{
+ public static final String JBOSSWS_ENDPOINT = "jbossws-endpoint";
+
/**
* Get the Service Endpoint based on the endpoint name's short name.
*
Modified: labs/jbossesb/trunk/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/JBossWSAdapterContractPublisherUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/JBossWSAdapterContractPublisherUnitTest.java 2010-07-30 07:46:02 UTC (rev 34401)
+++ labs/jbossesb/trunk/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/JBossWSAdapterContractPublisherUnitTest.java 2010-07-30 07:55:41 UTC (rev 34402)
@@ -81,7 +81,7 @@
private Action buildActionConfig(boolean rewriteUrls) {
final Properties properties = new Properties() ;
- properties.put(SOAPProcessor.JBOSSWS_ENDPOINT, "BlahEndpoint");
+ properties.put(WebServiceUtils.JBOSSWS_ENDPOINT, "BlahEndpoint");
properties.put(AbstractWsdlContractPublisher.REWRITE_ENDPOINT_URL, Boolean.toString(rewriteUrls));
return new Action("name", "class", "process", properties) ;
More information about the jboss-svn-commits
mailing list