Java mapping of application triggered an exception
Hi,
We have ascenario where a vendor will be sending us a cXML file which has the second line as <!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.009/InvoiceDetail.dtd">. If I open it in XMLSpy, it is saying the file as invalid. XI is unable to map this file. So we decided to remove that line using Java mapping and then do the regular graphical mapping.
I took the java code from the SAP note 812966 and used the aii_map_api.jar, dom.jar, jaxp-api.jar to create the class of that java file and used that class file by importing that into XI as a jar file.
I'm getting this error in the request message mapping of SXMB_MONI
<SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
<SAP:Category>Application</SAP:Category>
<SAP:Code area="MAPPING">STREAM_TRANSFORMATION_EX</SAP:Code>
<SAP:P1>mypackage/DeleteDTDDeclarationWithDOM</SAP:P1>
<SAP:P2>Failed to load resource from the context classloa~</SAP:P2>
<SAP:P3 />
<SAP:P4 />
<SAP:AdditionalText />
<SAP:ApplicationFaultMessage namespace="" />
<SAP:Stack>Java mapping of application triggered an exception</SAP:Stack>
<SAP:Retry>M</SAP:Retry>
</SAP:Error>
I'm new to this java mapping, Can you please provide me some details about what files need to be loaded into the XI along with the class file.
Appreciate you help.
Thanks,
MT.
Hi Prateek,
Thanks for your quick reply. Yes I have downloaded the aii_map_api.jar from <SAP_install_dir>/<system_name>/<instance_name>/j2ee/cluster/server<number>/apps/sap.com/com.sap.xi.services/
And also I have compiled my java code using the dom.jar, sax.jar, jaxp-api.jar and aii_map_api.jar.
I took the class file of my javacode and all the class files of the above mentioned jar files and prepared one single jar file, which I imported into XI.
It is not allowing me to make a single jar of the actual class file and all the supporting jar files.
What is the actual method of doing it.
Appreciate all your help. Thanks very much.
Thanks,
Maulik.
Similar Messages
-
JAVA Mapping with SAX: Illegal character exception &
Hi everybody,
I use a SAX JAVA Mapping. It throws an error cause the xml that is parsed has a
&
like in
<D_3036>Company & Co. KG</D_3036>
Does anybody know how to solve the problem?
I do not want to replace the
&
Are there special settings/properties for the handler/parser?
Thanks
Regards
MarioHi all,
thanks for your comments and suggestions. The error was not cause by the problem I describes.
FYI:
If there is an ampersand in the middle of a string, than the standard method
characters
in the handler is called three times!
This let me asume the ampersand was the error.
Regards Mario
Edited by: Mario Müller on Dec 19, 2008 1:23 AM -
Java mapping how to use com.sap.tc.logging
Hi I would like to know how to use logging within a java mapping.
I know i have to use theese classes : Location, Category, ConsoleLog but i dont know how.
1) How to load the P1, P2, P3 and P4 tags in the Error tag of the SOAP header watched in SXMB_MONI
- <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
<SAP:Category>Application</SAP:Category>
<SAP:Code area="MAPPING">STREAM_TRANSFORMATION_EX</SAP:Code>
<SAP:P1>SwissMedical/Interfaces/IFI002/LiquidacionMapping~</SAP:P1>
<SAP:P2 />
<SAP:P3 />
<SAP:P4 />
<SAP:AdditionalText />
<SAP:ApplicationFaultMessage namespace="" />
<SAP:Stack>Java mapping of application triggered an exception</SAP:Stack>
<SAP:Retry>M</SAP:Retry>
</SAP:Error>
2) How to load and activate log in the DIAGNOSTIC tag of the SOAP Header.
- <SAP:Diagnostic xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
<SAP:TraceLevel>Information</SAP:TraceLevel>
<SAP:Logging>Off</SAP:Logging>
</SAP:Diagnostic>
Thanks!!As already suggested, you can display custom messages using AbstractTrace.
trace = (AbstractTrace)param.get( StreamTransformationConstants.MAPPING_TRACE );
trace.addInfo("G1-CYCLE is missing");
For more on coding front refer:
http://help.sap.com/javadocs/NW04/current/pi/com/sap/aii/mapping/api/StreamTransformation.html
To get this trace seen in MONI, set parameter TRACE_LEVEL in SXMB_ADM to 2. -
XI AF API call failed. Module exception: Java Mapping
Hi Experts,
I have faced a typical error for one of my interface. The Scenario is SOAP to SOAP and we are performing SOAP Lookup before sending the data to Target web service. We are using one Java Mapping 'FileIns_lookupLoad.java --- com/fi/' and performing the SOAP Lookup from within the code. In the Lookup Communication channel we are using 'Axis' as message protocol and passing couple of values through Module Key parameters. We have same ESR and ID objects in Development, Quality and Production (as per Version ID and History).
Now the problem is Lookup is failing only in Development but Quality and Production is working fine. I have replaced Quality CC URL with the development WSDL URL, but that worked fine. That means Development Web Service is good. We are getting the below error in Dev:
<SAP:Stack>StreamTransformationException triggered by application mapping program com/fi/FileIns_lookupLoad; Look Up Failed</SAP:Stack>
Trace : *
<Trace level="1"
type="T"> Some Thing Wrong in LookUpError when calling an adapter by using the communication channel CC_IN_SOAP_GEInsuranceLoadLookup1 (Party: , Service: BusService_GE, Object ID: 4214805c52893ef9b0b3f0ef0902fe9e) XI AF API call failed. Module exception: 'while trying to invoke the method org.apache.axis.types.URI.toString() of an object returned from com.sap.xi.XI.Message._30.QualifiedName.getNamespace()'. Cause Exception: 'while trying to invoke the method org.apache.axis.types.URI.toString() of an object returned from com.sap.xi.XI.Message._30.QualifiedName.getNamespace()'. </Trace>
<Trace level="1" type="T">*** END APPLICATION TRACE ***</Trace>
<Trace level="1" type="T">Java mapping com/fi/FileIns_lookupLoad has thrown a StreamTransformationException. Thrown: com.sap.aii.mapping.api.StreamTransformationException: Look Up Failed at com.fi.FileIns_lookupLoad.execute(FileIns_lookupLoad.java:282) at com.fi.FileIns_lookupLoad.transform(FileIns_lookupLoad.java:74) at com.sap.aii.ib.server.mapping.execution.JavaMapping.executeStep(JavaMapping.java:92) at com.sap.aii.ib.server.mapping.execution.Mapping.execute(Mapping.java:60) at com.sap.aii.ib.server.mapping.execution.SequenceMapping.executeStep.................................................
................................................................................<Trace level="1" type="T">Application mapping program com/fi/FileIns_lookupLoad throws a stream transformation exception: Look Up Failed Thrown: com.sap.aii.ib.core.mapping.execution.ApplicationException: Application mapping program com/fi/FileIns_lookupLoad throws a stream transformation exception: Look Up Failed at com.sap.aii.ib.server.mapping.execution.JavaMapping.executeStep(JavaMapping.java:95) at com.sap.aii.ib.server.mapping.execution.Mapping.execute(Mapping.java:60) at com.sap.aii.ib.server.mapping.execution.SequenceMapping.executeStep(SequenceMapping.java:40) at com.sap.aii.ib.server.mapping.execution.Mapping.execute
I have already checked with Basis and as per them JDK and Java versions are identical in Dev, QAS and Prod. It seems something is wrong with 'XI AF API' which we are calling from the channel. If we totally ignore Lookup process and send direct data, it is working fine. Target CC is also using Axis.
Sequence in CC: afreq ->xireq ->wssec2 ->xires ->afres
For any more information please let me know.
Thanks,
Nabendu.Hi Anupam,
The Java Mapping code is same in Dev , QAS and Prod. Also the versions of the JAR is same.
Please find the code below.
package com.fi;
import java.util.HashMap;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.MappingTrace;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.*;
import org.w3c.dom.views.AbstractView;
import org.xml.sax.SAXException;
import java.io.ByteArrayInputStream;
import com.sap.aii.mapping.lookup.*;
/*import com.sap.aii.utilxi.hmis.server.HmisEnvironment.Accessor;
//import com.sap.aii.utilxi.lock.api.LockServiceException;
//import com.pmintl.pppimes.RFCLookup.javamapping.*;
//import java.io.FileInputStream;
//import java.io.FileOutputStream;*/
import java.text.DateFormat;
import java.text.SimpleDateFormat;
//import java.text.ParseException;
import java.util.Date;
import java.io.*;
public class FileIns_lookupLoad extends AbstractTransformation{
private Map param = null;
private AbstractTrace trace = getTrace();
String senderService = null;
String inParamChannel = null;
String inParamBusService = null;
//3. Each JAVA Mapping using program 7.1 API must implement the method
// transform(TransformationInput in, TransformationOutput out)
// as oppose to execute Method in earlier version.
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
// TODO Auto-generated method stub
//4. An info message is added to trace. An instance of trace of object is obtained by calling
// the getTrace method of class AbstractTransformation
inParamChannel = arg0.getInputParameters().getString("COMM_CHANNEL");
inParamBusService = arg0.getInputParameters().getString("BUS_SERVICE");
getTrace().addInfo("Input Parameter: " + inParamChannel);
getTrace().addInfo("Input Parameter: " + inParamBusService);
this.execute(arg0.getInputPayload().getInputStream(),
arg1.getOutputPayload().getOutputStream());
//5. Input payload is obtained by using arg0.getInputPayload().getInputStream()
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
// TODO Auto-generated method stub
try
//Get The Trace
// trace = (AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE );
trace = getTrace();
getTrace().addInfo("Java Mapping Started");
DocumentBuilderFactory ifactory = DocumentBuilderFactory.newInstance();
DocumentBuilder ibuilder = ifactory.newDocumentBuilder();
Document IDoc = ibuilder.parse(in);
Document TDoc = ibuilder.newDocument();
String mrnVal = "";
trace.addInfo("Preparing Target Doc");
Element message = TDoc.createElementNS("urn:Medtronic.com:CATS_Patient_Transactions","n1:Mt_Insurance");
Node tRoot = TDoc.appendChild(message);
//trace.addInfo(tRoot.getNodeName());
Element sRoot = (Element)IDoc.getFirstChild();
//trace.addInfo(sRoot.getNodeName());
NodeList nl = sRoot.getChildNodes();
// trace.addInfo("Len"+nl.getLength());
//// for(int i=0;i<nl.getLength();i++)
// Node n1 = TDoc.importNode(nl.item(i), true);
// trace.addInfo("Adding Child Nodes");
// trace.addInfo(nl.item(i).getNodeName());
// tRoot.appendChild(n1);
NodeList lmrn = sRoot.getElementsByTagName("Mrn");
if(lmrn != null)
Node n1 = TDoc.importNode(lmrn.item(0), true);
Element e1 = (Element)lmrn.item(0);
//trace.addInfo(e1.getNodeName());
mrnVal = e1.getTextContent();
tRoot.appendChild(n1);
NodeList lfsc = sRoot.getElementsByTagName("Fsc");
if(lfsc != null)
for(int i=0;i<lfsc.getLength();i++){
Element n1=TDoc.createElement(lfsc.item(i).getNodeName());
tRoot.appendChild(n1);
Node fieldch = TDoc.createElement("Fields");
n1.appendChild(fieldch);
NodeList chl = lfsc.item(i).getChildNodes();
trace.addInfo("len11"+chl.getLength());
for(int j=0;j<chl.getLength();j++){
if(!chl.item(j).getNodeName().equals("FscNumber")&&!chl.item(j).getNodeName().equals("Priority")){
if(chl.item(j).hasChildNodes()){
trace.addInfo(chl.item(j).getNodeName());
Element fscfield = TDoc.createElement("FSCField");
fieldch.appendChild(fscfield);
NodeList FUQl = chl.item(j).getChildNodes();
for(int p =0;p<FUQl.getLength();p++){
//trace.addInfo(" i: "+i+" J: "+j+" P: "+p);
if(FUQl.item(p).getNodeName().equals("FUQNumber")){
//Node tFUQ = TDoc.createElement("FUQNumber");
//tFUQ.setTextContent(FUQl.item(p).getTextContent());
fscfield.setAttribute("FUQNumber", FUQl.item(p).getTextContent());
if(FUQl.item(p).getNodeName().equals("Value")){
Node tVal = TDoc.createElement("Value");
tVal.setTextContent(FUQl.item(p).getTextContent());
fscfield.appendChild(tVal);
//Node tName = TDoc.createElement("Field");
//tName.setTextContent(chl.item(j).getNodeName());
fscfield.setAttribute("Field", chl.item(j).getNodeName());
// Node fuqch = chl.item(j).getFirstChild();
// Node valch = fuqch.getNextSibling();
// if(fuqch!=null){
// Node tFUQ = TDoc.createElement("FUQNumber");
// tFUQ.setTextContent(fuqch.getTextContent());
// fscfield.appendChild(tFUQ);
// if(valch!=null){
// Node tVal = TDoc.createElement("Value");
// tVal.setTextContent(valch.getTextContent());
// fscfield.appendChild(tVal);
// Node tName = TDoc.createElement("Filed");
// tName.setTextContent(chl.item(j).getNodeName());
// fscfield.appendChild(tName);
else{
//Node numch =TDoc.importNode(chl.item(j), true);
//Element e1 =(Element)n1;
if(chl.item(j).getNodeName().equals("FscNumber")){
n1.setAttribute("Number", chl.item(j).getTextContent());
if(chl.item(j).getNodeName().equals("Priority")){
n1.setAttribute("Priority", chl.item(j).getTextContent());
//tRoot.appendChild(lfsc.item(0));
// Element e1 = (Element)lfsc.item(0);
// trace.addInfo(e1.getNodeName());
// mrnVal = e1.getNodeValue();
/////Start of Look Up Code////
//Preparing Input String
String lookUpRequest = "<LoadPatientFullInsuranceDetail><Mrn>"+mrnVal+"</Mrn></LoadPatientFullInsuranceDetail>";
trace.addInfo("Request");
trace.addInfo(lookUpRequest);
SystemAccessor acc;
Channel channel;
Payload lookupResult;
try
channel = LookupService.getChannel(inParamBusService, inParamChannel);
trace.addInfo("Got the channel");
acc = LookupService.getSystemAccessor(channel);
trace.addInfo("Got The Channel and Accessor");
InputStream ist = new ByteArrayInputStream(lookUpRequest.getBytes());
XmlPayload payload = LookupService.getXmlPayload(ist);
if(acc != null){
trace.addInfo("Got The Channel and Accessor");
trace.addInfo("Executing The Webservice");
lookupResult = acc.call(payload);
trace.addInfo("End of Executing The Webservice");
trace.addInfo(lookupResult.toString());
if(lookUpRequest!=null){
trace.addInfo("Responce is not null");
InputStream rist = lookupResult.getContent();
Document lresDoc = ibuilder.parse(rist);
Node n1 = lresDoc.getFirstChild();
trace.addInfo(n1.getNodeName());
if(n1.getNodeName().endsWith("LoadPatientFullInsuranceDetailResponse"))
Node ch1 = n1.getFirstChild();
trace.addInfo(ch1.getNodeName());
NodeList lookupnl = ch1.getChildNodes();
//trace.add
for(int i=0;i<lookupnl.getLength();i++)
Node n2 = TDoc.importNode(lookupnl.item(i), true);
trace.addInfo("Adding Child Nodes");
trace.addInfo(lookupnl.item(i).getNodeName());
tRoot.appendChild(n2);
else{
throw new StreamTransformationException("Error in Look Up"+n1.getTextContent());
//while(ch1.hasChildNodes() && !ch1.getNodeName().equals("FSCS")){
else{
trace.addWarning("Responce is null");
throw new LookupException();
catch(LookupException le)
trace.addWarning("Some Thing Wrong in LookUp"+le.getMessage());
throw new StreamTransformationException("Look Up Failed");
Transformer transformer = TransformerFactory.newInstance().newTransformer();
// StreamResult reqResult = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(TDoc);
Result result = new StreamResult(out);
transformer.transform(source,result);
catch(StreamTransformationException ste)
throw new StreamTransformationException(ste.getMessage());
catch(Exception e){
trace.addInfo(e.getMessage());
finally{ -
Generic Exception in java mapping
hi all,
i'm using xerces api inorder to validate the outbound xml with its corresponding xsd using java mapping . when mapping is executed , i get "Generic Exception". it does'nt leave any trace other than the word "Generic Exception". i use same jdk version used by XI.kindly help me regarding this issue.
Thanks and Regards
kausikhello kausik,
i have the same problem in java mapping by validating incoming xml files.
could you solve the problem?
can you tell me how to solve the problem?
you can write me an email with the solution ([email protected])? or post it here?
thanks a lot
ciao alex -
hi All,
I'm trying to validate the incoming XML against a given XSD using Java Mapping.. When i execute it i get the following error in the Mapping...
com.sap.engine.lib.xml.util.NestedException -> com.sap.engine.lib.xml.parser.ParserException -> java.io.IOException: Parsing an empty source. Root element expected!
Please do help me out..... I have given my java Code Below.....
Note:The XSD is attached in the same zip file which contains java class and the zip file is imported in the Imported ARchive Area....
package cts.com.XSD;
import java.io.*;
import java.util.Map;
import com.sap.aii.mapping.api.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
public class TestJavaMapping implements StreamTransformation
Map param=null;
public void setParameter(Map arg0)
this.param=arg0;
public void execute(InputStream in, OutputStream out) throws StreamTransformationException
byte b[];
byte b1[];
try
b = new byte[in.available()];
in.read(b);
AbstractTrace trace=(AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);
InputStream Schemainput= new
TestJavaMapping().getClass().getClassLoader().getResourceAsStream("cts/com/XSD/ShipmentDetails.xsd");
b1 = new byte[Schemainput.available()];
Schemainput.read(b1);
String XsdString =new String(b1);
trace.addInfo("XSD obtained");
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
docBuilderFactory.setValidating(true);
trace.addInfo("After Setting True");
docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage","http://www.w3.org/2001/XMLSchema");
docBuilderFactory.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaSource",XsdString);
trace.addInfo("After Setting ATtribute");
trace.addInfo("B4 Parsing");
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document validDoc = docBuilder.parse(in);
trace.addInfo("After Parsing");
out.write(b);
catch(Exception e)
AbstractTrace trace=(AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo(e.getMessage());Hi Thorsten,
Thanks for the Suggestion of using SAX instead of DOM... i even tried using SAX parser i get "Generic Exception"..i have give the code below.. please do help me out..
package cts.com.XSD;
import java.util.Map;
import java.io.*;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import org.w3c.dom.Document;
public class TestJavaMapping implements StreamTransformation
Map param=null;
public void setParameter(Map arg0)
this.param=arg0;
public void execute(InputStream in, OutputStream out) throws StreamTransformationException
try
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware( true);
factory.setValidating( true);
InputStream Schemainput = new
TestJavaMapping().getClass().getClassLoader().getResourceAsStream("cts/com/XSD/ShipmentDetails.xsd");
SAXParser parser = factory.newSAXParser();
parser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
parser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource",Schemainput);
byte b[]=new byte[in.available()];
in.read(b);
XMLReader reader = parser.getXMLReader();
reader.parse(new String(b));
out.write(b);
catch ( ParserConfigurationException e)
AbstractTrace trace=(AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo(e.getMessage());
catch ( SAXException e)
AbstractTrace trace=(AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo(e.getMessage());
catch ( IOException e)
AbstractTrace trace=(AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo(e.getMessage());
catch(Exception e)
AbstractTrace trace=(AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo(e.getMessage()); -
Null exception in Java mapping
Hi Experts,
I am getting "Exception in thread "main" java.lang.NoClassDefFoundError: com/sap/aii/utilxi/misc/api/BaseRuntimeException
in line Container container = new Context(new FunctionWrapper(0)); " when trying to execute the java mapping inside my interface mapping.
I am using the following code iside my java class in NWDS when I get the above error:
//Get the message Header
Container container = new Context(new FunctionWrapper(0));
map = container.getTransformationParameters();
strMessageID = (String) map.get("MessageId"); // Get Message GUID
strMessageID = strMessageID.trim();
strMessageDate = (String) map.get("TimeSent");
strMessageTime = (String) map.get("TimeSent"); // Get Time Sent
I have also imported aii_mt_rt.jar, aii_map_api.jar, aii_utilxi_misc.jar into my class.
Please can you help me solve this problem.
Thanks and regards,
BrendonI solved the problem by using
strMessageID = (String)param.get(
StreamTransformationConstants.MESSAGE_ID); -
Exception while perfroming Java mapping in XI
Hi there,
Im doing some java mapping in XI using the standard/classic DOM and JAXP packages, I have tested everything outside XI and the code seems to be OK.
However when I deploy the code into XI self and run a test, something goes wrong.
This is the exception Im getting from my log (PS: In th eyes of XI eveything goes fine, but this is because I have all my code surrounded by try/catch statements...):
<b>java.lang.ClassCastException: com.inqmy.lib.xml.dom.DocumentImpl</b>
1) First, what I dont understand here is the fact that Im not doing any kind of parsing to this type "com.inqmy.lib.xml.dom.DocumentImpl" in my code, so Why XI is doing this?
2) It seems to me like XI internally uses this "fancy" INQMY package to perform my XML parsing/mapping. But nowhere in the documentation is mentioned, at least I haven't read about it.
3) Is there anyplace where I can find/download this package "com.inqmy.lib.xml.dom.*" so that I can test/debug my code using this specific SAP pacakge?
Can anyone give me some clues how to solve and prevent this issue? Below is the part of the code where the exception is generated:
private void processMultiMessages(Vector indexVector, NodeList msgList) {
Iterator iter = indexVector.iterator();
Integer tempIndex = null;
int index = 0;
try {
for (int i = 0; i < indexVector.size(); i++) {
tempIndex = (Integer) indexVector.elementAt(i);
index = tempIndex.intValue();
Range range = ((DocumentRange) mainDocument).createRange();
range.setStartBefore(msgList.item(index));
if ((i + 1) > (indexVector.size() - 1)) {
index = msgList.getLength() - 1;
range.setEndAfter(msgList.item(index));
} else {
tempIndex = (Integer) indexVector.elementAt(i + 1);
index = tempIndex.intValue();
range.setEndAfter(msgList.item(--index));
createNewMsg(range.cloneContents());
range.detach();
getSystemParams().put("STATUS", "OK");
getSystemParams().put("TOTAL_MSG", new Integer(indexVector.size()));
getSystemParams().put(
"STATUS_MSG",
"Target directory on XI Server: " + folder);
this.out.write(
new LogDocument().createDocument(getSystemParams()).getBytes());
} catch (Exception e) {
getSystemParams().put("STATUS", "FAIL");
getSystemParams().put("TOTAL_MSG", new Integer(indexVector.size()));
getSystemParams().put(
"STATUS_MSG",
"** Exception in Java Mapping: " + e.toString() +" ** System error: " + System.err);
try {
this.out.write(
new LogDocument()
.createDocument(getSystemParams())
.getBytes());
e.printStackTrace();
} catch (IOException ioE) {
ioE.printStackTrace();Hi there,
I have included the inqmyxml.jar in my classpath and perfor
med some tests (outside XI), with good results.
However, when I copy/deploy the same classes into XI then the problem still there. My Java class is complaining about some ClassCastException, the error looks like this:
java.lang.ClassCastException: com.inqmy.lib.xml.dom.DocumentImpl
has anyone any ideas/clues was happening here?
Cheers,
Rob.
PS: These are the packages Im importing in my class:
import com.sap.aii.mapping.api.*;
<i>import java.io.*;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.w3c.dom.*;
import org.w3c.dom.ranges.*;
import com.inqmy.lib.jaxp.*;
import com.inqmy.lib.xml.*;
import com.inqmy.lib.xml.parser.*;
import com.inqmy.lib.xml.dom.*;</i>
And these are the Global vars Im using:
<i> // declare Global vars
private Map systemParams;
private InputStream in;
private OutputStream out;
private DocumentBuilderFactory domFactory;
private DocumentBuilder documentBuilder;
private Document mainDocument;
private String path;
private String separator;
private File folder;</i>
And finally this is the way I start my mapping/parsing process:
<i> ClassLoader cl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
domFactory = DocumentBuilderFactoryImpl.newInstance();
Thread.currentThread().setContextClassLoader(cl);
// Optional: set various configuration options
domFactory.setIgnoringComments(true);
domFactory.setIgnoringElementContentWhitespace(true);
domFactory.setValidating(false);
domFactory.setCoalescing(false);
// Create and set documentBuilder
documentBuilder = domFactory.newDocumentBuilder();
// parse the input file
mainDocument = documentBuilder.parse(in);
</i> -
Throw exception in Java mapping and handle this in BPM
Hi,
I'll use a Java mapping in a BPM transform step. Is it possible to throw an exception inside this Java mapping and handle this in a BPM exception handler?
thanks and regards
VerenaHi Verena,
In a BPM transformation step, I think you can throw exceptions only for system errors.
Let me explain with an example, one of the ways to handle your scenario:
Lets assume your Java Mapping fails then you can trap that exception in your Java mapping and compose an XML message which indicates that an error has occurred.
say for e.g.
<intermediateStructure>
<SatusDocument>
<StatusCode>ERROR</StatusCode>
<ErrCode>123</ErrCode>
<ErrDesc><!populate the thrown exception details></ErrDesc>
</StatusDocument>
<Payload>
<!contains actual XML message with data>
</Payload>
</intermediateStructure>
if Java mapping is Successful, you can compose the XML message as follows:
<intermediateStructure>
<SatusDocument>
<StatusCode>SUCCESS</StatusCode>
<ErrCode>0</ErrCode>
<ErrDesc></ErrDesc>
</StatusDocument>
<Payload>
<!contains actual XML message with data>
</Payload>
</intermediateStructure>
You can use BPM switch operation to switch to different processing branches say for e.g. "error" branch or "success" branch by examining the value of <StatusCode> tag.
Hope it helps !
Regards,
Sridhar -
Handling Java Mapping Exception in BPM Transformation step
Dear SDN members,
I have developed a File to File scenario using BPM as follows.
Step 1:
Sender file adapter picks the file from FTP server and using file content conversion mapped to XML structure.
Step 2:
BPM will recieve the XML payload , immediately in the block a transformation step is called with an interface mapping. In the interface mapping a Java mapping will be executed with certain data validations on the XML payload. If found any invalid data is there a suitable excptions will be raised . Here the transformation step should be catch the error and control should be sent to exception block to place the recived file as a error file.
else if the transformation is executed with out any issues, the file will be placed in success folder.
But in the transformation step, though java mapping thorwing exceptions, the control not going into exception block, instead it is continuing to next step i.e the file is placing in the success folder.
Can anybody tell me, how to handle the exceptions raised in java mapping in the BPM transformation step?
I have refered all the SDN blogs, forums related to this issue, but could not able to find the answer. Please help me?
Thanks & Regards
Vijayanand PoreddyHi Abhishek,
Once the file is picked from FTP server then sent to BPM,
the BPM steps
Step1:
-->Recive
Step 2:
Block Starts
---Block Start: New Transaction
---Block End : New Transaction
---Exception : Error
Step 3
Inside the Block
Transformation Step
--Interface Mapping: <IM Name>
-- Check box ticked for Create New Transcation
-- Exceptions
--System Error: Error
--Source Message: Message recieved in Recieve Step (Step 1)
Step 4:
--Send
--Source Maessage: Output message from the Transformation Step
Block End
Inserted a Exception Branch for Block
Steps inside Exception Branch
-Control
--Throw Alert
--Alert Name
In the above scenario
The transformation step is not throwing error even my interface mapping going to error. The same transformation step if i place outside the block next to recieve step, then the transformation step is throwing error and BPM stops the process.
Also, when transformation is inside the block, i have used the exception handling on the send step inside the block. here it is throwing error as the source message payload is empty. because in the preceding transformation step the interface mapping is failed due to which there the target will not be filled. But even though it is not entered into exception block.
Regards
Vijayanand Poreddy -
Call method execute of the application Java mapping
Hi,
I'm using a RFC Lookup in a Java Mapping. In PI 7.0 it was working fine. Now we use the Mapping in our PI 7.30 Testsystem and I get following LookupException:
Error when calling an adapter by using the communication channel CC_Receiver_RFC_XXXXX (Party: , Service: BS_ERP_XXX_400, Object ID: 445eef339f2039b0856093c54c3656dd) The channel with object ID 445eef339f2039b0856093c54c3656dd could not be found in the Integration Server Java Cache. Check if the channel exists in the Integration Builder Directory and execute a refresh of the Java Cache
The Channel name and Business Service Name are correct. If I look in the Integration Builder, my Communication Channel is working fine.
I did a complete restart, the error afterwards was all the same. How can I refresh the cache for the ID's?.
I checked the party name it's having the space value not with *.
Thanks
Naresh N
Edited by: Naresh Nelapatla on Feb 25, 2012 5:46 AMHello,
Error when calling an adapter by using the communication channel CC_Receiver_RFC_XXXXX (Party: , Service: BS_ERP_XXX_400, Object ID: 445eef339f2039b0856093c54c3656dd) The channel with object ID 445eef339f2039b0856093c54c3656dd could not be found in the Integration Server Java Cache. Check if the channel exists in the Integration Builder Directory and execute a refresh of the Java Cache
This error usually happens when you have created the RFC Receiver that has an entry of * in the Party. What you can do is to recreate the CC and remove the entry in the party. Save and activate.
Hope this helps,
Mark -
PI Java Mapping NullPointerException
Hi Gurus,
I'm having some troubles doing the mapping through java mapping in PI.
I've done the java class in the SAP NWDS and imported it on PI through the ESR.
Now i'm trying to test through the SOAP and i've found the following error in the "Communication Channel Monitor":
500 Internal Server Error SAP NetWeaver Application Server/Java AS
java.lang.NullPointerException: while trying to invoke the method com.sap.aii.af.sdk.xi.lang.Binary.getBytes() of a null object returned from com.sap.aii.af.sdk.xi.mo.xmb.XMBPayload.getContent()
And the following error in the SXMB_MONI:
<SAP:Category>XIServer</SAP:Category>
<SAP:Code area="INTERNAL">CLIENT_SEND_FAILED</SAP:Code>
<SAP:P1>500</SAP:P1>
<SAP:P2>Internal Server Error</SAP:P2>
<SAP:P3>(See attachment HTMLError for details)</SAP:P3>
<SAP:P4 />
<SAP:AdditionalText />
<SAP:Stack>Error while sending by HTTP (error code: 500 , error text: Internal Server Error) (See attachment HTMLError for details)</SAP:Stack>
I've developed the code below:
public class PI_Mapping_IF extends AbstractTransformation {
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
this.execute(in.getInputPayload().getInputStream(), out.getOutputPayload().getOutputStream());
public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
try
// Inicio do java mapping
getTrace().addInfo("JAVA Mapping Iniciado"); //Log para o PI/XI
// Declarações referentes ao XML de entrada
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document xml_in = db.parse(in);
// Declarações referentes ao XML de saída
Document xml_out = db.newDocument();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
// Remove o standalone
xml_in.setXmlStandalone(true);
// Declara a estrutura que a RFC irá receber
Element root = xml_out.createElement("ns1:ZFSD_VMOI_UPLOAD_CF_PG");
root.setAttribute("xmlns:ns1","urn:sap-com:document:sap:rfc:functions");
xml_out.appendChild(root);
Element i_cenario = xml_out.createElement("I_CENARIO");
root.appendChild(i_cenario);
Element t_input = xml_out.createElement("T_INPUT");
root.appendChild(t_input);
Element item = xml_out.createElement("ITEM");
t_input.appendChild(item);
Element STRING = xml_out.createElement("STRING");
item.appendChild(STRING);
Element t_return = xml_out.createElement("T_RETURN");
root.appendChild(t_return);
Element item_r = xml_out.createElement("ITEM");
t_return.appendChild(item_r);
Element message = xml_out.createElement("MESSAGE");
item_r.appendChild(message);
// Verifica se existe algum filho no nó
NodeList nodos = xml_in.getChildNodes();
if (nodos.item(0) != null)
getTrace().addInfo("O nó(XML) possui filhos"); //Log para o PI/XI
// Declaração de variáveis
String ident = ""; // <Ident>
String buyer = ""; // <BuyerLineItemNum>
String result = ""; // <Ident>;<BuyerLineItemNum>;<Date>;<QuantityValue>
// Inicia a extração das informações do XML
try{
// Recupera o nó ShipToParty
NodeList nodeShip = xml_in.getElementsByTagName("ns0:ShipToParty");
Node node = nodeShip.item(0);
Element elemXML = (Element) node;
try{
NodeList nodeIdent = elemXML.getElementsByTagName("ns0:Ident");
Element nameElement = (Element) nodeIdent.item(0);
nodeIdent = nameElement.getChildNodes();
// Recupera o valor da chave <Ident>
ident = PI_Mapping_IF.VerifyNull(((Node) nodeIdent.item(0)).getNodeValue());
}catch(Exception e){
result += "0.0;";
// Recupera o nó ListOfMaterialGroupedPlanningDetail
NodeList nodeBuyer = xml_in.getElementsByTagName("ns0:MaterialGroupedPlanningDetail");
for (int i = 0; i < nodeBuyer.getLength(); i++) {
node = nodeBuyer.item(i);
elemXML = (Element) node;
try{
// Preenche a chave BuyerLineItemNum
NodeList nodeBuyerLine = elemXML.getElementsByTagName("ns0:BuyerLineItemNum");
Element elemBuyerLine = (Element) nodeBuyerLine.item(0);
nodeBuyerLine = elemBuyerLine.getChildNodes();
buyer = PI_Mapping_IF.VerifyNull(((Node) nodeBuyerLine.item(0)).getNodeValue());
}catch(Exception e){
buyer += "0;";
result = ident+";"+buyer+";";
Node nodeDt_Qnt = nodeBuyer.item(i);
Element elemDt_Qnt = (Element)nodeDt_Qnt;
NodeList nodeValores = elemDt_Qnt.getElementsByTagName("ns0:ScheduleDetail");
for (int j = 0; j < nodeValores.getLength(); j++) {
node = nodeValores.item(j);
elemXML = (Element) node;
try{
// Preenche a chave Date
NodeList modelExtra = elemXML.getElementsByTagName("ns0:Date");
Element extraElement = (Element) modelExtra.item(0);
modelExtra = extraElement.getChildNodes();
result += PI_Mapping_IF.VerifyNull(((Node) modelExtra.item(0)).getNodeValue())+";";
}catch(Exception e){
result += "//;";
try {
// Preenche a chave QuantityValue
NodeList modelURL = elemXML.getElementsByTagName("ns0:QuantityValue");
Element urlElement = (Element) modelURL.item(0);
modelURL = urlElement.getChildNodes();
result += PI_Mapping_IF.VerifyNull(((Node) modelURL.item(0)).getNodeValue())+";";
} catch (Exception e) {
result += "0.0;";
// Marca o final do registro
result += "||";
// Preenche os nós itens
Text srcxml = xml_out.createTextNode(result);
STRING.appendChild(srcxml);
result = "";
buyer = "";
}catch(Exception e){
// Remove o standalone
xml_out.setXmlStandalone(true);
// Preenche o Cenario
Text cenario = xml_out.createTextNode("P&G");
i_cenario.appendChild(cenario);
// Preenche mensagem de retorno
Text msgxml = xml_out.createTextNode("XML lido com sucesso!");
message.appendChild(msgxml);
// Escreve a saida do XML
transformer.transform(new DOMSource(xml_out), new StreamResult(out));
getTrace().addInfo("Fim da execução do Java Mapping");
} catch (ParserConfigurationException e) {
getTrace().addWarning(e.getMessage());
throw new StreamTransformationException("Can not create DocumentBuilder.", e);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
Am i doing anything wrong in the code? Where can this nullpointerexception be triggered?
Thanks.These three xml are the same:
<?xml version="1.0"?><a:xml xmlns:a="urn:123">root</a:xml>
<?xml version="1.0"?><xml xmlns="urn:123">root</xml>
<?xml version="1.0"?><ns0:xml xmlns:ns0="urn:123">root</ns0:xml>
But your code will work only with last one, because it doesn't bound namespace to prefix ns0. -
How to load a java class when application is at first time browsed.
Hi
How can i load a simple java class on application startup.
For servlet it could be done using "load on startup" tag in web.xml
but how could the same be achieved for a simple java class.
ThanksHi
Code is given below....
package com;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Test {
Test()
HttpServletRequest request=null;
HttpServletResponse response=null;
RequestDispatcher requestDispatcher = request.getRequestDispatcher("a.jsp");
try {
requestDispatcher.forward(request,response);
} catch (ServletException e) {
System.out.println("success");
e.printStackTrace();
} catch (IOException e) {
System.out.println("success 1");
e.printStackTrace();
finally
System.out.println("success 2");
System.out.println("success 3");
}Web.xml :
<servlet>
<servlet-name>simple</servlet-name>
<servlet-class>com.Test</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>simple</servlet-name>
<url-pattern>/init.do</url-pattern>
</servlet-mapping>Error Trace :
org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /DispatcherTest threw load() exception
java.lang.IllegalAccessException: Class org.apache.catalina.core.StandardWrapper can not access a member of class com.Test with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
at java.lang.Class.newInstance0(Class.java:344)
at java.lang.Class.newInstance(Class.java:303)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1048)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:925)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3857)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4118)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1069)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1162)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:293)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1304)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1568)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1577)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1557)
at java.lang.Thread.run(Thread.java:595) -
Hi All,
I am getting the below error while executing a JAVA mapping.
<SAP:Category>Application</SAP:Category>
<SAP:Code area="MAPPING">LINKAGE_ERROR</SAP:Code>
<SAP:P1>XMLNSTagCreate1/XMLNSTagCreate1</SAP:P1>
<SAP:P2>java.lang.NoClassDefFoundError: XMLNSTagCreate1/XM</SAP:P2>
<SAP:P3>LNSTagCreate1 (wrong name: XMLNSTagCreate1)</SAP:P3>
<SAP:P4 />
<SAP:AdditionalText />
<SAP:Stack>Linkage error while loading class XMLNSTagCreate1/XMLNSTagCreate1; java.lang.NoClassDefFoundError: XMLNSTagCreate1/XMLNSTagCreate1 (wrong name: XMLNSTagCreate1)</SAP:Stack>
<SAP:Retry>M</SAP:Retry>
I have tried compiling the code in the same JRE as the one in PI. Still it is not working.
Please suggest.
Regards,
Yashwanth
Edited by: YashwanthSVK on Aug 17, 2011 8:38 PMHi all... thank you for the replies.. I have compiled the code in the same version of JRE as the PI version...
Hi Vijay,
I also felt the same but as I do not have much knowledge in JAVA, i could not track it further.
below is the code for the mapping... would you mind if I ask you to have a look at it and let me know where the error is..
thank you so much ...
import java.io.*;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerFactory;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import com.sap.aii.mapping.api.MappingTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.FileWriter;
This mapping creates xmlns attribute to send to Tradeplace
public class XMLNSTagCreate1 extends DefaultHandler implements StreamTransformation {
private Map param;
private MappingTrace trace;
private OutputStream out;
public void execute(InputStream in, OutputStream out)
throws StreamTransformationException {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
try {
//trace.addWarning("Execute function starts here");
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
try {
org.w3c.dom.Document doc = docBuilder.parse(in);
//Node TradeplaceMessage = doc.getFirstChild();
Element trade=(Element) doc.getFirstChild();
if(trade.hasAttribute("tag1"))
NamedNodeMap TradeplaceMessageAttributes = trade.getAttributes();
String xmlnsValue=trade.getAttribute("tag1");
String modeValue=trade.getAttribute("productionMode");
trace.addInfo("XMLNS Value:"+xmlnsValue);
trade.removeAttribute("tag1");
trade.removeAttribute("productionMode");
trade.setAttribute("xmlns",xmlnsValue);
trade.setAttribute("productionMode",modeValue);
javax.xml.transform.Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult result = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
String xmlString = result.getWriter().toString();
//System.out.println(xmlString);
out.write(xmlString.getBytes());
} catch (SAXException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerFactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public static void main2(String[] args) throws Exception {
String xmlFile = "U:
Untitled.xml";
InputStream in = new BufferedInputStream(new FileInputStream(xmlFile));
XMLNSTagCreate1 test = new XMLNSTagCreate1();
//test.countOccurences(in);
public static void main(String[] args) throws Exception {
String xmlFile = "//NA.AD.WHIRLPOOL.COM//myApps//home//NA//qqjos1d//My Documents//TP2.xml";
InputStream in = new BufferedInputStream(new FileInputStream(xmlFile));
FileOutputStream out = new FileOutputStream("//NA.AD.WHIRLPOOL.COM//myApps//home//NA//qqjos1d//My Documents//DhanishTP2.xml");
XMLNSTagCreate1 test = new XMLNSTagCreate1();
test.execute(in, out);
OutputStreamWriter out1 = new OutputStreamWriter(out,"UTF-8");
/* (non-Javadoc)
@see com.sap.aii.mapping.api.StreamTransformation#setParameter(java.util.Map)
public void setParameter(Map param) {
// TODO Auto-generated method stub -
Keystore access in Java Mapping Program - user J2EE_GUEST
Dear Gurus,
I have the following problem:
I need to validate the digital signature of a XML document and I'm using some examples provided by SAP as follows:
InitialContext ctx = ctx = new InitialContext();
Object o = (Object) ctx.lookup("keystore");
KeystoreManager manager = (KeystoreManager) o;
KeyStore ks = manager.getKeystore("Serasa");
{/code}
But I get the error below, saying that user J2EE_GUEST is not authorized. How do I change the user who executes java mapping, because I granted permissions in Visual Admin to another user.
at com.sap.aii.ibrun.sbeans.mapping.MappingServiceObjectImpl0_0.processFunction(MappingServiceObjectImpl0_0.java:131)
at sun.reflect.GeneratedMethodAccessor267.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:62)
at java.lang.reflect.Method.invoke(Method.java:391)
at com.sap.engine.services.ejb.session.stateless_sp5.ObjectStubProxyImpl.invoke(ObjectStubProxyImpl.java:187)
at $Proxy218.processFunction(Unknown Source)
at sun.reflect.GeneratedMethodAccessor266.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:62)
at java.lang.reflect.Method.invoke(Method.java:391)
at com.sap.engine.services.rfcengine.RFCDefaultRequestHandler.call(RFCDefaultRequestHandler.java:284)
at com.sap.engine.services.rfcengine.RFCDefaultRequestHandler.handleRequest(RFCDefaultRequestHandler.java:219)
at com.sap.engine.services.rfcengine.RFCJCOServer$J2EEApplicationRunnable.run(RFCJCOServer.java:254)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(AccessController.java:219)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:104)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:176)
Caused by: com.sap.engine.services.keystore.exceptions.BaseKeystoreException: User is not authorized to execute keystore operation[{GET_VIEW Serasa }]
at com.sap.engine.services.keystore.impl.security.UserBasedSecurityConnector.checkUserPermission(UserBasedSecurityConnector.java:889)
at com.sap.engine.services.keystore.impl.security.SecurityRestrictionsChecker.checkUserPermission(SecurityRestrictionsChecker.java:52)
at com.sap.engine.services.keystore.impl.security.SecurityRestrictionsChecker.isUserAuthorized(SecurityRestrictionsChecker.java:148)
at com.sap.engine.services.keystore.impl.security.SecurityRestrictionsChecker.checkPermission(SecurityRestrictionsChecker.java:174)
at com.sap.engine.services.keystore.impl.ParameterChecker.checkPermission(ParameterChecker.java:35)
at com.sap.engine.services.keystore.impl.KeystoreManagerImpl.checkPermission(KeystoreManagerImpl.java:46)
... 28 more
Caused by: java.security.KeyStoreException: (thread: SAPEngine_Application_Thread[impl:3]_56,view:Serasa, entry: , user: J2EE_GUEST) - checkPermissions 'getView': com.sap.engine.services.security.exceptions.BaseSecurityException: Caller not authorized.
at com.sap.engine.services.keystore.impl.security.UserBasedSecurityConnector.checkFailed(UserBasedSecurityConnector.java:1097)
at com.sap.engine.services.keystore.impl.security.UserBasedSecurityConnector.checkPermissions_getView(UserBasedSecurityConnector.java:773)
at com.sap.engine.services.keystore.impl.security.UserBasedSecurityConnector.checkUserPermission(UserBasedSecurityConnector.java:823)
... 33 more
{/code}
Thank you very muchHi Fabio,
first of all have you checked if standard functions to verify digital signature for pi adpaters would work for you?
We have used the following code to access the Keystore in a custom adapter. It accesses the keystore with the access rights of a JEE application (it has a reference to the sample adapter "sap.com/com.sap.aii.adapter.sample.ra"). Check out if it works in your mapping, too.
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.UnrecoverableKeyException;
import java.util.HashMap;
import java.util.Map;
import javax.resource.ResourceException;
import com.sap.aii.af.service.resource.SAPSecurityResources;
import com.sap.aii.security.lib.KeyStoreManager;
import com.sap.aii.security.lib.PermissionMode;
public class XIKeystoreAccessor {
private static final XITrace TRACE = new XITrace(XIKeystoreAccessor.class.getName());
static XIKeystoreAccessor instance = null;
SAPSecurityResources securityResources;
KeyStoreManager keystoreManager;
Map<String, KeyStore> keystores = null;
private XIKeystoreAccessor() throws ResourceException {
final String SIGNATURE = "XIKeystoreAccessor()";
TRACE.entering(SIGNATURE);
keystores = new HashMap<String, KeyStore>();
securityResources = SAPSecurityResources.getInstance();
try {
keystoreManager = securityResources.getKeyStoreManager(PermissionMode.SYSTEM_LEVEL,
new String[] { "sap.com/com.sap.aii.adapter.sample.ra" });
} catch (KeyStoreException e) {
TRACE.catching(SIGNATURE, e);
throw new ResourceException(e);
TRACE.exiting(SIGNATURE);
* Get a key from AS Java keystore
* @param view
* @param alias
* @param password
* @return
* @throws ResourceException
public Key getPrivateKey(String view, String alias, String password) throws ResourceException {
final String SIGNATURE = "getPrivateKey()";
TRACE.entering(SIGNATURE);
KeyStore keystore = getKeystore(view);
Key privateKey = null;
try {
privateKey = keystore.getKey(alias, password.toCharArray());
if (privateKey == null) {
throw new ResourceException("Key not found. alias=" + alias);
} catch (KeyStoreException e) {
TRACE.catching(SIGNATURE, e);
throw new ResourceException(e);
} catch (NoSuchAlgorithmException e) {
TRACE.catching(SIGNATURE, e);
throw new ResourceException(e);
} catch (UnrecoverableKeyException e) {
TRACE.catching(SIGNATURE, e);
throw new ResourceException(e);
TRACE.exiting(SIGNATURE);
return privateKey;
public PublicKey getPublicKey(String view, String alias) throws ResourceException {
final String SIGNATURE = "getPublicKey()";
TRACE.entering(SIGNATURE);
KeyStore keystore = getKeystore(view);
PublicKey publicKey = null;
try {
publicKey = keystore.getCertificate(alias).getPublicKey();
if (publicKey == null) {
throw new ResourceException("Key not found. alias=" + alias);
} catch (KeyStoreException e) {
TRACE.catching(SIGNATURE, e);
throw new ResourceException(e);
TRACE.exiting(SIGNATURE);
return publicKey;
* Get a keystore i.e. a view from AS Java
* @param view
* @return
* @throws ResourceException
public KeyStore getKeystore(String view) throws ResourceException {
final String SIGNATURE = "getKeystore()";
TRACE.entering(SIGNATURE);
KeyStore keystore;
try {
if (keystores.containsKey(view) == true) {
keystore = keystores.get(view);
} else {
keystore = keystoreManager.getKeyStore(view);
if (keystore == null) {
throw new ResourceException("Keystore not found. view=" + view);
keystores.put(view, keystore);
TRACE.exiting(SIGNATURE);
return keystore;
} catch (KeyStoreException e) {
TRACE.catching(SIGNATURE, e);
throw new ResourceException(e);
static public XIKeystoreAccessor getInstance() throws ResourceException {
if (instance == null) {
instance = new XIKeystoreAccessor();
return instance;
Maybe you are looking for
-
How can i email my pdf files?
hey guys, i am having a problem with my ipad in sending my pdf files in microsoft exchange for work... it deletes all my entry's when i attach it to a emaiil!! so do i have to purchase another adobe app or ehat?
-
My account keeps resetting and my music is deleting itself from my library. Help!
Every time I log into my account it starts everything the way it had at the start of the last thing, I'll open up an application like Firefox and it'll ask if I want to open it like when you have just downloaded it from the internet. All my settings
-
Emails not loading after moving from one Inbox to another
I was having problems with one of my Mail accounts recently (it would randomly not pull in new emails, go offline, not connect to the SMTP server etc.) and on advice create a new one. When this was up and running, I planned on moving the Inbox and Se
-
I'm unable to start Photoshop without holding down Ctrl, Alt, Shift each time I open it. Also Lightroom is now unable to open photos in Photoshop. I'm at a loss as to how to fix this.
-
How can I use the MS Windows Key in Linux
Hello! I'm using KDE 4.3 and want to use the MS Windows Key to open the KDE start menu. I tried to add the Windows Key by pressing as a "KDE Application Launcher" hotkey, but the window key wasn't accepted as a hotkey. Is it possible to add this key