Quantcast
Channel: SCN : Unanswered Discussions - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 6719

Executing graphical mapping based on Java mapping in SAP PO7.4

$
0
0

Hi All,

 

I tried to follow the blog ESR: Message and Java Mapping's - in a Single Message Mapping!! and I using NWDS Java editor to integrate my code with the given code as per the blog.

 

Code Details:

 

package com.sap.xi.tf.user.functions;

 

 

import com.sap.aii.mapping.api.*;

import com.sap.aii.mapping.lookup.*;

import com.sap.aii.mappingtool.tf7.rt.*;

import java.io.*;

import java.lang.reflect.*;

import java.util.*;

import com.sap.ide.esr.tools.mapping.core.Init;

import com.sap.ide.esr.tools.mapping.core.Cleanup;

import java.net.URL;

 

 

 

 

public class MM_JAVAANDGRAPHICALMAPPING  {

 

  InputAttachments inputAttachments; 

  InputHeader inputHeader; 

  InputParameters inputParameters; 

  DynamicConfiguration dynamicConfiguration; 

  OutputAttachments outputAttachments; 

  OutputHeader outputHeader; 

  OutputParameters outputParameters; 

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

   try 

   { 

   dynamicConfiguration = in.getDynamicConfiguration(); 

   inputAttachments = in.getInputAttachments(); 

   inputHeader = in.getInputHeader(); 

   inputParameters = in.getInputParameters(); 

   outputAttachments = out.getOutputAttachments(); 

   outputHeader = out.getOutputHeader(); 

   outputParameters = out.getOutputParameters(); 

   InputStream is = (InputStream) in.getInputPayload().getInputStream(); 

   /*

   * **************************** GuideLines for Java Mapping ********************************************************************

   * You can have java mapping code INLINE if it is few lines. And if it is a big and complex code, then I recommend to isolate

   * java mapping logic and develop it separately as a NORMAL java program. Import it as 'imported archive' and refer it in graphical mapping

   * And then call the externally developed public method here

   * Recommendation for external method signature: public ByteArrayOutputStream YourExtBussLogicMethod(InputStream is, ...)

   * **********************************************************************************************************************************

   */ 

   /*BEGIN ************************************************* PATTERN 1 (JM - GM) **************************************************/ 

   //Java Mapping: YourExtBussLogicMethod(is) code is nothing but your java mapping logic. You can also have INLINE code here 

//  ByteArrayOutputStream baos = YourExtBussLogicMethod(is); 

//  InputStream newInputStream = new ByteArrayInputStream(baos.toByteArray()); 

   //InputPayloadImpl payloadInObj = new InputPayloadImpl(newInputStream); 

  // TransformationInputImpl transformInObj = new TransformationInputImpl(payloadInObj); 

   //Graphical mapping called here

  

  

   //My Own Code - START

  

      String str_output_temp = new String();

      String str_ULR = new String("http://XYZ/export/currrate.xml");

      String str_URLResponse_temp = new String();

      String str_URLResponse_temp2 = new String();

      String str_output_temp1 = new String();

      String str_output_temp2 = new String();

      URL url_Response = new URL(str_ULR);

      BufferedReader br_input = new BufferedReader(new InputStreamReader(url_Response.openStream()));

      while((str_URLResponse_temp = br_input.readLine()) != null)

          str_URLResponse_temp2 = str_URLResponse_temp2 + str_URLResponse_temp;

      br_input.close();

      str_output_temp = str_URLResponse_temp2;

      out.getOutputPayload().getOutputStream().write(str_output_temp.getBytes());

  

   //My Own Code - END

  

   super.transform(transformInObj, out);    >---- Error

   /*END ************************************************* PATTERN 1 (JM - GM) **************************************************/

 

 

   } 

   catch (Exception e){ 

   throw new StreamTransformationException(e.getMessage()); 

   } 

  } 

  class InputPayloadImpl extends InputPayload{ 

   InputStream in; 

     public InputPayloadImpl(InputStream in){ 

   this.in = in; 

   } 

   @Override 

     public InputStream getInputStream(){ 

   return in; 

   } 

  } 

  class TransformationInputImpl extends TransformationInput{ 

   InputPayload payload; 

   public DynamicConfiguration getDynamicConfiguration(){ 

   return dynamicConfiguration; 

   } 

   public TransformationInputImpl(InputPayload payload){ 

   this.payload = payload; 

   } 

   @Override 

   public InputAttachments getInputAttachments(){ 

   return inputAttachments; 

   } 

   @Override 

   public InputHeader getInputHeader(){ 

   return inputHeader; 

   } 

   @Override 

   public InputParameters getInputParameters(){ 

   return inputParameters; 

   } 

   @Override 

   public InputPayload getInputPayload(){ 

   return payload; 

   } 

  } 

  class OutPayloadImpl extends OutputPayload { 

     OutputStream ou; 

     public OutPayloadImpl(OutputStream ou){ 

   this.ou = ou;} 

   @Override 

     public OutputStream getOutputStream(){ 

   return ou;} 

  } 

  class TransformationOutputImpl extends TransformationOutput { 

     OutputPayload payload; 

     public TransformationOutputImpl(OutputPayload payload){ 

   this.payload = payload; 

   } 

   @Override 

     public void copyInputAttachments(){ } 

   @Override 

     public OutputAttachments getOutputAttachments(){ 

   return outputAttachments; 

   } 

   @Override 

     public OutputHeader getOutputHeader(){ 

   return outputHeader; 

   } 

   @Override 

     public OutputParameters getOutputParameters() { 

   return outputParameters; 

   } 

   @Override 

     public OutputPayload getOutputPayload(){ 

   return payload; 

   } 

  } 

 

 

  

  @Init(description="")

  public void init (

  GlobalContainer container)  throws StreamTransformationException{

 

  }

 

 

  @Cleanup

  public void cleanup (

  GlobalContainer container)  throws StreamTransformationException{

 

  }

}

 

 

I am getting error at statement    super.transform(transformInObj, out); 

Could you advice with what details I need to create transformInObj because I would like to write my java code in the same code which will provide the xml structure retrieved from URL and the same will be provided as source to graphical mapping for further mapping with IDoc.


Thanks,

Dhill


 


Viewing all articles
Browse latest Browse all 6719

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>