cancel
Showing results for 
Search instead for 
Did you mean: 

Java Map for writing the file

Former Member
0 Kudos

Hello Experts,

I have a scenarion where i have two XSLT transformation.

Now what I need is I need to store the output of transformation one in File System and also send it to transformation 2 as input.

Again i have to write the output of transformation 2 on the file system and also send to the intended reciver.

Here I want to use Java map In between these two XSLT maps that write the file on the file system. and send the output to the next xslt also.

Please help if u can provide me some code.

Thanks and Regards

Hemant

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Gupta,

When defining an interface mapping in XI/PI, I think it is possible to create a mapping stack so you can create multiple mapping steps (src_msg -> XSL1 -> XSL2 -> ... -> tgt_msg), have you tried to use this feature ? I also remember SAP not recommending file system access during mapping (same for multi threading) ...

Rgds

Chris

Former Member
0 Kudos

Hello Pankaj,

In the below code I have

FileInputStream fin = new FileInputStream(args[0]);

FileOutputStream fout = new FileOutputStream(args[1]);

JMByPass mapping = new JMByPass();

//mapping.setParameter(mapOfMap);

mapping.execute(fin, fout);

commented the line " //mapping.setParameter(mapOfMap);" because this is giving some error. Can you plese let me know wat this line does.

Thanks and Regards

Hemant

former_member181985
Active Contributor
0 Kudos

That line is not required. I used that while i am simulating in standalone mode.

so comment or remove that line.

Any other issue r u facing?

former_member181985
Active Contributor
0 Kudos

> I have a scenarion where i have two XSLT transformation.

> Now what I need is I need to store the output of transformation one in File System and also send it to transformation 2 as input.

> Again i have to write the output of transformation 2 on the file system and also send to the intended reciver.

>

> Here I want to use Java map In between these two XSLT maps that write the file on the file system. and send the output to the next xslt also.

In each XSLT mapping set dynamic configuration for the FileName. (We can set Dynamic ASMA's in XSLT mapping. Fix the file name in each XSLT mapping say TRANSFORMATION1.xml, TRANSFORMATION2.xml etc..in XSLT1, XSLT2 mappings respectively)

write a generic java mapping program which can read an input stream and then can write it to a file system (read the file name set previously from XSLT using dynamic configuration and then get current XI system time step and append it to FileName) and at the same time it will by pass the input stream to output stream which will be used for the next XSLT mapping.

So the sequence should be like this,

1. XSLT1 Mapping (which does some transformation and it has to put some static file name say TRANSFORMATION1.xml in the dynamic configuration header "FileName")

2. Generic Java Mapping (which Does a bypass and it will write the stream to a file system by reading FileName from Dynamic configuration which was previously set in XSLT1 mapping. Of course, it has to use a time stamp to be appended to the FileName to prevent file over writing and loosing Transformed data.)

3. XSLT2 Mapping (which does some transformation and it has to put some static file name say TRANSFORMATION2.xml in the dynamic configuration header "FileName")

4. Same Generic Java Mapping (which Does a bypass and it will write the stream to a file system by reading FileName from Dynamic configuration which was previously set in XSLT2 mapping. Of course, it has to use a time stamp to be appended to the FileName to prevent file over writing and loosing Transformed data.)

So, one generic java mapping is enough and we can re use it.

Let us know if you need any further inputs............:)

Regards,

- Gujjeti.

former_member181985
Active Contributor
0 Kudos

Generic Java Code Snippet

import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.*;
import java.io.*;
import java.util.*;
import java.util.Map;

public class JMByPass implements StreamTransformation
{
	static final int BUFFER = 1024*1000;
    private Map param;
    public JMByPass(){  }
	public void setParameter (Map map)
	{
		param = map;
		if (param == null)
		{
			param = new HashMap();
		}
	}
	public static void main(String args[])
	{
		try
		{
			FileInputStream fin = new FileInputStream(args[0]);
			FileOutputStream fout = new FileOutputStream(args[1]);
			JMByPass mapping = new JMByPass();
			mapping.setParameter(mapOfMap);
			mapping.execute(fin, fout);
		}
		catch (Exception e)
			{
				e.printStackTrace();
			}
	}
    public void execute(InputStream inputstream, OutputStream outputstream)
    {
		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();}
    }
}

Former Member
0 Kudos

Thanks Praveen for your great Help.

Can you provide me how to set dynamic file name in our XSLT map.

Thanks and Regards

Hemant

former_member181985
Active Contributor
0 Kudos

Hi Hemanth,

Hmm.......a little search on SDN would have helped you.

Check this link

[http://help.sap.com/saphelp_nw04/helpdata/en/43/03fe1bdc7821ade10000000a1553f6/frameset.htm|http://help.sap.com/saphelp_nw04/helpdata/en/43/03fe1bdc7821ade10000000a1553f6/frameset.htm]

Embed the below XSLT code in each of your XSLTs. I used "XSLTTransformation1.xml" file name for the first XSLT. Likewise use "XSLTTransformation2.xml" for the second XSLT etc.........

<?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, 'XSLTTransformation1.xml')" /> 
  
</xsl:template>

</xsl:stylesheet>

Regards,

Praveen Gujjeti.

udo_martens
Active Contributor
0 Kudos

Hi Hemant,

you can have that much easier with PI standards:

customize two receivers for your first step:

1. File adapter without conversion

2. Http receiver PI-Host:PI Port/sap/xi/adapter_plain plus a query string determining a new message signature: ?service=<myService>&interface=<myInterface>&namespace=<MyNs>&QOS=EO

Now create the second step, execute the second mapping and customize two receivers: the file receiver and your "real" receiver.

Regards,

Udo

Former Member
0 Kudos

Hello Udo,

I also want to store the intermediate transformation output also.

Thanks and Regards

Hemant

udo_martens
Active Contributor
0 Kudos

Yes, i explained that in my answer. You just need to read it

Former Member
0 Kudos

Thank Udo,

Can you explain this in detail.

Thanks and Regards

Hemant

udo_martens
Active Contributor
0 Kudos

Hi Hemant,

that was detailed

create a message executing your first xslt:


real sender -> XSLT -> file receiver
                    -> http receiver

The http receiver is a http receiver adapter, but you type in the http address of your PI system:

<host>:<port>/sap/xi/plain/<query-string>

Plz find the explaination for the query string [here|http://help.sap.com/saphelp_nw2004s/helpdata/en/43/64db4daf9f30b4e10000000a11466f/content.htm].

Now create a second message with the sender signature used in the http adapter:


virtual sender -> XSLT -> file receiver
                        -> real receiver

Now you have two messages, each saving the result of the XSLT. If you have further question exept "plz elaborate" dont hesitate to ask your specific questions.

Regards,

Udo

Former Member
0 Kudos

Hello Udo,

Thanks for your help.

Sorry to disturb you again.

This approach is really good.

I wnt to store the incoming payload also before the actual XSLT transformation occurs.

Also if there are 3 XSLT transformation we need around 5 adapters for this approach.

And we have to configure more then 100 scenario.

So reusabilty will not come in this...for every scenario we have to configure lots of adapter, dummy interfaces etc.

The one approach I think first is to write java code in XSLT map to write the file on file system but I donot know how to do the same.

SO I went for Java Mapping. So that we can use this Java map in each scenario to write the file on file system.

Can you suggest me what will be the optimal solution for this.

If you think Java map is gud solution can you provide me some code.

Thanks and Regards

Hemant

former_member200962
Active Contributor
0 Kudos
Now what I need is I need to store the output of transformation one in File System and also send it to transformation 2 as input.
Again i have to write the output of transformation 2 on the file system and also send to the intended reciver.

My first thought on achieving this would be through a BPM....not sure if this will be an optimal solution but if you intend to use a BPM then get back....will be happy to provide the solution

Regards,

Abhishek.

Former Member
0 Kudos

Hello,

Thanks for ur help.

Actually I have to make lots of interface and every interface contains the 2 or more XSLT transformation.

So i have to store the payload of intermediate stages also and final output in the file system.

So going for BPM is not suggested by SAP, thats why I am going for Java Map.

Thanks and Regards

Hemant