cancel
Showing results for 
Search instead for 
Did you mean: 

Problems calling SOAP in JAVA program

Former Member
0 Kudos

Hello Experts,

I'm quite new to using SOAP. I just want to ask how to call SOAP in JAVA specifically NetBean. I already created a webservice using the WSDL a created in SAP XI but problem is when I'm trying to invoke the webservice I always get error "401 Unathorized". Is there a way to specify the user name and password when calling the webservice via JAVA code?

Error Message:

Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized

Sample Code:

public class Main {

/**

  • @param args the command line arguments

*/

public static void main(String[] args) throws UnsupportedEncodingException {

ph.co.amkor.atp.ppmodule.synch.ReqCustomerNoDT Req = new ph.co.amkor.atp.ppmodule.synch.ReqCustomerNoDT();

Req.setCompanyCode(" ");

Req.setCustomerNumber("00110");

RespCustDetailsDT cdwsMI = cdwsMI(Req);

System.out.println("Customer :" + cdwsMI.getCustomerNumber());

System.out.println("Name :" + cdwsMI.getName());

System.out.println("Street :" + cdwsMI.getStreet());

System.out.println("Coutnry :" + cdwsMI.getCountry());

System.out.println("City :" + cdwsMI.getCity());

System.out.println("MSG Type :" + cdwsMI.getMessageType());

System.out.println("Message :" + cdwsMI.getReturnMessage());

}

private static RespCustDetailsDT cdwsMI(ph.co.amkor.atp.ppmodule.synch.ReqCustomerNoDT reqCustomerNoMT) {

ph.co.amkor.atp.ppmodule.synch.CDWSMIService service = new ph.co.amkor.atp.ppmodule.synch.CDWSMIService();

ph.co.amkor.atp.ppmodule.synch.CDWSMI port = service.getCDWSMIPort();

return port.cdwsMI(reqCustomerNoMT);

}

}

SAP Netweaver Information

Session Information

Application:

Design: Integration Builder

User:

aafri

Logon Language:

Korean

Server:

atpxisd01_XD1_01

Server Node:

server0

Runtime Environment

Java version:

1.4.2_12

Java vendor:

Sun Microsystems Inc.

Version

Service pack:

12

Release:

NW04S_12_REL

Latest change:

29423

Sync time:

${sync.time}

Regards,

Alfred

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

can you try this

BindingProvider prov = (BindingProvider) port;

        prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "username");
        prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");

Former Member
0 Kudos

Hello John Wu,

Points were given.

The code you gave me worked. Thanks! but now I'm having another error below. It seems that it did not returned anything at all cause cdwsMI object is null.

Error:

Exception in thread "main" java.lang.NullPointerException

at xiwebservice.Main.main(Main.java:31)

Java Result: 1

Line were error happened:

public class Main {

/**

  • @param args the command line arguments

*/

public static void main(String[] args) throws UnsupportedEncodingException {

ph.co.amkor.atp.ppmodule.synch.ReqCustomerNoDT Req = new ph.co.amkor.atp.ppmodule.synch.ReqCustomerNoDT();

Req.setCompanyCode(" ");

Req.setCustomerNumber("00110");

RespCustDetailsDT cdwsMI = cdwsMI(Req);

+System.out.println("Customer :" + cdwsMI.getCustomerNumber());+

System.out.println("Name :" + cdwsMI.getName());

System.out.println("Street :" + cdwsMI.getStreet());

System.out.println("Coutnry :" + cdwsMI.getCountry());

System.out.println("City :" + cdwsMI.getCity());

System.out.println("MSG Type :" + cdwsMI.getMessageType());

System.out.println("Message :" + cdwsMI.getReturnMessage());

}

private static RespCustDetailsDT cdwsMI(ph.co.amkor.atp.ppmodule.synch.ReqCustomerNoDT reqCustomerNoMT) {

ph.co.amkor.atp.ppmodule.synch.CDWSMIService service = new ph.co.amkor.atp.ppmodule.synch.CDWSMIService();

ph.co.amkor.atp.ppmodule.synch.CDWSMI port = service.getCDWSMIPort();

BindingProvider prov = (BindingProvider) port;

prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "aafri");

prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "betanew3");

return port.cdwsMI(reqCustomerNoMT);

}

}

Regards,

Alfred

Former Member
0 Kudos

Hello John Wu,

It was successfully called when I've checked in communication channel monitoring and SXMB_MONI but I only see the request message but no response message. I believe this supposed to return a response since the setup is asynchronous. Alos noticed the the XML message it sent in SXMB_MONI message still has asynchronous stated and not synchronous.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

- <!-- Response

-->

- <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SAP="http://sap.com/xi/XI/Message/30">

- <SOAP:Header>

- <SAP:Main xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsu="http://www.docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" versionMajor="003" versionMinor="000" SOAP:mustUnderstand="1" wsu:Id="wsuid-main-92ABE13F5C59AB7FE10000000A1551F7">

<SAP:MessageClass>ApplicationMessage</SAP:MessageClass>

<SAP:ProcessingMode>asynchronous</SAP:ProcessingMode>

<SAP:MessageId>05259730-C78D-11DF-9256-00144F6987BB</SAP:MessageId>

<SAP:TimeSent>2010-09-24T03:37:13Z</SAP:TimeSent>

+ <SAP:Sender>

Regards,

Alfred

former_member200962
Active Contributor
0 Kudos
but I only see the request message but no response message. I believe this supposed to return a response since the setup 
is asynchronous.

You will get a response only when the setup is SYNCHRONOUS and not Asynchronous.....is your above statement a typo?

What have you selected as Quality of service in the SOAP Channel....it should be Best Effort.

Regards,

Abhishek.

Former Member
0 Kudos

Sorry it was just a typo error. I setup synchronous Message Interface in Integration Builder: Design.

Regards,

Alfred

former_member200962
Active Contributor
0 Kudos
I setup synchronous Message Interface in Integration Builder: Design.

This is fine....but what about the quality of service option in Sender SOAP Channel? Have you set it as Best Effort.

You said that that the request is reaching SAP....now can you confirm for SAP developer that SAP is able to process this request and also to generate the response?

What are you using on the SAP side...PROXY/ RFC? I hope that it is configured to work in SYNC mode.

Regards,

Abhishek.

Former Member
0 Kudos

Hello,

I am using RFC on SAP side specifically BAPI_CUSTOMER_GETDETAIL2. Setup is SOAP -> RFC. I already changed it just recently to Best Effort now I am having error in channel saying "error occured" after "request recieved" logs. Also below is the message returned by JAVA.

Error message in Java:

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Server Error
        at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
        at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:119)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
        at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
        at $Proxy28.cdwsMI(Unknown Source)
        at xiwebservice.Main.cdwsMI(Main.java:47)
        at xiwebservice.Main.main(Main.java:29)
Java Result: 1

Regards,

Alfred

former_member200962
Active Contributor
0 Kudos

Are you sure that you have created all the required objects in SAP PI?

Did you confirm the working of request in SAP system?

Former Member
0 Kudos

Hi,

Yes, I just followed this steps. I created message mapping for the request and response part and assigned both in the Interface message both in response and request part.

Thanks,

Alfred

Former Member
0 Kudos

It already worked when I use Exactly once option but problem is no response message received and no I've changed it to Best Effort it is now having error saying error occurred in channel monitoring.

Regards,

Alfred

former_member200962
Active Contributor
0 Kudos

provide details about each object that you have created in IR and ID of SAP XI/ PI for this interface.

This is a simple scenario...feel that you have missed some configuration somewhere.

Former Member
0 Kudos

Hi,

Below are the objects I've created.

Data Type:

ReqCustomerNo_DT

RespCustDetails_DT

Message Type:

ReqCustomerNo_MT -> using ReqCustomerNo_DT (Data Type)

RespCustDetails_MT -> using ReqCustomerNo_DT (RespCustDetails_DT)

Message Interface:

CDWS_MI -> synchronous/Outbound

Output Message : ReqCustomerNo_MT -> using ReqCustomerNo_DT (Data Type)

Input Message : RespCustDetails_MT -> using ReqCustomerNo_DT (RespCustDetails_DT)

Message Mapping:

Request_MM -> mapped ReqCustomerNo_MT with BAPI_CUSTOMER_GETDETAIL2(RFC)

Response_MM - mapped BAPI_CUSTOMER_GETDETAIL2.response (RFC) with RespCustDetails_MT

Interface Mapping:

CDWS_IM:

Source Interface -> CDWS_MI

Target Interface -> BAPI_CUSTOMER_GETDETAIL2

Messages:

Request: Mapping Program -> Request_MM

Source Message: ReqCustomerNo_MT

Target Message: BAPI_CUSTOMER_GETDETAIL2

Response: Mapping Program -> Response_MM

Source Message: BAPI_CUSTOMER_GETDETAIL2.Response

Target Message: RespCustDetails_MT

Regards,

Alfred

Former Member
0 Kudos

Hi,

Below are the objects created in ID.

Sender Agreement:

Service: ZBSBACKEND

Interface: CDWS_MI

Interface Namespace: http://atp.amkor.co.ph/ppmodule/synch

Receiver Determination:

Service: ZBSBACKEND

Interface: CDWS_MI

Interface Namespace: http://atp.amkor.co.ph/ppmodule/synch

Configured Receivers: ZBSBACKEND

Interface Determination:

Inbound Interface : BAPI_CUSTOMER_GETDETAIL2

Interface Mapping : CDWS_IM

Receiver Agreement:

Sender

Service: ZBSBACKEND

Receiver

Service: ZBSBACKEND

Interface: BAPI_CUSTOMER_GETDETAIL2

Interface namespace: urn:sap-com:document:sap:rfc:functions

Regards,

Alfred

former_member200962
Active Contributor
0 Kudos
ZBSBACKEND

Why are you using the above Business System both as sender and receiver? The Business System ZBSBACKEND, would represent the SAP ECC system and you normally define a Business Service for the sender (in your case).

Former Member
0 Kudos

Hello,

I've just followed this steps on this site -> [http://www.riyaz.net/blog/xipi-consuming-xi-web-services-using-web-dynpro-part-i/technology/sap/6/]

I think I did all that it said right but still having error during testing

Regards,

Alfred

Former Member
0 Kudos

Hi,

So I need to define the soap channel on a different business system? I still don't know how to set another business system for JAVA. Can you show me how?

Thanks,

Alfred

Former Member
0 Kudos

Hello,

I think its just fine to use same Business system as stated in this forum. Someone said this below

"As mentioned above there is no need to create a Business System for entities outside your SLD boundaries.

You can create a Party in the ID, under that, create a Business Service for your SOAP Sender.

Under that Business Service you can define your SOAP Sender Communication Channel."

[;

Regards,

Alfred

former_member200962
Active Contributor
0 Kudos

A Business System is required when you have to exchange message between SAP PI and SAP ECC system.

In your case JAVA application surely is not a SAP ECC system.....so you need to have a Business Service for it....assign the Source Message Interface (for SOAP) to this Business Service.

Former Member
0 Kudos

Hi,

I see. Can you guide me on how to set this up on SLD.

Regards,

Alfred

former_member200962
Active Contributor
0 Kudos
Can you guide me on how to set this up on SLD.

It is not to be set in SLD....only Business System is created in SLD.

Business Service is created in Integration Directory itself.

Integration Directory --> Right Click and select Business Service....assign a name and say create...then assign the Sender Sync Message Interface to this Business Service.

Delete the existing objects in Integration Directory (RD, ID, SA) you created for this interface.....then again redo the objects with this business service as sender

Regards,

Abhishek.

Former Member
0 Kudos

Hi,

Sorry for the late reply. Already did what you said. I've created a new business system and assigned the sender interface to it but still I get the same error. I I run the program it takes a while and then eventually stops with the same error.

Regards,

Alfred

Former Member
0 Kudos

Hello,

Here are some details that basis found related to the error that I was talking about.

Runtime Errors         DBIF_RSQL_SQL_ERROR
Exception              CX_SY_OPEN_SQL_DB
Date and Time          28.09.2010 09:31:23



 Short text
     SQL error in the database when accessing a table.



 What happened?
     The database system detected a deadlock and avoided it by rolling back
     your transaction.



 What can you do?
     If possible (and necessary), repeat the last database transaction in the
      hope that locking the object will not result in another deadlock.

     Note which actions and input led to the error.

     For further help in handling the problem, contact your SAP administrator
     .

     You can use the ABAP dump analysis transaction ST22 to view and manage
     termination messages, in particular for long term reference.

     Note which actions and input led to the error.

     For further help in handling the problem, contact your SAP administrator
     .

     You can use the ABAP dump analysis transaction ST22 to view and manage
     termination messages, in particular for long term reference.




 Error analysis
     An exception occurred that is explained in detail below.
     The exception, which is assigned to class 'CX_SY_OPEN_SQL_DB', was not caught
      in
     procedure "DELETE_LUW_PACKET" "(FORM)", nor was it propagated by a RAISING
      clause.
     Since the caller of the procedure could not have anticipated that the
     exception would occur, the current program is terminated.
     The reason for the exception is:
     The database system recognized that your last operation on the database
     would have led to a deadlock.
     Therefore, your transaction was rolled back
     to avoid this.

     ORACLE always terminates any transaction that would result in deadlock.
     The other transactions involved in this potential deadlock
     are not affected by the termination.

Regards,

Edited by: alfred_A_sap on Sep 28, 2010 9:10 AM

Answers (2)

Answers (2)

Former Member
0 Kudos

Answered

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi,

You have to pass user name and password of PI in JAVA Program.

Regards,

Raj