on 12-17-2013 3:51 PM
Hello SAP fellowship,
I've got a problem with my scenario. I'm intending to save a JPG file in a server. The scenario works fine except for one thing. In the end of the execution the file I've got in my server is an XML and not a JPG. I don't know if i'm forgetting some module or what. I've implemented ASMA in order to solve it but it seems it wasn't enought.
Thanks in advance.
Pablo
Dear Pablo,
1) To make the mapping Filename should use a user function (UDF) try to view these post:
http://wiki.scn.sap.com/wiki/pages/viewpage.action?original_fqdn=wiki.sdn.sap.com&pageId=272171407
Example:
2) Then to convert the contents of the tag "Imagen" you have to create a java program that extracts the contents of the Base64Binary image using Java Mapping and write it directly in place of the XML payload.
Try with this:
This help to Read XML File In Java
It may also be useful
http://scn.sap.com/thread/2068827#
Example, The following code works fine:
package javamapping;
import com.sap.aii.mapping.api.*;
import java.io.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import sun.misc.BASE64Decoder;
public class JMDecodeImage extends AbstractTransformation
{
private MappingTrace trace;
public void transform (TransformationInput in, TransformationOutput out)
throws StreamTransformationException
{
trace = getTrace();
byte[] imageByte;
InputStream ins = in.getInputPayload().getInputStream();
try{//Get document XML from input stream.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document docOld = builder.parse(ins);
docOld.getDocumentElement().normalize();
//Get the node List that contains the node "File-Name" and "Image"..
NodeList details = docOld.getChildNodes();
//Get the Text of Node "Image" Item(0).
String data = details.item(0).getChildNodes().item(0).getTextContent();
//Instantiate an object of BASE64Decoder...
BASE64Decoder decoder = new BASE64Decoder();
//Decode the encoded information....
imageByte = decoder.decodeBuffer(data);
//Write Output Pay-load
out.getOutputPayload().getOutputStream().write(imageByte);
}
catch (Exception e) { trace.addWarning(e.getMessage()); }
}
}
Best regards,
Patricio Cabezas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pablo,
How your are sending the JPG image from Proxy? are you sending as attachment?
Please provide more detail about the schenario and error.
regards,
Harish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mark,
I tried to do the "Mapping" as follows, but the problem is that the received file saves it as text.
then I detail the steps performed.
Program "Java Mapping":
import com.sap.aii.mapping.api.*;
import java.io.*;
public class MapBinaryToHexStream extends AbstractTransformation
{
private MappingTrace trace;
private String digits = "0123456789ABCDEF";
public void transform (TransformationInput in, TransformationOutput out)
throws StreamTransformationException
{
// Initialize variables, objects for processing
trace = getTrace();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out.getOutputPayload().getOutputStream()));
StringBuffer sb = new StringBuffer();
int c;
byte[] buffer = new byte[4096];
// Get buffered reader for input stream
InputStream ins = in.getInputPayload().getInputStream();
// Read direct binary file input stream and convert to hex
try {
while(ins.read(buffer) != -1)
{
for(int i = 0; i < buffer.length; i++)
{
c = (int) buffer[i] & 0xff;
char bit1 = digits.charAt(c >> 4);
char bit2 = digits.charAt(c & 0xf);
sb.append(Character.toString(bit1) + Character.toString(bit2));
}
}
}
catch (IOException e) {
trace.addWarning(e.getMessage());
}
// Close XML message stream
try {
bw.write(sb.toString());
bw.close();
}
catch (IOException e) {
trace.addWarning(e.getMessage());
}
}
}
The Result is a File like this : when it should be an image (. JPG or. PDF)
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.