on 01-12-2016 9:44 AM
I have a synchronous REST - ECC scenario. I am using REST sender adapter.
In the response message, i am using a java mapping to convert xml to JSON. I am getting this error
does not implement the required interface com.sap.aii.mapping.api.StreamTransformation or does not enhance the class com.sap.aii.mapping.api.AbstractTransformation:
I downloaded a jar file json-org.jar. I used this as imported archive in ESR and added this under operation mapping for response
Hi Midhun,
Can you share the code you wrote?
The error simply means PI is not finding the required standard java mapping classes.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Anupam
I didn't write any code. I just used a jar file that I found online for converting to JSON.
I get it now. I have to use some classes.
I am on single stack PO 7.4 SP 12. which version of NWDS should I use to write code?
Also, I have eclipse in my machine so is it enough if I code in eclipse
Hi Midhun,
Use below java mapping.
import java.io.InputStream;
import java.io.OutputStream;
import org.json.JSONObject;
import org.json.XML;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class XMLToJSONJavaMap extends AbstractTransformation {
@Override
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
throws StreamTransformationException {
InputStream inputStream = transformationInput.getInputPayload().getInputStream();
OutputStream outputStream = transformationOutput.getOutputPayload().getOutputStream();
try {
byte[] buf = new byte[inputStream.available()];
inputStream.read(buf);
JSONObject xmlJsonObj = XML.toJSONObject(new String(buf, "utf-8"));
String jsonPrettyPrintString = xmlJsonObj.toString(4);
byte[] bytes = jsonPrettyPrintString.toString().getBytes("UTF-8");
outputStream.write(bytes);
} catch (Exception e) {
getTrace().addDebugMessage("Exception while writing OutputPayload: IOException", e);
throw new StreamTransformationException(e.toString());
}
}
}
Regards,
Praveen.
Hi Midhun
Having a copy of NWDS is good and I'd definitely recommend using it for your development. However, at >1GB it does take a while to download and it can sometimes be a bit "tricky" to set up correctly.
While you wait for it to download, in the meantime you can check out a "trick" on how you can in order to test out Praveen's code.
Rgds
Eng Swee
Praveen
The code tat you gave me, should I develop it in NWDS and add as a jar under imported archives or should I create it as a mapping in esr in the existing response mapping like how mentioned here. Write java mapping directly in ESR?
If I am importing jar file from NWDS then I caanot import org.json jar to imported archives right?
I have onluy done udfs and not well versed with java mappings..
Hi Praveen
I got this error when I triggered from POSTMAN
Error encountered while executing mapping: com.sap.aii.af.service.mapping.MappingException: Unexpected exception caught while executing mapping: javax.ejb.EJBException: nested exception is: java.lang.RuntimeException: java.lang.Error: Unresolved compilation problems:
The import org.json cannot be resolved
The import org.json cannot be resolved
JSONObject cannot be resolved to a type
XML cannot be resolved
I coded in NWDS.
I have attached screenshot of both
Hi Midhun,
The error is because you havent imported json jar , you have just mentioned import statment in jav mapping.
As praveen mentioned you need to import json jar :
you can download json jar from here :
org.json-20120521.jar - org-json-java - org.json-20120521.jar - org.json.jar for Java from www.json.org - Google Pro…
Once downloaded add into your project in eclipse / nwds then compile the java mapping provided by praven and create a jar for that.
Then finally in ESR under imported archive you need to import json jar and the jar which you created after compiling java mapping.
Br,
Manoj
Hi Midhun,
Why do you need to convert XML to JSON in mapping - why not to utilize standard XML/JSON conversion functionality of a REST adapter?
Regarding an error you get. Library that you imported is a JSON processor, not a valid mapping. So you need to develop your custom mapping program and you may get use of that JSON library in a mapping program if necessary, but you cannot directly refer to JSON library in an operation mapping. In operation mapping, you can only refer to Java classes that extend abstract class com.sap.aii.mapping.api.AbstractTransformation.
Regards,
Vadim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi vadim
I tried the existing conversion, I am getting this error.
I am sending a url in the payload in the response message from ECC.
It gets escaped with a backward slash when I do that.
the REST webservice is getting the mesage like this:
http://host:port/REST/DFT/employee/<number> in the payload will become like this
http:\/\/host:port\/REST\/DFT\/employee\/<number>
This is how the REST channel is doing converison.
I have only two options. 1) to use adapter module to remove back slash from target payload or 2) use java mapping to convert xml to json so that forward slashes in url will not be escaped
Midhun,
Jettison has parameterization to switch on/off escaping of forward slash which can be set through its configuration, but looking in REST adapter, it doesn't look like it implements support of this configuration option currently. So maybe you can raise a suggestion to SAP to implement this.
For PO 7.4, an appropriate NWDS version is 7.31. As for SP level of NWDS, following SAP recommendation, "Install SAP NetWeaver Developer Studio (NWDS) 7.3 EHP1 latest SP to use it as development environment for SAP NetWeaver 7.4 latest SP. If you are using SAP NetWeaver 7.4 SP lower that the latest, please install SAP NetWeaver Developer Studio 7.3 EHP1 with SP version five levels higher than the number of your SAP NetWeaver 7.4 SP." (extract from SAP Note 1791485). In your case, NWDS 7.31 with currently latest SP is applicable.
Yes, you can use pure Eclipse installation for Java mappings development. Having NWDS in place simplifies construction of build path of a Java mapping project (necessary mapping API libraries are already there and can be referenced, no need to download specific JAR files from application server), but if you already have pure Eclipse in place and if you are fine with constructing build path manually, then pure Eclipse is absolutely fine for development of Java mapping programs.
Regards,
Vadim
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.