Skip to Content
0
Former Member
Jul 31, 2008 at 10:59 AM

Problem to get whole payload?

24 Views

Hi Guys,

I need to call JDBC adapter so that I need to send the complete source XML payload as a string in just one element and not mapping each element with input variables of the store procedure.

So i developed the java mapping like this

import java.io.*;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.parsers.SAXParser;

import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.DefaultHandler;

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

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

public class Create_JDBC_Structure

extends DefaultHandler

implements StreamTransformation {

public void setParameter(Map map) {

}

public void execute(InputStream iStream, OutputStream oStream)

throws StreamTransformationException {

// TODO Auto-generated method stub

this.out = oStream;

try {

DefaultHandler handler = this;

SAXParserFactory factory =

SAXParserFactory.newInstance();

SAXParser saxParser = factory.newSAXParser();

saxParser.parse(iStream, handler);

} catch (Exception e) {

e.printStackTrace();

}

}

}

public void startDocument() throws SAXException {

// TODO Auto-generated method stub

strbfr_FirstFields.append("<Statement>");

strbfr_FirstFields.append("<ref_bod_put action=\"\">");

strbfr_FirstFields.append("<table></table>");

strbfr_FirstFields.append("<param1 type=\"\"></param1>");

strbfr_FirstFields.append("<param2 type=\"\"></param2>");

strbfr_FirstFields.append("<param3 type=\"\"></param3>");

strbfr_FirstFields.append("<param4 type=\"\"></param4>");

strbfr_FirstFields.append("<param5 type=\"\"></param5>");

strbfr_FirstFields.append("<param6 type=\"\"></param6>");

strbfr_FirstFields.append("<param7 type=\"\"></param7>");

strbfr_FirstFields.append("<param8>");

}

public void startElement(

String namespaceURI,

String localName,

String qName,

Attributes atts)

throws SAXException {

ifNewRec = true;

}

if (ifNewRec) {

if (!(qName.equals("Records"))) {

strbfr_LastField.append("&lt;");

strbfr_LastField.append(qName);

if (qName.equals("SITELEVEL")) {

strbfr_LastField.append(" " +

atts.getQName(0) + "=");

strbfr_LastField.append(atts.getValue(0));

}

if (qName.equals("DATETIME")) {

strbfr_LastField.append(" " +

atts.getQName(0) + "=");

strbfr_LastField.append(atts.getValue(0));

}

if (qName.equals("AMOUNT")) {

strbfr_LastField.append(" " +

atts.getQName(0) + "=");

strbfr_LastField.append(atts.getValue(0));

}

if (qName.equals("DATE_TIME")) {

strbfr_LastField.append(" " +

atts.getQName(0) + "=");

strbfr_LastField.append(atts.getValue(0));

}

if (qName.equals("AMOUNT1")) {

strbfr_LastField.append(" " +

atts.getQName(0) + "=");

strbfr_LastField.append(atts.getValue(0));

}

if (qName.equals("OPERAMT")) {

strbfr_LastField.append(" " +

atts.getQName(0) + "=");

strbfr_LastField.append(atts.getValue(0));

}

if (qName.equals("QUANTITY")) {

strbfr_LastField.append(" " +

atts.getQName(0) + "=");

strbfr_LastField.append(atts.getValue(0));

}

if (qName.equals("CCA_GLACCT")) {

strbfr_LastField.append(" " +

atts.getQName(0) + "=");

strbfr_LastField.append(atts.getValue(0));

}

strbfr_LastField.append("&gt;");

} else {

//

strbfr_LastField.append("&lt;!DOCTYPE SYNC_ITEM_005&gt;");

//

strbfr_LastField.append("&lt;");

//

strbfr_LastField.append("SYNC_ITEM_005");

//

strbfr_LastField.append("&gt;");

}

}

}

public void characters(char[] arg0, int arg1, int arg2)

throws SAXException {

if (ifNewRec) {

strbfr_LastField.append(data);

}

}

public void endElement(String namespaceURI, String localName, String

qName)

throws SAXException {

// echoText();

if (ifNewRec) {

if (!(qName.equals("Records"))) {

strbfr_LastField.append("&lt;/");

strbfr_LastField.append(qName);

strbfr_LastField.append("&gt;");

} else {

//

strbfr_LastField.append("&lt;/");

//

strbfr_LastField.append("SYNC_ITEM_005");

//

strbfr_LastField.append("&gt;");

}

}

if (qName.equals("Records")) {

strbfr_LastField.append("</param8>");

strbfr_LastField.append("</ref_bod_put>");

strbfr_LastField.append("</Statement>");

ifNewRec = false;

}

}

public void endDocument() throws SAXException {

// TODO Auto-generated method stub

outputxml.append("<?xml version=\"1.0\"

encoding=\"UTF-8\"?>");

outputxml.append(

"<ns0:JDBC_MT

xmlns:ns0=\"http://ccamatil.com/amatil_c_ccaml/ptp/\">");

outputxml.append(strbfr_LastField.toString());

outputxml.append("</ns0:JDBC_MT>");

print(outputxml.toString());

}

private void print(String str) {

try {

out.write(str.getBytes());

out.flush();

out.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (NullPointerException e) {

e.printStackTrace();

}

}

String data = null;

private OutputStream out;

private StringBuffer outputxml = new StringBuffer();

///////////////////////////

private boolean ifNewRec = false;

private int int_No_Rec;

private StringBuffer strbfr_LastField = new StringBuffer();

private StringBuffer strbfr_FirstFields = new StringBuffer();

private Hashtable ht = new Hashtable();

////////////////////////////

}

so what are the changes i have to make to get whole payload as a sting

Thans In advance.

Rishi