3 Replies Latest reply on Aug 30, 2012 3:49 AM by Erhard Siegl

    Switchyard Java Transformation: @Inject without effect

    Christoph Gostner Newbie

      Hi,

       

      I'm running into some trouble with my SY transformation.

      Basically it's a transformation from one Java Object to another. But for the transformation additional information is needed.

       

      So I tried to inject some DAO objects, but without success. Then I modified the transformator to be a SY service with the same effect. The DAO objects are always null.

       

      @Service(RequestTransformers.class)

      public class RequestTransformersImpl implements RequestTransformers {

          @Inject

          private MyDao dao; // <- always null

         

          @Transformer

          public Request toDomainType(RequestType from) throws RoadrunnerException {

              return toDomainTypeLogic(from);

          }

         

          @Transformer

          public RequestType toSoapType(Request e) throws RoadrunnerException {

              return toSoapTypeLogic(e);

          }

      ...

      }

       

      Is @Inject not supported by transformers or is there a better solution to my problem?

        • 1. Re: Switchyard Java Transformation: @Inject without effect
          Keith Babo Master

          Whoops - this thread fell through the cracks.  Sorry about that.

           

          Injection of beans into a Transformer instance won't work because we create the Transformer instances vs. pulling them out of the CDI bean registry.  It's an interesting idea, though.  If you can file a JIRA we can have our CDI expert (*cough* Lukasz!) have a look.  It should be possible to look for injection points and wire in a reference from the bean registry.  It would be a bit of a hack though, since we're re-implementing a really narrow part of CDI (no injection scope, no observers, etc., etc.).  Another way to go would be to support a bean name instead of a java class in the Java transformer definition in switchyard.xml.  That avoids reimplementing pieces of CDI.

           

          Aside from the changes mentioned above, you can go the old school route and invoke your transformation procedurally through a camel route.  A bean can be called from the route and that bean can @Inject references to other beans.  Not as pretty as declarative transformation, but it gets the job done.  You could also put this in a CDI bean service, but you would have to call that service from a Camel route or BPM process before invoking your target service.

           

          hth,

          keith

          • 2. Re: Switchyard Java Transformation: @Inject without effect
            Christoph Gostner Newbie

            Thx for your suggestions, even if the recommended solutions seem more to be a workaround to my problem.

            But it's a good moment to improve my camel knowledge

             

            I've created a JIRA: https://issues.jboss.org/browse/SWITCHYARD-1006

             

            Christoph

            • 3. Re: Switchyard Java Transformation: @Inject without effect
              Erhard Siegl Novice

              You can also wrap an EJB around the DAO and lookup the EJB via JNDI.

               

              Erhard

              1 of 1 people found this helpful