Search in sources :

Example 6 with HttpRequest

use of jp.ossc.nimbus.service.http.HttpRequest in project nimbus by nimbus-org.

the class HttpKeepAliveCheckerService method startService.

public void startService() throws Exception {
    if (httpClientFactoryServiceName != null) {
        httpClientFactory = (HttpClientFactory) ServiceManagerFactory.getServiceObject(httpClientFactoryServiceName);
    }
    if (httpClientFactory == null) {
        throw new IllegalArgumentException("HttpClientFactory is null.");
    }
    if (checkTargetRequestName == null || "".equals(checkTargetRequestName)) {
        throw new IllegalArgumentException("CheckTargetRequestName is null.");
    }
    if (hostResolverServiceName != null) {
        hostResolver = (HostResolver) ServiceManagerFactory.getServiceObject(hostResolverServiceName);
    }
    HttpRequest request = httpClientFactory.createRequest(checkTargetRequestName);
    checkTargetUrl = new URL(request.getURL());
    if (protocol == null) {
        protocol = checkTargetUrl.getProtocol();
    }
    if (port == -1) {
        port = checkTargetUrl.getPort();
    }
    if (path == null) {
        path = checkTargetUrl.getPath();
    }
}
Also used : HttpRequest(jp.ossc.nimbus.service.http.HttpRequest) URL(java.net.URL)

Example 7 with HttpRequest

use of jp.ossc.nimbus.service.http.HttpRequest in project nimbus by nimbus-org.

the class HttpKeepAliveCheckerService method checkAlive.

public boolean checkAlive() throws Exception {
    HttpClient client = httpClientFactory.createHttpClient();
    HttpRequest request = httpClientFactory.createRequest(checkTargetRequestName);
    try {
        HttpResponse response = client.executeRequest(request);
        if (response.getStatusCode() == 200) {
            if (assertString != null) {
                String responseBody = (String) response.getObject();
                if (assertString.equals(responseBody)) {
                    return true;
                }
            } else {
                return true;
            }
        }
    } catch (HttpClientConnectTimeoutException e) {
    } catch (HttpClientSocketTimeoutException e) {
    }
    return false;
}
Also used : HttpRequest(jp.ossc.nimbus.service.http.HttpRequest) HttpClient(jp.ossc.nimbus.service.http.HttpClient) HttpClientConnectTimeoutException(jp.ossc.nimbus.service.http.httpclient.HttpClientConnectTimeoutException) HttpResponse(jp.ossc.nimbus.service.http.HttpResponse) HttpClientSocketTimeoutException(jp.ossc.nimbus.service.http.httpclient.HttpClientSocketTimeoutException)

Aggregations

HttpRequest (jp.ossc.nimbus.service.http.HttpRequest)7 PropertySchemaDefineException (jp.ossc.nimbus.beans.dataset.PropertySchemaDefineException)3 HttpClient (jp.ossc.nimbus.service.http.HttpClient)3 HttpClientFactory (jp.ossc.nimbus.service.http.HttpClientFactory)3 HttpResponse (jp.ossc.nimbus.service.http.HttpResponse)3 HttpClientImpl (jp.ossc.nimbus.service.http.httpclient.HttpClientFactoryService.HttpClientImpl)3 ConvertException (jp.ossc.nimbus.util.converter.ConvertException)3 InputStream (java.io.InputStream)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 DataSet (jp.ossc.nimbus.beans.dataset.DataSet)2 Header (jp.ossc.nimbus.beans.dataset.Header)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1