Tuesday, October 16, 2012

How to invoke Admin Services with SoapUI

It is very very easy to invoke WSO2 Carbon Admin Services with SOAP UI.

Step 1. 
Use the AuthenticationAdmin Service to obtain the session cookie.
You can access the AuthenticationAdmin WSDL of a carbon server with the following url assuming that the server is running with default ports.

http://localhost:9763/services/AuthenticationAdmin?wsdl

SOAP SoapUI to generate the Client for it.
Now invoke the login method. A sample request would be like



<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:aut="http://authentication.services.core.carbon.wso2.org">
   <soap:Header/>
   <soap:Body>
      <aut:login>
         <!--Optional:-->
         <aut:username>admin</aut:username>
         <!--Optional:-->
         <aut:password>admin</aut:password>
         <!--Optional:-->
         <aut:remoteAddress>127.0.0.1</aut:remoteAddress>
      </aut:login>
   </soap:Body>
</soap:Envelope>


In the response message, an HTTP Header will be available with a session cookie.

HTTP/1.1 200 OK

Set-Cookie: JSESSIONID=2671C3A974C0FE67BD9D1DDF665E1DC3; Path=/; Secure; HttpOnly
Content-Type: application/soap+xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 16 Oct 2012 18:48:33 GMT
Server: WSO2 Carbon Server

Step 2.

Now when invoking any other admin service, add the http header COOKIE from soap UI.

COOKIE: JSESSIONID=2671C3A974C0FE67BD9D1DDF665E1DC3
A sample request message would look like 

POST http://localhost:9763/services/ProcessManagementService HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:getProcessInfo"
COOKIE: JSESSIONID=2671C3A974C0FE67BD9D1DDF665E1DC3
User-Agent: Jakarta Commons-HttpClient/3.1
Host: localhost:9763
Content-Length: 571

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:To>local://services/ProcessManagementService</wsa:To>
<wsa:MessageID>urn:uuid:ac59f8ff-de2e-42d1-88f6-2542d54a869c</wsa:MessageID>
<wsa:Action>urn:getProcessInfo</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<ns1:getProcessInfoIn xmlns:ns1="http://wso2.org/bps/management/schema">
<ns1:pid xmlns:s13="http://ode/bpel/unit-test">s13:HelloWorld2-2</ns1:pid>
</ns1:getProcessInfoIn>
</soapenv:Body>
</soapenv:Envelope>



4 comments:

  1. Hi Nandika,

    Your post was of a great help to me.
    Was struggling to find an example on using cookies as headers

    Thanks,

    ReplyDelete
  2. You can also use the basic auth headers to invoke the admin services. If you are using soap ui, you can set the username and password and then it will work fine.

    ReplyDelete
  3. Hi,

    I m trying to invoke the service AuthenticationAdmin via SOAP UI... when I hit login, I pass admin,admin,127.0.0.1.

    In the response, when I see, at bottom I only get 6 elements in header as follows :

    Date Tue, 25 Jun 2013 14:31:42 GMT
    Transfer-Encoding chunked
    #status# HTTP/1.1 200 OK
    Content-Type text/xml; charset=UTF-8
    Connection Keep-Alive
    Server WSO2-PassThrough-HTTP

    Now, I dont get session ID. Can you please point out where m I going wrong?

    Also, as you mentioned about second service at port 9763, only services at this port can be accessed?

    Please help.

    Thanks and Regards,
    Naveen.

    ReplyDelete
  4. Nandika,

    What is the minimum role that the user needs to be assigned to able to authenticate using the AuthenticationAdmin WS?

    Saqib

    ReplyDelete