HTTP resource adaptor package includes an example "Ping" service. This service simply responds with a page displaying the request contents.

Install and run the service

Below are basic instructions for deploying and testing the HTTP example service in your SLEE, followed by an excerpt of SBB code showing how a client sends and a server processes HTTP requests.

1

Install the service:

$ cd examples
$ ant

2

Navigate to http://localhost:8000/ in a web browser.

HTTPS

To enable HTTPS:

1

Generate a keystore for the server:

$ keytool -keystore http-ra.ks -storepass changeit -genkeypair
Warning The http-ra.ks file should be placed in the Rhino home directory. The resource adaptor has a default FilePermission allowing it to read ${rhino.dir.home}/http-ra.ks. If you put the file elsewhere or give it a different name, you will need to update the security permissions for the resource adaptor entity.

2

Configure the resource adaptor entity and restart it:

rhino$ client/bin/rhino-console
[Rhino@localhost (#0)] updateraentityconfigproperties httpra SecureListenPort 8002 KeyStore "${rhino.dir.home}/http-ra.ks" KeyStorePassword changeit
[Rhino@localhost (#1)] deactivateraentity httpra
[Rhino@localhost (#2)] activateraentity httpra

3

The URL https://localhost:8002/ should now display the same page as before, using HTTPS.

Sample code

Below are excerpts of SBB code showing how servers can process HTTP requests, and clients can send them.

Server

Below is an excerpt of SBB code showing how incoming HTTP requests can be processed.

import com.opencloud.slee.resources.http.*;

...

// SBB event handler
public void onGET(HttpRequest event, ActivityContextInterface aci) {
    IncomingHttpRequestActivity activity = (IncomingHttpRequestActivity) aci.getActivity();
    // Send a redirect response...
    HttpResponse response = activity.createResponse(302, "Moved Temporarily");
    response.setHeader("Location", "http://anotherserver/index.html");
    try {
        activity.sendResponse(response);
    } catch (IOException e) {
        warn("unable to send response", e);
    }
}

Client

Below is an excerpt of SBB code showing how outgoing HTTP requests can be made.

import com.opencloud.slee.resources.http.*;

...

public void setSbbContext(SbbContext sbbContext) {
    this.sbbContext = sbbContext;
    Context sbbEnv = (Context) new InitialContext().lookup("java:comp/env");
    provider = (HttpProvider) sbbEnv.lookup("slee/resources/http/2.2/provider");
    acif = (HttpActivityContextInterfaceFactory) sbbEnv.lookup("slee/resources/http/2.2/acifactory");
    ...
}

public void onSomeEvent(SomeEvent event, ActivityContextInterface aci) {
    ...
    HttpRequest newRequest = provider.createRequest(HttpRequest.POST, new URL("http://someserver/service.jsp"));
    newRequest.setContentAsString("text/plain; charset=\"utf-8\"", "test message");

    OutgoingHttpRequestActivity activity = provider.createRequestActivity(newRequest);
    ActivityContextInterface newACI = acif.getActivityContextInterface(activity);
    // attach so we will receive response...
    newACI.attach(sbbContext.getSbbLocalObject());
    //Set the SAS trail to one we have on hand.
    sasFacility.setActivityTrail(newACI, trail);
    activity.sendRequest();
}

public void onHttpResponse(HttpResponse event, ActivityContextInterface aci) {
    trace("Received " + event.getStatusCode() + " response");
    byte[] data = event.getContent();   // Or getContentAsString() if appropriate
    // process response content...
}

// instance vars
private SbbContext sbbContext;
private HttpProvider provider;
private HttpActivityContextInterfaceFactory acif;
Previous page