cancel
Showing results for 
Search instead for 
Did you mean: 

File Content Conversion: Remove reserved characters from Content

mkral
Explorer
0 Kudos

Hi PI Gurus,

we're facing a little problem with FCC in File Receiver Adapter. Sometimes the defined fieldSeparator ("|") comes within the field content.

e.g.

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Positions xmlns:ns0="http://test.com">
<Position>
<Value1>001</Value1>
<Value2>Test|Content</Value2>
</Position>
</ns0:Positions>

So, my first thought was to replace all "|" with a litte java mapping beind the actual mapping.

But, is there any possibility to achieve this via configuration of FCC (something like fieldSeperatorSubstitution)?

Help is as always highly appreciated!

Cheers,

Matthias Kral

Accepted Solutions (1)

Accepted Solutions (1)

deepak_shah
Contributor
0 Kudos

Hi,

You can achive this in your message mapping. No need for java mapping.

For that field you can use Replace string function available under function category "Text"

You can replace '|' with blank space.

In example below i will replace | with a hypen -.

replaceString(/ns0:Source_MT/Field1 const(value=|), const(value=-)

Regards,

Deepak.

Edited by: Deepak Shah on Feb 8, 2011 12:24 PM

mkral
Explorer
0 Kudos

Thank you guys for your ideas. But I need the solution for several messages and various fields. Putting an UDF into each mapping association would be much effort.

On the other hand, a global Java Mapping as shown below will lead into an OutOfMemoryError very quick. (In my local NWDS with messages > 20 MB)

Here's my approach for Java Mapping (just for completeness):

public void execute(InputStream in, OutputStream out)
		throws StreamTransformationException {
		try {
			String output = new String(getBytes(in)).replace('|', ' ');
			out.write(output.getBytes());
		} catch (IOException e) {
			throw new StreamTransformationException(e.getMessage());
		}

	}

deepak_shah
Contributor
0 Kudos

Hi,

I think you can use replace string function for various fields. As it is standard function it will not lead to any performance issue as well.

I dont think there will be any problem to use standard function in place of customised java code.

regards,

deepak.

Former Member
0 Kudos

It is recommended to use Standard Replacestring function that will not lead to any performance issues. But, if we go with Java mapping contexts need to be handled properly and might be memory issues.

I suggest to go with Graphical message mapping.

Thanks,

Answers (3)

Answers (3)

mkral
Explorer
0 Kudos

Hello Hareenkumar,

yes you're totally right. I ran in several OutOfMemoryError while testing the code above. The errors started with messages over 15 MB.

Here's the code, that is productive now. It replaces all Pipes "|" by Slashes "|" and really works fine and performant.


public void execute(InputStream in, OutputStream out)
		throws StreamTransformationException {
		try {
			int totalCount = 0;
		byte[] buf = new byte[40960];
		int count = 0;
			while (count >= 0) {
				count = in.read(buf);
				totalCount += count;

				if (count > 0) {
					for (int i=0; i<count; i++){
						if (buf<i>==124){
							buf<i> = 47;
						}
					}
					out.write(buf, 0, count);
				}
			}

		} catch (IOException e) {
			throw new StreamTransformationException(e.getMessage());
		}
	}

Thank you all again!!!

Cheers Matthias

Former Member
0 Kudos

Hi,

Use Replacestring function: replaces each occurance of a pattern of source string by third string.

Length: returns length of the string

First argument: is the input text,

Second argument: is the text needs to be replaced.

Third argument: the text to be replaced with the second argument.

Thanks,

Former Member
0 Kudos

Hi Matthias,

Check if the field value is passed with '|', to handle this we need to replace the character from it using UDF. After this, the adapter will do the content conversion.

Thanks,