cancel
Showing results for 
Search instead for 
Did you mean: 

Need Java Adapter module for reoving xml tags from Input Payload

Former Member
0 Kudos

Hi All,

I have the below file which I am getting via Proxy Sender to File Receiver.

<?xml version="1.0" encoding="utf-8"?>

<nm:MT_Send_EWM_to_SSIDataOut xmlns:nm="http://abc.com/EWM/SAPTOSSI/EWM_I66" xmlns:prx="urn:sap.com:proxy:ETD:/1SAI/TAS1C2471FB6D66D1F4F1B1:731">

<action>

<outputs>

<output name="2.1.5" set="TRUE"/>

</outputs>

</action>

</nm:MT_Send_EWM_to_SSIDataOut>

But I need the file to be like:

<action>

<outputs>

<output name="2.6.6" set="true"/>

</outputs>

</action>

So, this means I want to remove first 2 xl lines and one last xml line from the incoming payload.

PS: I am not using any Mapping in this interface.

Can anybody give me some idea or inputs for the same.

Thanks

Neha

Accepted Solutions (1)

Accepted Solutions (1)

subhro_de
Active Participant
0 Kudos

Keep a dummy interface on the receiver end which most probably you have already -  add a java mapping and replace the following strings with blank.

String 1 --> <?xml version="1.0" encoding="utf-8"?><nm:MT_Send_EWM_to_SSIDataOutxmlns:nm="http://abc.com/EWM/SAPTOSSI/EWM_I66" xmlns:prx="urn:sap.com:proxy:ETD:/1SAI/TAS1C2471FB6D66D1F4F1B1:731">

String 2 --> </nm:MT_Send_EWM_to_SSIDataOut>

Note that the double quotes need to be placed with escape characters in front when you are using it in java.

The java mapping code can be something like below :


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
//1. AbstractTransformation class is imported.
// The associated jar file is: com.sap.xpi.ib.mapping.lib.jar
import com.sap.aii.mapping.api.AbstractTransformation;
import  com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.mapping.api.InputHeader;
 
public class RemoveHeader extends AbstractTransformation {


  public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
     getTrace().addDebugMessage("JAVA Mapping Called");
  String inData = convertStreamToString(arg0.getInputPayload().getInputStream());
  try
  {
   String output = inData.replace() --> your string 1;
   output.replace() --> your string 2;
   arg1.getOutputPayload().getOutputStream().write(output.getBytes());
  }
  catch(Exception exception1) {
  
  }
      }
     
  /* Converts Input stream to String */
  public String convertStreamToString(InputStream in){
  StringBuffer sb = new StringBuffer();
  try
  {
  InputStreamReader isr = new InputStreamReader(in);
  Reader reader =
  new BufferedReader(isr);
  int ch;
  while((ch = in.read()) > -1) {
   sb.append((char)ch);}
   reader.close();
  }
  catch(Exception exception) { }
  return sb.toString();
     }
}

Regards

Subhro

Former Member
0 Kudos

Hi,

M not using any mappings till now.

Is mapping really required or is their some other way too??

Former Member
0 Kudos

Hello,

U can use either adapter module or java mapping, so certainly both the options are available. Having said that maintaining java mapping is bit more easy then adapter module, but the choice is urs.

Thanks

Amit Srivastava

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi I have the same issue. I am trying to remove <?xml version="1.0" encoding="utf-8"?>. My scenario is JDBC to file. But in the receiver side as file we do not want to placed <?xml version="1.0" encoding="utf-8"?>. So I used java mappig and xsl mapping . But unfortunatelly in Operation mapping testing it is not in xml format. Is xsl wron or is it not possible to remove with xsl mapping ?

Sincerely ,

Ceren.


Former Member
0 Kudos

Hi All,

The issue is resolved.

I am using Java Mapping.

S0003485845
Contributor
0 Kudos

Hi,

in case you have a some Seeburger EDI-Adapter available on the system, you can also use the  "replace string" module to remove these parts of the file.

(there you can use "regular expressions" to define the parts that need to be removed)

Kind Regards

Stefan

Former Member
0 Kudos

Hmm... this is a little unorthodox but maybe you can treat this mapping like a content conversion (in the receiver file adapter)

like that - you will insert each tag name as a value (where you will use constants for the action and outputs open and close tags) and so you will not have to deal with the adapter module (I don't know of any that can do exactly what you require.

I guess you can also use the message mapping as Amit said above and code the parsing of the output XML... not sure what will be better.

Good luck anyway.

former_member190624
Active Contributor
0 Kudos

Hello Neha,

If your scenario is proxy to file (Asyn).

By using any mapping program , you can achieve your requirement . For example use graphical mapping as shown below ,

Regards

Hari.

Former Member
0 Kudos

I think that in this case the first line <?xml version="1.0" encoding="utf-8"?> will still be in the output file...

And also the lines of the MT will be created (only with a different name for the MT)

Former Member
0 Kudos

Hello,

I think u can also use java mapping? Anyway in ur code u have to just use replaceAll function to remove the xml declaration and MT** tag from the incoming message...

Thanks

Amit Srivastava