Showing posts with label httpclient. Show all posts
Showing posts with label httpclient. Show all posts

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