Tuesday, December 7, 2010

JDeveloper and HttpClient to test a OSB "any XML" service

I want to code some Unit Tests for a Pure XML service.
SOAPUI doesn't seem to have any support for such services (maybe?).

So I will code something in Java. Actually I might do it in Groovy.

HttpClient is deployed 3 times (!!!) with SOASuite and JDev:

C:\Oracle1\Middleware\jdeveloper\communications\modules\oracle.sdp.client_11.1.1\commons-httpclient-3.1.jar

C:\Oracle1\Middleware\jdeveloper\ide\lib\commons-httpclient-3.1.jar

C:\Oracle1\Middleware\Oracle_SOA1\soa\modules\commons-httpclient-3.1.jar

In reality httpclient 3 is a legacy code and one is encouraged to upgrade to 4
http://hc.apache.org/downloads.cgi

(download both core and httpclient jars)
here is the link with the dependencies.


Here a quick tutorial.

Bear in mind that even if you post a XML to a "Any XML" service, OSB will still wrap it into a soapenv:Body element....




so if you want to grab the payload you should get the XPath "./*" of variable $body...
using the XPath "." will return you an object of type Body.


Here is the harness:

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost request = new HttpPost("http://localhost:7001/CreateOrder/PS/CreateOrderPS");
HttpEntity httpEntity = new FileEntity(new File("C:\\JDeveloper\\mywork\\ACME_POC\\CreateOrderTest\\resources\\createorderpayload.xml"), "text/html");
request.setEntity(httpEntity);
HttpResponse response = httpclient.execute(request);
System.out.println(response.getStatusLine().getStatusCode());

and of course the status should be 200
If it's 500 you might have a fault (e.g. validation error)


Here for my reference are the available sbresource queries:

* http://host:port/sbresource?WSDL/project/...wsdlname
* http://host:port/sbresource?POLICY/project/...policyname
* http://host:port/sbresource?MFL/project/...mflname
* http://host:port/sbresource?SCHEMA/project/...schemaname
* http://host:port/sbresource?PROXY/project/...proxyname

4 comments:

Damien said...

Hi

I think the url will need to include sbresource?PROXY directive in order to call the proxy service from a http client. Also doers the proxy service not require a WSDL service?

vernetto said...

Hello Damien,
if the Proxy Service is a "Any XML", no WSDL is associated to it...
if I am wrong please correct me.

actually the POST works without the "sbresource?PROXY" directive.... can you tell me more about this "sbresource?PROXY" thingie?

thanks!

Damien said...

Hi Perluigi,

Apologies the sbresource?PROXY is used the url for accessing the WSDL of the proxy service as desribed here -http://download.oracle.com/docs/cd/E13159_01/osb/docs10gr3/userguide/configuringandusingservices.html

This would be required if the proxy service was based on a WSDL and you needed to test via SOAPUI, XMLSPY etc

vernetto said...

actually I have tried:

http://localhost:7001/sbresource?PROXY/CreateOrder/PS/CreateOrderPS

and I get

java.io.IOException: This service is not associated to a wsdl


since it's a "Any XML" service....


Anyway it's interesting that you can retrieve those entities through a HTTP GET, nice one Damien!