cancel
Showing results for 
Search instead for 
Did you mean: 

How to Handle Special Characters in PI7.1

sriram_devarapalli
Participant
0 Kudos

Hi Team,

I need to handle some special characters like <,>,& etc.. from WS Adapter to CRM in PI 7.1.

http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/9420 [original link is broken]

By using the above blog i had implemented the Java Code as

public void execute(InputStream in, OutputStream out){

try{

int read_data;

while((read_data = in.read()) != -1){

if (read_data == '&'){

out.write("&amp;".getBytes());

}else if (read_data == '>'){

out.write("&gt;".getBytes());

}else if (read_data == '<'){

out.write("&lt;".getBytes());

}else if (read_data == '/'){

out.write("&frasl;".getBytes());

}else if (read_data == '\''){

out.write("&apos;".getBytes());

}

else { out.write(read_data);

}

}

out.flush();

} catch (Exception e){}

}

I had added this class file in Operational Mapping.

It is working if we have only one IF condition for & in while

Any suggestion

Thanks

Sriram

Accepted Solutions (0)

Answers (2)

Answers (2)

stefan_grube
Active Contributor
0 Kudos

> I need to handle some special characters like <,>,& etc.. from WS Adapter to CRM in PI 7.1.

Could you describe the issue that you have?

When you change < and >, then the result is non-XML.

sriram_devarapalli
Participant
0 Kudos

Hi Ramesh,

Thanks for your inputs, I have tried your code but it is not working. The error message stays the same.

Dear Stephane,

To describe the error more, the requirement is the payload coming from source through WS Adapter consists of the special characters <, > , & which are basic sematics of XML syntax. I need PI to process this payload with special characters and successfully transfer it to target CRM system. I have created the Java class with code (ref: Blog 9420) as stated earlier and added this class to my existing Operation Mapping. I am expecting the java mapping to replace the special characters in payload like < with "&gt;" . So as the case with the other characters >,&,'

After activaton of my operation mapping, I triggered the test message with Soap UI client and I could able to get a successful mapping only When I put the logic for &ampersand symbol only. However when I am trying to add the logic for > or < or ' the mapping is failing . I am using UTF-8 encoding across the source and PI enviroments.

Sample SOAP message :


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:abcabca.com">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:MT_ABCDEFG_Req>
	<activity>
		<id/>
		<type>ZEMA</type>
		<actionType>C</actionType>
		<firewall>10000003</firewall>
		<subject>small &gt; &lt; attachment test</subject>
		<location/>
		<startDate>2010-07-08T10:53:31.000Z</startDate>
		<endDate>2010-07-08T10:53:31.000Z</endDate>
		<mainClient>1000319</mainClient>
		<mainContact>1000003</mainContact>
		<isConfidential>false</isConfidential>
		<summary/>
		<fullText>test body  - small.txt</fullText>
		<owner>1000021</owner>
		<from>ABCDEDF</from>
		<sendTo>emailaddress</sendTo>
		<copyTo/>
		<keywords/>
		<referenceId/>
		<createdBy>1000021</createdBy>
		<additionalContacts/>
		<additionalClients/>
		<additionalParticipants/>
		<status>A0008</status>
		<attachments>
			<fileUrl>20100708110053-XXXXXXXXX</fileUrl>
			<fileName>small.txt</fileName>
		</attachments>
		<attachments>
			<fileUrl>20100708110053-XXXXXXXXX</fileUrl>
			<fileName>EMail 2010-07-08.pdf</fileName>
		</attachments>
	</activity>
      </urn:MT_ABCDEFG_Req>
   </soapenv:Body>
</soapenv:Envelope>

Output on the SOAP UI client for the above request:


<!--see the documentation-->
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP:Body>
      <SOAP:Fault>
         <faultcode>SOAP:Server</faultcode>
         <faultstring>Server Error</faultstring>
         <detail>
            <s:SystemError xmlns:s="http://sap.com/xi/WebService/xi2.0">
               <context>XIAdapter</context>
               <code>ADAPTER.JAVA_EXCEPTION</code>
               <text>com.sap.engine.interfaces.messaging.api.exception.MessagingException: com.sap.engine.interfaces.messaging.api.exception.MessagingException: XIServer:NO_MAPPINGPROGRAM_FOUND:
	at com.sap.aii.adapter.soap.ejb.XISOAPAdapterBean.process(XISOAPAdapterBean.java:1160)
	at sun.reflect.GeneratedMethodAccessor342.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal(
.............

What do you think where I am doing the wrong?

Sriram

stefan_grube
Active Contributor
0 Kudos

> To describe the error more, the requirement is the payload coming from source through WS Adapter consists of the special characters <, > , & which are basic sematics of XML syntax. I need PI to process this payload with special characters and successfully transfer it to target CRM system. I have created the Java class with code (ref: Blog 9420) as stated earlier and added this class to my existing Operation Mapping. I am expecting the java mapping to replace the special characters in payload like < with "&gt;" . So as the case with the other characters >,&,'

>

That will not work. You cannot change < to &amp;lt; without corrupting the whole XML document.

Fix the issue in the sender application

Edited by: Stefan Grube on Jul 27, 2010 1:38 PM

sriram_devarapalli
Participant
0 Kudos

Thank You Stefan.

If it is not possible to replace the > with &gt; of the payload, can you suggest how can this problem be resolved using PI.

Even if the fix is to be done at sender application what should be the payload format that we can ask the send application to send? I mean how should the < and > symbols of the payload to be sent by the sender application.

Regards,

Sriram

stefan_grube
Active Contributor
0 Kudos

> I mean how should the < and > symbols of the payload to be sent by the sender application.

It should be &amp;lt; and &amp;gt;

See this document; it is an official document, so no one can deny the validity:

http://www.w3.org/TR/2006/REC-xml11-20060816/#syntax

" The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, ... If they are needed (...), they MUST be escaped using either numeric character references or the strings "&amp;amp;" and "&amp;lt;" respectively. The right angle bracket (>) may be represented using the string "&amp;gt;", "

Edited by: Stefan Grube on Jul 27, 2010 2:03 PM

Former Member
0 Kudos

Hi Sriram,

Try this code

public void execute(InputStream in, OutputStream out) {

try {

int read_data;

while ((read_data = in.read())!=-1)

{

if (read_data != '&' || read_data != '>' || read_data != '<')

out.write(read_data);

else if(read_data.equals("&"))

out.write("&".getBytes());

else if(read_data.equals("<"))

out.write("<".getBytes());

else if(read_data.equals(">"))

out.write(">".getBytes());

}

out.flush();

} catch (Exception e) {

}

Regards

Ramesh