Thursday, June 23, 2011

OSB testing services through HTTPClient

I have created a HTTP Facade to my Proxy Service,
and I invoke it with a HTTP Client, I enable monitoring and I observe the performance of the service via the Operation Console / Server Health

This is the Java client


import java.util.Date;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;

public class GUPT {
    public static final String FACADE_URL = "";

    public static void main(String[] args) throws Exception {
        HttpContext localContext = new BasicHttpContext();
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(FACADE_URL);
        StringEntity entity = new StringEntity("<BLANotification Type='TrainItinerary' DateTime='2007-10-26T08:36:28' Id='3' ValidityDate='2004-02-14'/>");
        httppost.setEntity(entity );
        HttpResponse response = httpclient.execute(httppost, localContext);
        System.out.println("getReasonPhrase " + response.getStatusLine().getReasonPhrase());
        System.out.println("getStatusCode " + response.getStatusLine().getStatusCode());
        HttpEntity resultEntity = response.getEntity();

In case of success, I get

getReasonPhrase OK
getStatusCode 200

In case of failure, I get

getReasonPhrase Internal Server Error
getStatusCode 500

In my proxy, I validate the payload; if validation fails, I get a HTTP 500

validate $body/* against BLANotification Schema

No comments: