[jboss-svn-commits] JBL Code SVN: r26863 - in labs/jbossesb/workspace/maeste/product/services/soap: src/main/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
Sun Jun 7 08:06:06 EDT 2009


Author: maeste
Date: 2009-06-07 08:06:05 -0400 (Sun, 07 Jun 2009)
New Revision: 26863

Modified:
   labs/jbossesb/workspace/maeste/product/services/soap/lib/ext/wise-core.jar
   labs/jbossesb/workspace/maeste/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java
Log:
code cleanup

Modified: labs/jbossesb/workspace/maeste/product/services/soap/lib/ext/wise-core.jar
===================================================================
(Binary files differ)

Modified: labs/jbossesb/workspace/maeste/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java
===================================================================
--- labs/jbossesb/workspace/maeste/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java	2009-06-06 22:22:20 UTC (rev 26862)
+++ labs/jbossesb/workspace/maeste/product/services/soap/src/main/java/org/jboss/soa/esb/actions/soap/wise/SOAPClient.java	2009-06-07 12:06:05 UTC (rev 26863)
@@ -26,6 +26,7 @@
 import java.util.List;
 import java.util.Map;
 import javax.xml.ws.handler.Handler;
+import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 import org.jboss.internal.soa.esb.publish.Publish;
 import org.jboss.soa.esb.ConfigurationException;
@@ -169,16 +170,14 @@
     private final String smooksResponseMapperURL;
     private final String smooksRequestReportURL;
     private final String smooksResponseReportURL;
-    private WiseMapper smooksRequestMapper;
-    private WiseMapper smooksResponseMapper;
-    private String operationName;
-    private String serviceName;
+    private final String operationName;
+    private final String serviceName;
     private final String username;
     private final String password;
     private final List<String> smooksHandler = new ArrayList<String>();
     private final List<String> customHandlers = new ArrayList<String>();
     private final MessagePayloadProxy payloadProxy;
-    private boolean loggingEnabled = false;
+    private final boolean loggingEnabled;
 
     private final boolean enableWSA;
     private final boolean enableWSSE;
@@ -191,9 +190,10 @@
     private final String securityConfigUrl;
     private final String securityConfigName;
 
-    private WSDynamicClient client;
-
+    private WSDynamicClient client = null;
     private WSMethod method = null;
+    private WiseMapper smooksRequestMapper = null;
+    private WiseMapper smooksResponseMapper = null;
 
     public SOAPClient( final ConfigTree config ) throws ConfigurationException {
         wsdl = config.getRequiredAttribute("wsdl");
@@ -204,11 +204,11 @@
         smooksRequestReportURL = config.getAttribute("smooksRequestReportURL");
         smooksResponseReportURL = config.getAttribute("smooksResponseReportURL");
 
-        serviceName = config.getAttribute("serviceName");
-        serviceName = serviceName != null ? serviceName : wsdl.substring(wsdl.lastIndexOf("/"), wsdl.lastIndexOf("?"));
+        serviceName = config.getAttribute("serviceName") != null ? config.getAttribute("serviceName") : wsdl.substring(wsdl.lastIndexOf("/"),
+                                                                                                                       wsdl.lastIndexOf("?"));
         username = config.getAttribute("username");
         password = config.getAttribute("password");
-        loggingEnabled = Boolean.parseBoolean(config.getAttribute("LoggingMessages"));
+        loggingEnabled = Boolean.parseBoolean(config.getAttribute("LoggingMessages", "false"));
         enableWSA = Boolean.parseBoolean(config.getAttribute("enableWSA"));
         enableWSSE = Boolean.parseBoolean(config.getAttribute("enableWSSE"));
         enableMTOM = Boolean.parseBoolean(config.getAttribute("enableMTOM"));
@@ -228,9 +228,9 @@
                 customHandlers.add(className);
             }
         }
-        operationName = config.getAttribute("operationName");
+        String opName = config.getAttribute("operationName");
 
-        if (operationName == null) {
+        if (opName == null) {
             if (soapAction == null) {
                 throw new ConfigurationException("Missing operationName or soapAction");
             }
@@ -240,11 +240,12 @@
                 if (pathIndex == soapAction.length() - 1) {
                     throw new ConfigurationException("Invalid soapAction, cannot end with '/'");
                 }
-                operationName = soapAction.substring(pathIndex + 1);
+                opName = soapAction.substring(pathIndex + 1);
             } else {
-                operationName = soapAction;
+                opName = soapAction;
             }
         }
+        operationName = opName;
 
         payloadProxy = new MessagePayloadProxy(config);
     }
@@ -255,7 +256,7 @@
      * @see org.jboss.soa.esb.actions.AbstractActionLifecycle#destroy()
      */
     @Override
-    public void destroy() throws ActionLifecycleException {
+    public synchronized void destroy() throws ActionLifecycleException {
         if (client != null) {
             if (logger.isDebugEnabled()) {
                 logger.debug("Wise cleaning up fo client " + operationName);
@@ -264,7 +265,12 @@
         }
     }
 
-    private void init( Object payload ) throws ActionLifecycleException {
+    private synchronized WSMethod init( Object payload ) throws ActionProcessingException {
+
+        if (client != null && method != null) {
+            return method;
+        }
+
         WSDynamicClientBuilder clientBuilder = WSDynamicClientFactory.getJAXWSClientBuilder();
         // TODO tmpDir
         try {
@@ -277,10 +283,10 @@
             if (logger.isDebugEnabled()) {
                 logger.debug("Exception thrown during client creation", e);
             }
-            throw new ActionLifecycleException("Could not initialize wise client " + operationName, e);
+            throw new ActionProcessingException("Could not initialize wise client " + operationName, e);
         }
-        smooksRequestMapper = createSmooksMapper(smooksRequestMapperURL, smooksRequestReportURL);
-        smooksResponseMapper = createSmooksMapper(smooksResponseMapperURL, smooksResponseReportURL);
+        smooksRequestMapper = createSmooksMapper(smooksRequestMapperURL, smooksRequestReportURL, client);
+        smooksResponseMapper = createSmooksMapper(smooksResponseMapperURL, smooksResponseReportURL, client);
 
         try {
             method = createWSMethod(client, payload);
@@ -288,33 +294,30 @@
             if (logger.isDebugEnabled()) {
                 logger.debug("Exception thrown during method creation", e);
             }
-            throw new ActionLifecycleException("Could not initialize wise WSMethod  " + operationName, e);
+            throw new ActionProcessingException("Could not initialize wise WSMethod  " + operationName, e);
         }
 
+        return method;
+
     }
 
     public Message process( final Message message ) throws ActionProcessingException {
 
         Object payload = getMessagePayload(message);
+        WSMethod localMethod = null;
 
-        if (client == null) {
-            try {
-                init(payload);
-            } catch (ActionLifecycleException e) {
-                throw new ActionProcessingException(e);
-            }
-        }
+        localMethod = init(payload);
 
         InvocationResult result;
         try {
-            result = method.invoke(payload, smooksRequestMapper);
+            result = localMethod.invoke(payload, getSmooksRequestMapper());
         } catch (final Exception e) {
             if (logger.isDebugEnabled()) {
                 logger.debug("Exception thrown from wsMethod invocation", e);
             }
             throw new ActionProcessingException("Could not call method" + operationName, e);
         }
-        return mapResponseToMessage(message, result, smooksResponseMapper, payload);
+        return mapResponseToMessage(message, result, getSmooksResponseMapper(), payload);
     }
 
     private Object getMessagePayload( final Message message ) throws ActionProcessingException {
@@ -326,7 +329,8 @@
     }
 
     private void addSmooksHandlers( final WSEndpoint endpoint,
-                                    final Object params ) {
+                                    final Object params,
+                                    final WSDynamicClient _client ) {
         for (String config : smooksHandler) {
             logger.debug("adding smooks handler:" + config);
             if (params instanceof Map) {
@@ -338,21 +342,21 @@
                 // TODO support smooks report also for handlers
                 logger.debug("adding smooks handler without map");
 
-                endpoint.addHandler(new SmooksHandler(config, null, client, null));
+                endpoint.addHandler(new SmooksHandler(config, null, _client, null));
             }
         }
 
     }
 
-    private WSMethod createWSMethod( WSDynamicClient client,
+    private WSMethod createWSMethod( WSDynamicClient _client,
                                      Object payload ) throws ResourceNotAvailableException {
         WSMethod localMethod;
 
-        localMethod = client.getWSMethod(this.serviceName, this.endPointName, this.operationName);
+        localMethod = _client.getWSMethod(this.serviceName, this.endPointName, this.operationName);
 
-        addSmooksHandlers(localMethod.getEndpoint(), payload);
+        addSmooksHandlers(localMethod.getEndpoint(), payload, _client);
         addCustomHandlers(localMethod.getEndpoint());
-        addWSExtensions(localMethod.getEndpoint());
+        addWSExtensions(localMethod.getEndpoint(), _client);
         addLoggingHandler(localMethod.getEndpoint());
 
         return localMethod;
@@ -373,20 +377,21 @@
     private void addLoggingHandler( final WSEndpoint endpoint ) {
         if (loggingEnabled) {
             logger.debug("adding logging handler");
-            // TODO support custom outputstream
-            endpoint.addHandler(new LoggingHandler());
         }
+        endpoint.addHandler(new LoggingHandler(logger, Level.INFO));
+
     }
 
-    private void addWSExtensions( final WSEndpoint endpoint ) {
+    private void addWSExtensions( final WSEndpoint endpoint,
+                                  final WSDynamicClient _client ) {
         if (enableWSSE) {
-            endpoint.addWSExtension(new WSSecurityEnabler(client));
+            endpoint.addWSExtension(new WSSecurityEnabler(_client));
         }
         if (enableWSA) {
-            endpoint.addWSExtension(new WSAddressingEnabler(client));
+            endpoint.addWSExtension(new WSAddressingEnabler(_client));
         }
         if (enableMTOM) {
-            endpoint.addWSExtension(new MTOMEnabler(client));
+            endpoint.addWSExtension(new MTOMEnabler(_client));
 
         }
 
@@ -409,13 +414,13 @@
     }
 
     private WiseMapper createSmooksMapper( final String url,
-                                           final String reportUrl ) throws ActionLifecycleException {
+                                           final String reportUrl,
+                                           final WSDynamicClient _client ) throws ActionProcessingException {
         if (url != null) {
             try {
-                // TODO support smooks reports
-                return new SmooksMapper(url, reportUrl, client);
+                return new SmooksMapper(url, reportUrl, _client);
             } catch (final Exception ex) {
-                throw new ActionLifecycleException("Unexpected exception while creating smooks mapper", ex);
+                throw new ActionProcessingException("Unexpected exception while creating smooks mapper", ex);
             }
         }
         return null;
@@ -432,4 +437,18 @@
         return operationName;
     }
 
+    /**
+     * @return smooksRequestMapper
+     */
+    private synchronized WiseMapper getSmooksRequestMapper() {
+        return smooksRequestMapper;
+    }
+
+    /**
+     * @return smooksResponseMapper
+     */
+    private synchronized WiseMapper getSmooksResponseMapper() {
+        return smooksResponseMapper;
+    }
+
 }




More information about the jboss-svn-commits mailing list