on 07-22-2010 10:46 AM
Dear experts,
I have an XSLT mapping for a message that is sent via a receiver channel to a customer.
The customer wants a certain file name which is put toghether by elements from the XML message.
I have looked at:
The java code and the XSLT work perfectly!
In the line
fos = new FileOutputStream(new File("Fixed_" + new Date().getTime() + ".xml"));
a fixed value, date and time are used for the file name.
But I need some values from the XML message to create my name. But how do I do that? Can I somehow get values from the XML message through that java function or do I have to adapt the XSLT?
Can someone please help me!
Thank you,
Peter
Hi Peter,
you can either replace the "Fixed_" by a XML field value using Java DOM: [Java DOM De- Mystified: Starter Kit|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/8871] [original link is broken] [original link is broken] [original link is broken];
or use a second variable reading a XML element in the receiver adapter to create the file name: [Configuring the Receiver File/FTP Adapter |http://help.sap.com/saphelp_nw2004s/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/content.htm]
Regards,
Udo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Udo, Hello experts,
Now I do have a problem. I am using this XSL file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:map="java:java.util.Map"
xmlns:dyn="java:com.sap.aii.mapping.api.DynamicConfiguration"
xmlns:key="java:com.sap.aii.mapping.api.DynamicConfigurationKey">
<xsl:output indent="no" />
<xsl:param name="inputparam"/>
<xsl:template match="/">
<!-- change dynamic configuration -->
<xsl:variable name="dynamic-conf"
select="map:get($inputparam, 'DynamicConfiguration')" />
<xsl:variable name="dynamic-key"
select="key:create('http://sap.com/xi/XI/System/File', 'FileName')" />
<xsl:variable name="dummy"
select="dyn:put($dynamic-conf, $dynamic-key, 'TOOLDATA_.xml')" />
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
But then the output file is only named "TOOLDATA_.xml". So I assume the XSL is working.
And I am using this Java-file:
package pi_mappings;
import com.sap.aii.mapping.api.*;
import java.io.*;
import java.util.*;
public class SetFileName extends AbstractTransformation
{
static final int BUFFER = 1024*1000;
private Map param;
public SetFileName(){ }
public void setParameter (Map map)
{
param = map;
if (param == null)
{
param = new HashMap();
}
}
public static void main(String args[])
{
try
{
InputStream in = new FileInputStream(args[0]);
OutputStream out = new FileOutputStream(args[1]);
SetFileName sfn = new SetFileName();
//sfn.setParameter(mapOfMap);
sfn.execute(in, out);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void execute(InputStream inputstream, OutputStream outputstream)
throws StreamTransformationException {
try
{
DynamicConfiguration conf = (DynamicConfiguration) param.get("DynamicConfiguration");
DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
int len = 0;
byte buf[] = new byte[BUFFER];
FileOutputStream fos = null;
if (conf != null)
{
fos = new FileOutputStream(new File(conf.get(KEY_FILENAME) + new Date().getTime()) ); //sample only
}
else
fos = new FileOutputStream(new File("Fixed_" + new Date().getTime() + ".xml"));
while ((len = inputstream.read(buf)) > 0)
{
outputstream.write(buf, 0, len);
fos.write(buf, 0, len);
}
fos.close();
}
catch(Exception e){ e.printStackTrace();}
}
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
getTrace().addInfo("JAVA Mapping Called");
this.execute(arg0.getInputPayload().getInputStream(), arg1
.getOutputPayload().getOutputStream());
}
}
Could you please help me find the mistake. I tried to test it locally by changing the main-method but I could not get it to work.
Thank you very much for any ideas!
Best regards,
Peter
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.