cancel
Showing results for 
Search instead for 
Did you mean: 

Java Mapping using "StreamTransformation"

helmut_skolaut3
Active Participant
0 Kudos

Hi all,

we facing during our PI 7.5 migration to the problem that Java mappings that have been implemented in the time with PI 7.0, migrated to 7.11 are no longer working.

They have been implemented using following pattern:

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

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

public class ClassName implements StreamTransformation {

     public void execute(InputStream in, OutputStream out) throws StreamTransformationException {

     }

}

I am wondering if there is a way to use those mappings without re-engineer them to the new way:

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

public class ClassName extends AbstractTransformation {

     public void transform(TransformationInput source, TransformationOutput target)  {

     }

}

I guess changing it to the new pattern will be quiet easy, but we need to plan comprehensive tests ... ;-(

Any comments from you?

Thanks

  Helmut

Accepted Solutions (1)

Accepted Solutions (1)

iaki_vila
Active Contributor
0 Kudos

Hi Helmut,

Are you using static fields or methods?. Pay attention to the documentation: AbstractTransformation

Regards.

helmut_skolaut3
Active Participant
0 Kudos

Hi all,

together with an external consultant I have found the problem:

// Get a SAX Parser
SAXParserFactory factory = null;
factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);

The default behavior of the SAX parser has changed, with older versions, "true" is default where current version "no" is standard so I had to set the flag ;-(

Regards

  Helmut

former_member182412
Active Contributor
0 Kudos

Close the thread then.

Answers (3)

Answers (3)

stefan_grube
Active Contributor
0 Kudos

In PI 7.11, there is an option "use SAPXMLTOOLKIT" in operation mapping. This should enable the use of PI 7.0 Java mappings without change.

former_member182412
Active Contributor
0 Kudos

Hi Helmut,

Just add this method in the java mapping, you no need to change anything.


@Override

  public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)

  throws StreamTransformationException {

  execute(transformationInput.getInputPayload().getInputStream(), transformationOutput.getOutputPayload().getOutputStream());

  }

Regards,

Praveen.

helmut_skolaut3
Active Participant
0 Kudos

Hi all,

I narrowed it a bit down. The mapping is using the sax parser and when I test it, i am getting an ClassPath exception for the sax parser.

I keep you informed.

Regards

  Helmut

manoj_khavatkopp
Active Contributor
0 Kudos

Helmut,

Check if this parameter helps.

Br,

Manoj

helmut_skolaut3
Active Participant
0 Kudos

Hi Manoj,

the parameter was already set in the system ....

Regards

  Helmut

manoj_khavatkopp
Active Contributor
0 Kudos

Helmut,

What is the error you are getting ?

Because even i am in the same phase of migrating from 7.1 and 7.5 and i didn't face any issue with JavaMapping , and some of them are already live in Production 7.5

As StreamTransformation is deprecated but still works in 7.5 , and if you have large number of javamapping then changing it to AbstractTransformation would cost more effort.

Br,

Manoj

helmut_skolaut3
Active Participant
0 Kudos

Hello Manoj,

when the Java mapping is configured in the Operational Mapping, the result payload is empty (0 bytes long). For test reason we have removed the Java mapping, then the result payload is there (for sure without the necessary manipulation).

You are using the old implementation pattern? I have learnt that under 7.1 created Java mappings are usually been implemented using the AbstractTransformation Class already.


Thanks for your collaboration, maybe you can briefly look into the mapping how it's implemented.


Regards

  Helmut

manoj_khavatkopp
Active Contributor
0 Kudos

Hi Helmut,

Not sure why old developer had used StreamTransformation in 7.1 as AbstractTransformation supports , but even we had a thought that this would cause issue in 7.5 but with no change these are working fine.

Below i have provided you a sample java mapping which went live last week , this is just simply reading a PDf and converting it into Base64:

package bsp;


import com.sap.aii.mapping.api.*; // Basic stream handling

import java.io.*;

import java.util.Arrays;

import java.util.Map;

import com.sap.aii.utilxi.base64.api.*;

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

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

public class MapBinaryToHexStream implements StreamTransformation {

BufferedReader docInput;

  String inputLine = "";

  String finalOutput = "";

  StringBuffer inputData = new StringBuffer();

  StringBuffer outputData = new StringBuffer();

  StringBuffer sb = new StringBuffer();

  private String digits = "0123456789ABCDEF";

  int c; 

    byte[] buffer = new byte[4096];

  public void execute(InputStream inputStream, OutputStream outputStream)

  throws StreamTransformationException {

  try {

  docInput = new BufferedReader(new InputStreamReader(inputStream));

  } catch (Exception e) {

  throw new StreamTransformationException(

  "Unable to parse input document - ".concat(e.getMessage()));

  }

  try {

  sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");

  sb.append("<MT_NoteProxy>\r\n");

  sb.append("<File>\r\n");

  String temp="";

  while ((temp = docInput.readLine()) != null) {

  String encodedString = Base64.encode(temp.getBytes());

  System.out.println(encodedString.replaceAll("=","").trim());

  sb.append(encodedString.replaceAll("=","").trim());

  }

  sb.append("</File>");

  sb.append("<FileName>TEST</FileName>");

  sb.append("</MT_NoteProxy>");

  finalOutput = sb.toString();

  System.out.println(finalOutput);

  outputStream.write(finalOutput.getBytes());

  } catch (IOException e) {

  System.out.println(e.getMessage());

  }

  }

  Public static void main(String[] args) {

  try {

  FileInputStream fin = new FileInputStream(

  "C:/My Folder/Java/test.pdf");

  FileOutputStream fout = new FileOutputStream(

  "C:/My Folder/Java/test.xml");

  MapBinaryToHexStream rsc = new MapBinaryToHexStream();

  rsc.execute(fin, fout);

  fin.close();

  fout.close();

  } catch (Exception e) {

  e.printStackTrace();

  }

  } //

  public void setParameter(Map arg0) {

  // TODO Auto-generated method stub

  }

}


when the Java mapping is configured in the Operational Mapping, the result payload is empty (0 bytes long). For test reason we have removed the Java mapping, then the result payload is there (for sure without the necessary manipulation).

is this happening with just one  mapping or all ? try to just recompile the same java mapping with 1.8 and test ( this is not actually required )

I am currently on : NW750EXT_03_REL

Br,

Manoj


former_member182412
Active Contributor
0 Kudos

Hi Helmut,

I can also confirm StreamTransformation still works, i just tested in development and it is working. Mine is PI 7.4 SP09.

Regards,

Praveen.

iaki_vila
Active Contributor
0 Kudos

Hi Praveen,

You are right in SAP doumentation mentioned that:


Note

You can still use the previous Java mapping API (see: Java Mapping API (SAP NetWeaver 2004 und 7.0) ).

Managing Services in the Enterprise Services Repository - SAP Library

I think Helmut the issue could be for example that you would need to compile your classes with the java version that your new PI and to take care about the restrictions (Runtime Environment (Java Mappings) - Managing Services in the Enterprise Services Repository - SAP ...)

Regards.