cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to send attachments from Sourcing W9 to PI web service

Former Member
0 Kudos

Hi,

We have a requirement to extract some details of Suppliers, including an extension Attachment field and pass these values to PI/PO. There is a SOAP web service at PI/PO side. I am able to send test data to this web service from an independent java program. The same logic is deployed in Sourcing as custom JAR. I have written a prepublish script in Sourcing. If the attachment is not passed, I am able to get a successful response from the web service. But when I try to pass the attachment, the message send itself fails.

I am using javax,xml.soap.SOAPMessage class to create the request. The web service is in SOAP 1.1

This is the code in my custom jar for processing attachment:

               File attch = vendorData.getW9Attach(); 

                FileDataSource fds = new FileDataSource(attch.getName());

                DataHandler dh = new DataHandler(fds);

                AttachmentPart attachment = message.createAttachmentPart();

                attachment.setDataHandler(dh);

               attachment.setContentId(attachFileName);

               message.addAttachmentPart(attachment);

Without this code to add attachment, I get a successful response. When I add the above code, I get the error message:

com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to internalize message

The stackTrace is:

com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:148), com.*****.custom.WebClientForVendorPublish.getResponseForVendorData(WebClientForVendorPublish.java:375), sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method), sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39), sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25), java.lang.reflect.Method.invoke(Method.java:597), bsh.Reflect.invokeOnMethod(Unknown Source), bsh.Reflect.invokeObjectMethod(Unknown Source), bsh.Name.invokeMethod(Unknown Source), bsh.BSHMethodInvocation.eval(Unknown Source), bsh.BSHPrimaryExpression.eval(Unknown Source), bsh.BSHPrimaryExpression.eval(Unknown Source), bsh.BSHBlock.evalBlock(Unknown Source), bsh.BSHBlock.eval(Unknown Source), bsh.BSHBlock.eval(Unknown Source), bsh.BSHTryStatement.eval(Unknown Source), bsh.Interpreter.eval(Unknown Source), bsh.Interpreter.eval(Unknown Source), bsh.Interpreter.eval(Unknown Source), com.sap.odp.comp.scripting.ScriptEnvironment.execute(ScriptEnvironment.java:144), com.sap.odp.comp.scripting.ScriptManager.executeDocumentEventScript(ScriptManager.java:1009), com.sap.odp.doc.ContainerBo.executeDocumentEventScript(ContainerBo.java:5722), com.sap.odp.doc.ContainerBo.prePublishERP(ContainerBo.java:6018), com.sap.odp.doccommon.masterdata.VendorHome.publishToERP(VendorHome.java:753), com.sap.eso.doccommon.doc.rq.IntegrationPublishRQ.processRequestHook(IntegrationPublishRQ.java:110), com.sap.odp.doc.display.util.AbsDocRQ.processRequest(AbsDocRQ.java:199), com.sap.odp.doc.display.util.AbsRQ.run(AbsRQ.java:110), java.lang.Thread.run(Thread.java)


If anyone has successfully used SOAP 1.1 with attachment from Sourcing, please help

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I tried out different suggestions given in various java forums and finally made it work by including the following changes:

1. Removed calls to message.saveChanges() throughout my custom JAR code, following the advice on this thread - http://www.coderanch.com/t/446725/Web-Services/java/SAAJ-SOAP-incompatibility-Java

SAP Sourcing W9 uses Java 6 (u33) and the above change resulted in an update in error message!

2. Downloaded the latest SAAJ implementation jar (saaj-impl-1.3.19.jar), deployed it as a custom jar in Sourcing and added this line in my script:

System.setProperty("javax.xml.soap.MessageFactory","com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl");

This tip is from https://community.oracle.com/thread/1628376?start=0

3. I was using a FileDataSource object to read the attachment file and creating DataHandler from this FileDataSource Updated the code to use a java.net.URL

    URL fileUrl = attachmentFile.toURL();

     DataHandler dh = new DataHandler(fileUrl);

     AttachmentPart attachment = message.createAttachmentPart(dh);

4. Removed the setContentId method. Somehow Sourcing was not liking the fact that I am setting a Content-Id header for my attachment!

A combination of all the above 4 steps is required to make attachment sending via web service work from sourcing.

Answers (0)