Skip to Content

A letter from Java Mapping to ESR


Dear ESR,

I am happy that you have provided such a wonderful Graphical Editor with rich GUI for Message Mapping, but a bit jealous also that you never cared about me. They treat me as last resort when nothing else works. It’s a bit unfair that I never had the privilege of friendly environment like you provided to your dear Message Mapping.

I agree that with swing based ESR it was difficult, but even with Eclipse based ESR I can’t see any improvement. Everyone know that Message Mapping is also kind of Java Mapping at heart. Still you helped him compiling the code with Mapping API and generating jar. I’d also love to be more visible and flexible instead of just hiding behind Imported archive.

Regards,

Java Mapping


I am sure you agree writing Java Mapping outside ESR has always been a pain. Even for doing a small change, you have to follow the whole cycle of checking your source code in a Java Editor, recompiling it with Mapping API and finally uploading the jar generated as Imported archive. And what if you don’t find the source code as earlier developer never bothered to keep a source code copy in Imported Archive, then one more unofficial step of decompiling the jar first.

Won’t it be a cool idea if you could manage your Java mapping directly in ESR. Here is the list of advantage you get

1. No need of Mapping API

2. No need to write mapping class from scratch

3. No need of manual compilation and Jar creation

4. No need of importing the jar as Imported Archive

5. With visible code, changing the mapping would be more transparent

If you can’t wait till the idea becomes reality, you have a workaround. Here you go!

1. Create Message Mapping

2. Select some dummy message type in Source and Target as that it is not validated in java mapping

3. Go to Functions tab > Attributes and Methods

4. Start with writing transform(PI >=7.1)/execute(PI< 7.1) method directly as all the import statement are already there in import section. For example to change namespace prefix from ns0 to pfx, you can try this code.

5. Save and test as is done for Message Mapping

public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {

    try {

          // Your logic goes here

  }

    catch (Exception e) {

           throw new StreamTransformationException(e.getMessage());

  }

}

/wp-content/uploads/2013/03/image002_193840.png

If you are lucky enough to have PI>=7.3, you can easily write code using Eclipse based ESR with auto completion feature(Ctrl + SPACE).

The first 2 steps are same as above.

3. Open Message Mapping in Java Editor

4. Start with writing the transform method

5. Save and test as is done for Message Mapping

/wp-content/uploads/2013/03/image004_193881.png

Hope you like this idea of writing Java Mapping directly in ESR. You can also vote to promote this at IdeaPlace.

Reference:

Hack: Using XPATH in XI Message Mappings

To report this post you need to login first.

25 Comments

You must be Logged on to comment or reply to a post.

  1. Panupong Jitchopjai

    Dear

    Sunil Chandra

         I am a new PI developer. I have some doubt about your way. After writing code of transform function, I try to test message mapping, i always got  an error which showed that target cannot be created. Could you please clarify me about necessary  step I missing. 🙁

    (0) 
  2. Shabarish Vijayakumar

    I think with the direction of a consolidated IDE i.e Eclipse for SAP PI/PO, one wouldnt really even open ESR eventually 🙂

    The IDE will then become centric to all development, including Java mapping.

    (0) 
        1. Emil Jessen

          Hi Sunil,

          Can you provide an working example from a message mapping? I can only get the AbstractTrace to work in the “old normal” java mapping. Not in the default method provided within the message mapping.

          Thanks.

          Emil

          (0) 
  3. Alessandro Guarneri

    Hi Sunil,

    Brilliant idea, but I can’t make it really work. I’m on PO 7.4 single stack, and using NWDS ESR Perspective.

    At first, I wrote a simple Identity Mapping with your method (let the InputStream flow into the OutputStream) and it looked like it was working.

    Now I came to something “real” (an Extended Receiver Determination, btw) and when I run it, a simply obtain the empty standard Receivers xml doc.

    I wanted to trace something (or even better debug it, but no clue) but when you state that getTrace() will do the job, it is in fact a method of AbstractTransformation, which a normal message mapping (even when opened in the Java editor) doesn’t extend itself. I will try adding it, but am I allowed?

    Do you have any suggestion?

    Many thanks and regards

    Alex

    (0) 
    1. Sunil Chandra Post author

      Nice to see a comment from you Alex 🙂

      As per my observation, getTrace() execution behavior is same in both swing based or NWDS java editor. Although it displays the line as error in NWDS java editor, it won’t be a problem while activating the mapping. The other way is to explicitly extend the class with AbstractTransformation as you mentioned already.

      I am not sure why it is not working for Extended Receiver Determination. Could you share more details about it.

      Regards,

      Sunil Chandra

      (0) 
      1. Alessandro Guarneri

        Sunil,

        Thanks for replying! 🙂

        Actually I was able to make it work, but let me point out a couple of bad drawbacks that this approach brings on:

        1. you cannot debug your java code: the real code being executed is different, in the sense that a bunch of methods and code are hidden in the Java Editor. If you connect you NWDS for remote debug on port 5xx21 of your Java AS, you will easily notice that: code is misaligned, so debugging is impossible.
        2. how to get the trace is still a mystery to me: in fact if you tweak the class declaration by adding “extends AbstractTransformation”, once you save it gets removed… And if you declare a trace as an attribute, and try to instantiate it in the “init” method using “container.getTrace()” (which makes sense), sadly the init method is not called and thus your trace instance crashes with a NullPointerException.
        3. The test feature inside NWDS is much less tolerant than the one in ESR, so I recommend to test in ESR. E.g. if you want to process a flat file, not XML, you can’t in NWDS, while it’s possible in ESR, no problem.
        4. Last but not least, from time to time, the ESR just goes nuts and doesn’t recognize anymore any change to your Java code, keeping on issuing ols errors, even if you fixed them, even if you activate the change list. No way out but creating a new mapping and copy-paste your code.

        Today I had to switch a tricky mapping to the old-fashioned Java Mapping in order to be able to debug it properly.

        So, to make a long story short, in my opinion this approach can be ok for simple code, but if things get hard, maybe the good old Java code and imported archive is still best.


        Just my 2 cents. 😉


        Good blog, Sunil, very good blog.

        Take care.


        Cheers


        Alex

        (0) 
        1. Eng Swee Yeoh

          Hi Alex

          I’ve used this technique by Sunil on quite a number of relatively complex Java mapping logic and they have all been working fine during development phase and also now running in production.

          Just wanted to share some of my experience in relation to the points that you mentioned.

          2. You can get the trace using the code below. Although this flags up as a syntax error in NWDS ESR Perspective Java Editor, it actually compiles fine.

          AbstractTrace trace = this.getTrace();

          Although it is not indicated in the Java Editor, the mapping actually internally extends com.sap.aii.mappingtool.tf7.AMappingProgram, which then extends AbstractTransformation which has the getTrace() method.

          You can check out Praveen’s reply in the comment section of his blog on this.

          ESR: Message and Java Mapping’s – in a Single Message Mapping!!

          3. I tested my mapping with a non-XML file in NWDS and it works fine too. In the ESR perspective, I right-clicked the Message Mapping and clicked Generate > XML File, but actually replaced the XML content with non XML content. After that I created a Run Configuration and linked the file as a test case and execute it. It seems to work fine.

          4. I initially had a lot of issues running mapping on NWDS ESR perspective. Finally the tricked that worked for me was to use SAP’s JVM, and ensure that my NWDS version/SP/patch matches the PI system.

          Also, to ensure that the changes in the Java editor always gets saved and activated correctly, I always use “Right-click > Open With > Java Editor” to access the source code, then save it in a change list. I noticed that if I open the mapping in the Mapping Editor first, saving it into a change list before switching into the Java Editor and making edits, although the code is there, but it does not work correctly. It’s weird but if you want to directly edit the Java code, go directly to the Java Editor first.

          Hope some of these might come in handy for you.

          Rgds

          Eng Swee

          (0) 
  4. Anand Gopinath

    Hi Sunil – Is there a way to access DynamicConfiguration object in this method of java mapping. Can the ‘map’ object from where the DynamicConfiguration object is obtained in a ‘normal’ java mapping, be accessed in this method as well?

    (0) 

Leave a Reply