Quantcast
Channel: SCN : All Content - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 7030

Chinese Character Handling in Java Mapping -SAP PI7.1

$
0
0

HI Folks,

 

I have a requirement where my inputxml  is containing chinese characters. But after transformation it gives special characters/junk values.

Any Idea How to achieve this . Have gone through lot of SDN blogs but couldnt able to fine concrete response.

 

 

 

Below is my code

==============

 

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.InputPayload;

import com.sap.aii.mapping.api.OutputPayload;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.Reader;

import java.util.Map;

 

public class GetSessionData

  extends AbstractTransformation

{

  String prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ins=\"http://soap.sforce.com/schemas/class/XYZKHT\" xmlns:sap=\"http://soap.sforce.com/schemas/class/JFUJHHJ\"><soapenv:Header> <ins:SessionHeader><ins:sessionId> ";

  String suffix = "</ins:sessionId> </ins:SessionHeader> </soapenv:Header> <soapenv:Body>";

  String envelope = "</soapenv:Body> </soapenv:Envelope>";

  private Map map;

 

  public void setParameter(Map param)

  {

    this.map = param;

  }

 

  public void transform(TransformationInput arg0, TransformationOutput arg1)

    throws StreamTransformationException

  {

    String xmldata = convertStreamToString(arg0.getInputPayload().getInputStream());

   

 

 

    String sessionId = xmldata.substring(xmldata.indexOf("<ns1:sessionId>"),xmldata.indexOf("</ns1:sessionId>"));

 

 

    sessionId = sessionId.substring(sessionId.indexOf(">") + 1, sessionId.length());

 

    xmldata = xmldata.substring(0, xmldata.indexOf("<ns1:sessionId>")) + xmldata.substring (xmldata.indexOf("<ns1:XYZZ>"),xmldata.length());

   

 

 

    int len = xmldata.indexOf(">");

   

    String newpayload = xmldata.substring(len + 1);

   

    //newpayload = xmldata.substring(len + 1);

   

 

 

    String outData = this.prefix + sessionId + this.suffix + newpayload + this.envelope;

    try

    {

      arg1.getOutputPayload().getOutputStream().write(

        outData.getBytes("UTF-8"));

    }

    catch (Exception localException) {}

  }

 

  public String convertStreamToString(InputStream in)

  {

 

 

    StringBuffer sb = new StringBuffer();

    try

    {

    

      InputStreamReader isr = new InputStreamReader(in,"UTF8");

      Reader reader = new BufferedReader(isr);

      int ch;

      while ((ch = in.read()) > -1)

      {

        sb.append((char)ch);

      }

      reader.close();

    }

    catch (Exception localException)

    {

    }

    return sb.toString();

  }

}

 

 

Please help us in reading chinese character from xml and writing it in the same format.

 

Thanks

Rohit


Viewing all articles
Browse latest Browse all 7030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>