Skip to Content
0
Jun 06, 2005 at 06:38 AM

Servlet calling a BAPI Web Service...

22 Views

Hi everyone,

I downloaded the wsdl file for the BAPI_USER_GETLIST.

I created a Deployable Proxy that points to this wsdl file.

I created a Web modul project with a servlet.

I also created an Enterprise application project that contains my Web modul project.

In the Web modul project, I created a servlet :

Here is the code of the servlet :

<b>try {

InitialContext ic = new InitialContext();

BAPI_USER_GETLISTService sampleWS = (BAPI_USER_GETLISTService)ic.lookup("java:comp/env/SampleWSProxy");

BAPI_USER_GETLISTPortType vi = sampleWS.getLogicalPort();

BAPI_USER_GETLIST importParams = new BAPI_USER_GETLIST();

ArrayList list = new ArrayList();

BAPIUSNAME structure = new BAPIUSNAME();

structure.setUSERNAME(new String());

structure.setFIRSTNAME(new String());

structure.setLASTNAME(new String());

structure.setFULLNAME(new String());

list.add(structure);

BAPIUSNAME[] rows = new BAPIUSNAME[list.size()];

list.toArray(rows);

importParams.setUSERLIST(rows);

importParams.setWITH_USERNAME("X");

BAPI_USER_GETLISTResponse exportParams = null;

BAPIUSNAME[] res = vi.BAPI_USER_GETLIST(rows,"");

for(int i=0;i<res.length;i++)

response.getWriter().write(res<i>.getFIRSTNAME());

} catch(Exception e)

{

response.getWriter().write("ERROR!!!" + e.getMessage());

}

</b>

The exception is :

<b>ERROR!!!Service call exception; nested exception is: com.sap.engine.services.webservices.jaxrpc.exceptions.InvalidResponseCodeException: Invalid Response Code: (401) Unauthorized.</b>

Can someone help with this security problem ?

Is the code OK except the security problem ?

Thanks a lot.