[jboss-svn-commits] JBL Code SVN: r24928 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src: test/java/org/jboss/soa/esb/actions/soap/wise and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Jan 26 11:53:25 EST 2009
Author: kevin.conner at jboss.com
Date: 2009-01-26 11:53:24 -0500 (Mon, 26 Jan 2009)
New Revision: 24928
Added:
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksHandler.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksMapper.java
Modified:
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/WSDynamicClientFactory.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wise/SOAPClientUnitTest.java
Log:
Update for JBESB-2301
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java 2009-01-26 16:21:36 UTC (rev 24927)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java 2009-01-26 16:53:24 UTC (rev 24928)
@@ -27,24 +27,18 @@
import it.javalinux.wise.core.client.WSEndpoint;
import it.javalinux.wise.core.client.WSMethod;
import it.javalinux.wise.core.client.handler.LoggingHandler;
-import it.javalinux.wise.core.client.handler.SmooksHandler;
import it.javalinux.wise.core.exceptions.WiseException;
-import it.javalinux.wise.core.mapper.SmooksMapper;
import it.javalinux.wise.core.mapper.WiseMapper;
-import it.javalinux.wise.core.utils.SmooksCache;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
import javax.xml.ws.handler.Handler;
import org.apache.log4j.Logger;
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor;
-import org.jboss.soa.esb.actions.ActionLifecycleException;
import org.jboss.soa.esb.actions.ActionProcessingException;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
@@ -167,6 +161,8 @@
private final String endPointName;
private final String smooksRequestMapperURL;
private final String smooksResponseMapperURL;
+ private final WiseMapper smooksRequestMapper;
+ private final WiseMapper smooksResponseMapper;
private String operationName;
private String serviceName;
private final String username;
@@ -178,20 +174,19 @@
private WSDynamicClient client;
- final ConcurrentMap<String, WSEndpoint> endpointMap = new ConcurrentHashMap<String, WSEndpoint>();
-
public SOAPClient(final ConfigTree config ) throws ConfigurationException
{
wsdl = config.getRequiredAttribute("wsdl");
soapAction = config.getRequiredAttribute("SOAPAction");
endPointName = config.getRequiredAttribute("EndPointName");
smooksRequestMapperURL = config.getAttribute("SmooksRequestMapper");
+ smooksRequestMapper = createSmooksMapper(smooksRequestMapperURL) ;
smooksResponseMapperURL = config.getAttribute("SmooksResponseMapper");
+ smooksResponseMapper = createSmooksMapper(smooksResponseMapperURL) ;
serviceName = config.getAttribute("serviceName");
serviceName = serviceName != null ? serviceName : wsdl.substring(wsdl.lastIndexOf("/"), wsdl.lastIndexOf("?"));
username = config.getAttribute("username");
password = config.getAttribute("password");
- logger.info(config.getAttribute("LoggingMessages"));
loggingEnabled = Boolean.parseBoolean(config.getAttribute("LoggingMessages"));
logger.info("loggingEnabled:" + loggingEnabled);
@@ -206,19 +201,32 @@
{
customHandlers.add(className);
}
-
}
operationName = config.getAttribute("operationName");
if (operationName == null)
{
- operationName = soapAction;
+ if (soapAction == null)
+ {
+ throw new ConfigurationException("Missing operationName or soapAction") ;
+ }
+ final int pathIndex = soapAction.lastIndexOf('/') ;
+ if (pathIndex >= 0)
+ {
+ if (pathIndex == soapAction.length() -1)
+ {
+ throw new ConfigurationException("Invalid soapAction, cannot end with '/'") ;
+ }
+ operationName = soapAction.substring(pathIndex+1) ;
+ }
+ else
+ {
+ operationName = soapAction;
+ }
}
payloadProxy = new MessagePayloadProxy(config);
-
- logger.info(this);
}
public Message process(final Message message) throws ActionProcessingException
@@ -236,13 +244,13 @@
InvocationResult result;
try
{
- result = wsMethod.invoke(payload, createSmooksMapper(smooksRequestMapperURL));
+ result = wsMethod.invoke(payload, smooksRequestMapper);
}
catch (final WiseException e)
{
throw new ActionProcessingException("Could not call method" + this.soapAction, e);
}
- return mapResponseToMessage(message, result, createSmooksMapper(smooksResponseMapperURL));
+ return mapResponseToMessage(message, result, smooksResponseMapper);
}
synchronized WSDynamicClient createClient(final String wsdl, final String serviceName, final String username, final String password) throws ActionProcessingException
@@ -287,19 +295,31 @@
}
private void addSmooksHandlers(final WSEndpoint endpoint, final Object params)
+ throws ActionProcessingException
{
- for (String config : smooksHandler)
+ try
{
- logger.info("adding smooks handler:" + config);
- if (params instanceof Map)
+ for (String config : smooksHandler)
{
- endpoint.addHandler(new SmooksHandler(config, (Map)params));
- }
- else
- {
- endpoint.addHandler(new SmooksHandler(config, null));
+ logger.info("adding smooks handler:" + config);
+ if (params instanceof Map)
+ {
+ endpoint.addHandler(new SmooksHandler(config, (Map)params));
+ }
+ else
+ {
+ endpoint.addHandler(new SmooksHandler(config, null));
+ }
}
}
+ catch (final RuntimeException re)
+ {
+ throw re ;
+ }
+ catch (final Exception ex)
+ {
+ throw new ActionProcessingException("Unexpected exception while adding smooks handlers", ex) ;
+ }
}
private void addCustomHandlers(final WSEndpoint endpoint)
@@ -339,15 +359,9 @@
throw new ActionProcessingException("No WSMethod found for " + name);
}
-
Map<String, WSEndpoint> getEndpoints(final WSDynamicClient client)
{
- if (endpointMap.isEmpty())
- {
- Map<String, WSEndpoint> processEndpoints = client.processEndpoints();
- endpointMap.putAll(processEndpoints);
- }
- return endpointMap;
+ return client.processEndpoints();
}
@@ -365,40 +379,17 @@
}
private WiseMapper createSmooksMapper(final String url)
+ throws ConfigurationException
{
if (url != null) {
- return new SmooksMapper(url, "smook/report/report.html");
+ try {
+ return new SmooksMapper(url, "smook/report/report.html");
+ } catch (final Exception ex) {
+ throw new ConfigurationException("Unexpected exception while creating smooks mapper", ex) ;
+ }
}
return null;
}
-
- @Override
- public void destroy() throws ActionLifecycleException
- {
- try
- {
- if (smooksRequestMapperURL != null)
- {
- SmooksCache.getInstance().put(smooksRequestMapperURL, null);
- }
- }
- catch (final Exception e)
- {
- throw new ActionLifecycleException("Error while trying to clean SmooksCache", e);
- }
-
- try
- {
- if (smooksResponseMapperURL != null)
- {
- SmooksCache.getInstance().put(smooksResponseMapperURL, null);
- }
- }
- catch (final Exception e)
- {
- throw new ActionLifecycleException("Error while trying to clean SmooksCache", e);
- }
- }
@Override
public String toString()
Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksHandler.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksHandler.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksHandler.java 2009-01-26 16:53:24 UTC (rev 24928)
@@ -0,0 +1,176 @@
+/**
+ * WISE Invokes Services Easily - Stefano Maestri / Alessio Soldano
+ *
+ * http://www.javalinuxlabs.org - http://www.javalinux.it
+ *
+ * Wise 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.
+ *
+ * Wise 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 at gnu.org.
+ */
+package org.jboss.soa.esb.actions.soap.wise;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.milyn.Smooks;
+import org.milyn.container.ExecutionContext;
+import org.milyn.javabean.BeanAccessor;
+import org.milyn.resource.URIResourceLocator;
+import org.xml.sax.SAXException;
+
+/**
+ * A SOAPHandler extension. It apply smooks transformation on soap message.
+ * Transformation can also use freemarker, using provided javaBeans map to get
+ * values It can apply transformation only on inbound message, outbound ones or
+ * both, depending on
+ *
+ * @see #setInBoundHandlingEnabled(boolean)
+ * @see #setOutBoundHandlingEnabled(boolean)
+ *
+ * @author Stefano Maestri, stefano.maestri at javalinux.it
+ *
+ */
+public class SmooksHandler implements SOAPHandler<SOAPMessageContext> {
+
+ private String smooksResource;
+
+ private Map beansMap;
+
+ private boolean outBoundHandlingEnabled = true;
+
+ private boolean inBoundHandlingEnabled = true;
+
+ private final Smooks smooks ;
+
+ /**
+ *
+ * @param resource
+ * URI of smooks config file
+ * @param beans
+ * used for smooks BeanAccessor
+ * @throws IOException
+ * @throws SAXException
+ * @throws IllegalArgumentException
+ */
+ public SmooksHandler(String resource, Map beans) throws IllegalArgumentException, SAXException, IOException {
+ this.smooksResource = resource;
+ this.beansMap = beans;
+ smooks = new Smooks();
+ smooks.addConfigurations("smooks-resource", new URIResourceLocator().getResource(smooksResource));
+ }
+
+ public Set getHeaders() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void close(MessageContext arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean handleFault(SOAPMessageContext arg0) {
+ return false;
+ }
+
+ public boolean handleMessage(SOAPMessageContext smc) {
+ SOAPMessage message = smc.getMessage();
+ Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
+ if (outboundProperty == true && this.isOutBoundHandlingEnabled() == false) {
+ return false;
+ }
+ if (outboundProperty == false && this.isInBoundHandlingEnabled() == false) {
+ return false;
+ }
+ if (smooksResource != null) {
+ try {
+ smc.setMessage(applySmooksTransformation(message));
+ } catch (Exception e) {
+ return false;
+ }
+ return true;
+
+ } else {
+ return false;
+ }
+
+ }
+
+ SOAPMessage applySmooksTransformation(SOAPMessage message) throws Exception {
+ ByteArrayOutputStream outStream = null;
+ ByteArrayInputStream inStream = null;
+
+ try {
+
+ ExecutionContext executionContext = smooks.createExecutionContext();
+ StringWriter transResult = new StringWriter();
+
+ BeanAccessor.getBeans(executionContext).putAll(this.beansMap);
+ StringWriter buffer;
+ outStream = new ByteArrayOutputStream();
+ message.writeTo(outStream);
+ outStream.flush();
+ inStream = new ByteArrayInputStream(outStream.toByteArray());
+ smooks.filter(new StreamSource(inStream), new StreamResult(transResult), executionContext);
+ inStream.close();
+ inStream = new ByteArrayInputStream(transResult.toString().getBytes());
+ SOAPMessage message2 = MessageFactory.newInstance().createMessage(message.getMimeHeaders(), inStream);
+ return message2;
+ } finally {
+ try {
+ inStream.close();
+ } catch (Exception e) {
+ // nop
+ }
+ try {
+ outStream.close();
+ } catch (Exception e) {
+ // nop
+ }
+ }
+ }
+
+ public boolean isOutBoundHandlingEnabled() {
+ return outBoundHandlingEnabled;
+ }
+
+ /**
+ *
+ * @param outBoundHandlingEnabled
+ * if true smooks transformation are applied to outBound
+ * message
+ */
+ public void setOutBoundHandlingEnabled(boolean outBoundHandlingEnabled) {
+ this.outBoundHandlingEnabled = outBoundHandlingEnabled;
+ }
+
+ public boolean isInBoundHandlingEnabled() {
+ return inBoundHandlingEnabled;
+ }
+
+ /**
+ *
+ * @param inBoundHandlingEnabled
+ * if true smooks transformation are applied to inBound
+ * message
+ */
+ public void setInBoundHandlingEnabled(boolean inBoundHandlingEnabled) {
+ this.inBoundHandlingEnabled = inBoundHandlingEnabled;
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksHandler.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksMapper.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksMapper.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksMapper.java 2009-01-26 16:53:24 UTC (rev 24928)
@@ -0,0 +1,122 @@
+/**
+ * WISE Invokes Services Easily - Stefano Maestri / Alessio Soldano
+ *
+ * http://www.javalinuxlabs.org - http://www.javalinux.it
+ *
+ * Wise 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.
+ *
+ * Wise 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 at gnu.org.
+ */
+package org.jboss.soa.esb.actions.soap.wise;
+
+import it.javalinux.wise.core.mapper.WiseMapper;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.xml.transform.Source;
+
+import org.milyn.Smooks;
+import org.milyn.container.ExecutionContext;
+import org.milyn.container.plugin.PayloadProcessor;
+import org.milyn.event.report.HtmlReportGenerator;
+import org.milyn.payload.JavaResult;
+import org.milyn.resource.URIResourceLocator;
+import org.xml.sax.SAXException;
+
+/**
+ * A WiseMapper based on smooks, copied from the wise codebase
+ *
+ * @author stefano.maestri at javalinux.it
+ *
+ */
+public class SmooksMapper implements WiseMapper {
+
+ private String smooksResource;
+
+ private String smooksReport ;
+
+ private final Smooks smooks ;
+
+ /**
+ * Create this mapper using passed resource
+ *
+ * @param smooksResource
+ * URI of smooks resource to use
+ * @throws SAXException
+ * @throws IOException
+ * @throws IllegalArgumentException
+ */
+ public SmooksMapper(String smooksResource)
+ throws IllegalArgumentException, IOException, SAXException {
+ this(smooksResource, null);
+ }
+
+ /**
+ * Create this mapper using passed resource and passed smooks html report to
+ * generate. A SmooksMapper created with this constructor will create an
+ * html smooks report useful for debug.
+ *
+ * @param smooksResource
+ * URI of smooks resource to use
+ * @param smooksReport
+ * the URI of smooks html report to generate.
+ * @throws SAXException
+ * @throws IllegalArgumentException
+ */
+ public SmooksMapper(String smooksResource, String smooksReport)
+ throws IOException, IllegalArgumentException, SAXException {
+ this.smooksResource = smooksResource;
+ this.smooksReport = smooksReport;
+ smooks = new Smooks();
+ smooks.addConfigurations("smooks-resource", new URIResourceLocator().getResource(smooksResource));
+ }
+
+ /**
+ * apply this mapping to original object
+ *
+ * @param originalObjects
+ * @return Map returned is typically used to invoke webservice operations.
+ * To do this, beanids defined in smooks config (and used here as
+ * Map's keys) have to be the parameters names as defined in
+ * wsdl/wsconsume generated classes
+ * @throws Exception
+ */
+ public Map<String, Object> applyMapping(Object originalObjects) throws Exception {
+
+ ExecutionContext executionContext = smooks.createExecutionContext();
+ Source source;
+ JavaResult result = new JavaResult();
+ // Configure the execution context to generate a report...
+ if (this.getSmooksReport() != null) {
+ executionContext.setEventListener(new HtmlReportGenerator(this.getSmooksReport()));
+ }
+ org.milyn.container.plugin.PayloadProcessor payloadProcessor = new PayloadProcessor(smooks, org.milyn.container.plugin.ResultType.JAVA);
+ // smooks should return a map
+ // TODO: verify with some unit tests
+ return (Map<String, Object>) payloadProcessor.process(originalObjects, executionContext);
+ // return result.getResultMap();
+
+ }
+
+ public String getSmooksResource() {
+ return smooksResource;
+ }
+
+ public void setSmooksResource(String smooksResource) {
+ this.smooksResource = smooksResource;
+ }
+
+ public String getSmooksReport() {
+ return smooksReport;
+ }
+
+ public void setSmooksReport(String smooksReport) {
+ this.smooksReport = smooksReport;
+ }
+
+}
Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SmooksMapper.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/WSDynamicClientFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/WSDynamicClientFactory.java 2009-01-26 16:21:36 UTC (rev 24927)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/WSDynamicClientFactory.java 2009-01-26 16:53:24 UTC (rev 24928)
@@ -48,8 +48,15 @@
{
private static final String WISE_PROPERTIES_FILE = "wise-core.properties";
- public WSDynamicClient create(final String wsdl, final String name, final String username, final String password) throws WiseException
+ private static final WSDynamicClientFactory SINGLETON = new WSDynamicClientFactory() ;
+
+ public static WSDynamicClientFactory getFactory()
{
+ return SINGLETON ;
+ }
+
+ public synchronized WSDynamicClient create(final String wsdl, final String name, final String username, final String password) throws WiseException
+ {
AssertArgument.isNotNull(name, "name");
AssertArgument.isNotNull(wsdl, "wsdl");
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wise/SOAPClientUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wise/SOAPClientUnitTest.java 2009-01-26 16:21:36 UTC (rev 24927)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/services/soap/src/test/java/org/jboss/soa/esb/actions/soap/wise/SOAPClientUnitTest.java 2009-01-26 16:53:24 UTC (rev 24928)
@@ -50,6 +50,7 @@
private static File workingDir;
private String wsdl = "http://127.0.0.1:8080/Quickstart_webservice_consumer_wise/HelloWorldWS?wsdl";
private String soapAction = "sayHello";
+ private String soapActionURI = "http://example.com/opnamespace/sayHello";
private String endPointName = "HelloWorldPort";
private String serviceName = "HelloWorldService";
@@ -69,8 +70,7 @@
@Test
public void configNoOperationName() throws ConfigurationException, ActionProcessingException, ActionLifecycleException
{
- final String operationName = null;
- final ConfigTree config = createConfig(operationName);
+ final ConfigTree config = createConfig(null, soapAction);
final SOAPClient client = new MockSOAPClient(config);
assertNotNull(client.getOperationName());
@@ -78,10 +78,20 @@
}
@Test
+ public void configNoOperationNameURI() throws ConfigurationException, ActionProcessingException, ActionLifecycleException
+ {
+ final ConfigTree config = createConfig(null, soapActionURI);
+ final SOAPClient client = new MockSOAPClient(config);
+
+ assertNotNull(client.getOperationName());
+ assertEquals(soapAction, client.getOperationName());
+ }
+
+ @Test
public void configOperationName() throws ConfigurationException, ActionProcessingException, ActionLifecycleException
{
final String operationName = "someOperation";
- final ConfigTree config = createConfig(operationName);
+ final ConfigTree config = createConfig(operationName, soapAction);
final SOAPClient client = new MockSOAPClient(config);
assertNotNull(client.getOperationName());
@@ -93,7 +103,7 @@
return new JUnit4TestAdapter(SOAPClientUnitTest.class);
}
- private ConfigTree createConfig(final String operationName)
+ private ConfigTree createConfig(final String operationName, final String soapAction)
{
final ConfigTree configTree = new ConfigTree("wise-soap-client");
configTree.setAttribute("wsdl", wsdl);
More information about the jboss-svn-commits
mailing list