Search in sources :

Example 1 with HttpClientActivity

use of net.java.client.slee.resource.http.HttpClientActivity in project charging-server by RestComm.

the class HTTPClientSbb method onResponseEvent.

// Event handler methods
public void onResponseEvent(ResponseEvent event, ActivityContextInterface aci) {
    HttpResponse response = event.getHttpResponse();
    if (tracer.isInfoEnabled()) {
        tracer.info("[<<] Received HTTP Response. Status Code = " + response.getStatusLine().getStatusCode());
        if (tracer.isFineEnabled()) {
            try {
                tracer.fine("[<<] Received HTTP Response. Response Body = [" + EntityUtils.toString(response.getEntity()) + "]");
            } catch (Exception e) {
                tracer.severe("[xx] Failed reading response body", e);
            }
        }
    }
    // end http activity
    ((HttpClientActivity) aci.getActivity()).endActivity();
    // call back parent
    HashMap params = (HashMap) event.getRequestApplicationData();
    RatingInfo ratInfo = buildRatingInfo(response, params);
    final DiameterChargingServer parent = (DiameterChargingServer) sbbContext.getSbbLocalObject().getParent();
    parent.getRateForServiceResult(ratInfo);
}
Also used : HashMap(java.util.HashMap) RatingInfo(org.mobicents.charging.server.ratingengine.RatingInfo) HttpResponse(org.apache.http.HttpResponse) HttpClientActivity(net.java.client.slee.resource.http.HttpClientActivity) StartActivityException(javax.slee.resource.StartActivityException) NamingException(javax.naming.NamingException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DiameterChargingServer(org.mobicents.charging.server.DiameterChargingServer)

Example 2 with HttpClientActivity

use of net.java.client.slee.resource.http.HttpClientActivity in project charging-server by RestComm.

the class HTTPClientSbb method getRateForServiceAsync.

public RatingInfo getRateForServiceAsync(HashMap params) {
    String sessionIdFromRequest = params.get("SessionId").toString();
    HttpClientActivity clientActivity = null;
    try {
        clientActivity = raSbbInterface.createHttpClientActivity(true, null);
    } catch (StartActivityException e) {
        tracer.severe("[xx] Failed creating HTTP Client Activity to send HTTP Request to Rating Engine.");
        return new RatingInfo(-1, sessionIdFromRequest);
    }
    ActivityContextInterface clientAci = httpClientAci.getActivityContextInterface(clientActivity);
    clientAci.attach(sbbContext.getSbbLocalObject());
    params.put("startTime", System.currentTimeMillis());
    HttpPost httpPost = buildHTTPRequest(params);
    // Asynchronous call
    clientActivity.execute(httpPost, params);
    tracer.info("[>>] Sent HTTP Request to Rating Client in asynchronous mode.");
    return null;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) RatingInfo(org.mobicents.charging.server.ratingengine.RatingInfo) ActivityContextInterface(javax.slee.ActivityContextInterface) HttpClientActivity(net.java.client.slee.resource.http.HttpClientActivity) StartActivityException(javax.slee.resource.StartActivityException)

Aggregations

StartActivityException (javax.slee.resource.StartActivityException)2 HttpClientActivity (net.java.client.slee.resource.http.HttpClientActivity)2 RatingInfo (org.mobicents.charging.server.ratingengine.RatingInfo)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 NamingException (javax.naming.NamingException)1 ActivityContextInterface (javax.slee.ActivityContextInterface)1 HttpResponse (org.apache.http.HttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 DiameterChargingServer (org.mobicents.charging.server.DiameterChargingServer)1