1 Reply Latest reply on Mar 5, 2009 4:05 AM by tfennelly

    SmooksMapper extension

    olegga

      There's a problem in SmooksMapper for Wise SOAPClient. It should return only webservice parameter beans in applyMapping for request transformation. Unfortunately, Smooks returns all the beans from its configuration as result map. It makes it impossible to use Smooks request transformation for complex parameters with bean wiring. To overcome the problem I modified SmooksMapper as follows:

      /**
       * <code>WiseMapper</code> based on <a href="http://www.smooks.org/">Smooks</a> transformation.
       * <p/>
       * Extends {@link org.jboss.soa.esb.actions.soap.wise.SmooksMapper} to filter out mapping results
       * not containing in webservice parameters.
       *
       * @see org.jboss.soa.esb.actions.soap.wise.SmooksMapper
       */
      public class SmooksMapper extends org.jboss.soa.esb.actions.soap.wise.SmooksMapper {
       private WSMethod method;
      
       /**
       * Creates a {@link SmooksMapper} using the specified resource.
       *
       * @param smooksResource the URI of the Smooks resource to use
       *
       * @throws IOException if Smooks failed to read the resource
       * @throws SAXException if Smooks failed to parse the resource
       */
       public SmooksMapper(String smooksResource) throws IOException, SAXException {
       this(smooksResource, null, null);
       }
      
       /**
       * Creates a {@link SmooksMapper} using the specified resource and Smooks HTML report to
       * generate.
       * <p/>
       * A {@link SmooksMapper} will create an HTML Smooks report useful for debugging.
       *
       * @param smooksResource the URI of the Smooks resource to use
       * @param smooksReport the URI of the Smooks HTML report to generate
       *
       * @throws IOException if Smooks failed to read the resource
       * @throws SAXException if Smooks failed to parse the resource
       */
       public SmooksMapper(String smooksResource, String smooksReport) throws IOException, SAXException {
       this(smooksResource, smooksReport, null);
       }
      
       /**
       * Creates a {@link SmooksMapper} using the specified resource and webservice method.
       *
       * @param smooksResource the URI of the Smooks resource to use
       * @param method the <code>WSMethod</code> to use when mapping method parameters
       *
       * @throws IOException if Smooks failed to read the resource
       * @throws SAXException if Smooks failed to parse the resource
       *
       * @see it.javalinux.wise.core.client.WSMethod
       */
       public SmooksMapper(String smooksResource, WSMethod method) throws IOException, SAXException {
       this(smooksResource, null, method);
       }
      
       /**
       * Creates a {@link SmooksMapper} using the specified resource, Smooks HTML report to
       * generate, and webservice method.
       *
       * @param smooksResource the URI of the Smooks resource to use
       * @param smooksReport the URI of the Smooks HTML report to generate
       * @param method the <code>WSMethod</code> to use when mapping method parameters
       *
       * @throws IOException if Smooks failed to read the resource
       * @throws SAXException if Smooks failed to parse the resource
       *
       * @see it.javalinux.wise.core.client.WSMethod
       */
       public SmooksMapper(String smooksResource, String smooksReport, WSMethod method)
       throws IOException, SAXException {
       super(smooksResource, smooksReport);
       this.method = method;
       }
      
       /* (non-Javadoc)
       * @see it.javalinux.wise.core.mapper.WiseMapper#applyMapping(java.lang.Object)
       */
       public Map<String, Object> applyMapping(Object originalObjects) throws Exception {
       Map<String, Object> result = super.applyMapping(originalObjects);
       if (method != null) {
       // filter out mapping results not containing in webservice parameters
       Map<String, WebParameter> params = method.getWebParams();
       Iterator<Map.Entry<String, Object>> it = result.entrySet().iterator();
       while (it.hasNext()) {
       Map.Entry<String, Object> entry = it.next();
       if (!params.containsKey(entry.getKey()))
       it.remove();
       }
       }
       return result;
       }
      
       /**
       * Gets the webservice method.
       *
       * @return the <code>WSMethod</code>
       */
       public WSMethod getWsMethod() {
       return method;
       }
      
       /**
       * Sets the webservice method.
       *
       * @param method the <code>WSMethod</code>
       */
       public void setWsMethod(WSMethod method) {
       this.method = method;
       }
      }
      


      SOAPClient requires a slight modification as well to set right WSMethod for Smooks request mapper.
      Hope, this will be helpful.

      Oleg

        • 1. Re: SmooksMapper extension
          tfennelly

          It might be possible to work around this without making any WISE based mods. You could implement a Smooks Visitor that gets applied at the end and removes all additional/unwanted java objects from the bean context. Would just be a few lines of code. If running ESB 4.5.GA, it could be easily scripted using groovy.