Search in sources :

Example 1 with HttpException

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

the class HttpTestControllerClientService method request.

private Object request(String action, Map params) throws HttpException, Exception {
    HttpClient client = httpClientFactory.createHttpClient();
    HttpRequest request = httpClientFactory.createRequest(templateAction);
    String accept = request.getHeader("Accept");
    if (accept == null) {
        request.setHeader("Accept", "application/octet-stream");
    }
    String url = request.getURL();
    request.setURL(url + (url.endsWith("/") ? "" : "/") + action);
    if (params != null) {
        Iterator entries = params.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            Object value = entry.getValue();
            if (value != null && value.getClass().isArray()) {
                String[] values = (String[]) value;
                for (int i = 0; i < values.length; i++) {
                    values[i] = URLEncoder.encode(values[i], urlEncodeCharacterEncoding);
                }
                request.setParameters((String) entry.getKey(), values);
            } else {
                request.setParameter((String) entry.getKey(), URLEncoder.encode((String) entry.getValue(), urlEncodeCharacterEncoding));
            }
        }
    }
    HttpResponse response = client.executeRequest(request);
    if (response.getStatusCode() != 200) {
        throw new HttpException("Illegal http status : " + response.getStatusCode());
    }
    String contentLengthStr = response.getHeader("Content-Length");
    int contentLength = 0;
    if (contentLengthStr != null) {
        contentLength = Integer.parseInt(contentLengthStr);
    }
    if (contentLength == 0) {
        return null;
    } else {
        String contentTypeStr = response.getHeader("Content-Type");
        if (contentTypeStr == null) {
            throw new HttpException("Content-Type is null.");
        }
        final MediaType mediaType = new MediaType(contentTypeStr);
        InputStream is = response.getInputStream();
        if ("application/octet-stream".equals(mediaType.getMediaType())) {
            ObjectInputStream ois = new ObjectInputStream(is);
            Object responseObj = ois.readObject();
            if (responseObj instanceof Exception) {
                throw (Exception) responseObj;
            } else {
                return responseObj;
            }
        } else if ("application/zip".equals(mediaType.getMediaType())) {
            return new Object[] { mediaType.getParameter("name"), is };
        } else {
            throw new HttpException("Unsupported Content-Type : " + mediaType.getMediaType());
        }
    }
}
Also used : HttpRequest(jp.ossc.nimbus.service.http.HttpRequest) ZipInputStream(java.util.zip.ZipInputStream) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) HttpResponse(jp.ossc.nimbus.service.http.HttpResponse) HttpException(jp.ossc.nimbus.service.http.HttpException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ZipEntry(java.util.zip.ZipEntry) HttpClient(jp.ossc.nimbus.service.http.HttpClient) Iterator(java.util.Iterator) HttpException(jp.ossc.nimbus.service.http.HttpException) HashMap(java.util.HashMap) Map(java.util.Map) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with HttpException

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

the class HttpTestControllerClientService method getTestScenarioStatus.

public TestScenario.Status getTestScenarioStatus(String scenarioGroupId, String scenarioId) {
    Map params = new HashMap();
    params.put("scenarioGroupId", scenarioGroupId);
    params.put("scenarioId", scenarioId);
    try {
        return (TestScenario.Status) request("getTestScenarioStatus", params);
    } catch (HttpException e) {
        throw e;
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new UndeclaredThrowableException(e);
        }
    }
}
Also used : HashMap(java.util.HashMap) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) HttpException(jp.ossc.nimbus.service.http.HttpException) HashMap(java.util.HashMap) Map(java.util.Map) HttpException(jp.ossc.nimbus.service.http.HttpException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 3 with HttpException

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

the class HttpTestControllerClientService method getTestCaseStatus.

public TestCase.Status getTestCaseStatus(String scenarioGroupId, String scenarioId, String testcaseId) {
    Map params = new HashMap();
    params.put("scenarioGroupId", scenarioGroupId);
    params.put("scenarioId", scenarioId);
    params.put("testcaseId", testcaseId);
    try {
        return (TestCase.Status) request("getTestCaseStatus", params);
    } catch (HttpException e) {
        throw e;
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new UndeclaredThrowableException(e);
        }
    }
}
Also used : HashMap(java.util.HashMap) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) HttpException(jp.ossc.nimbus.service.http.HttpException) HashMap(java.util.HashMap) Map(java.util.Map) HttpException(jp.ossc.nimbus.service.http.HttpException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 4 with HttpException

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

the class HttpTestControllerClientService method getTestScenarioGroupStatus.

public TestScenarioGroup.Status getTestScenarioGroupStatus(String scenarioGroupId) {
    Map params = new HashMap();
    params.put("scenarioGroupId", scenarioGroupId);
    try {
        return (TestScenarioGroup.Status) request("getTestScenarioGroupStatus", params);
    } catch (HttpException e) {
        throw e;
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new UndeclaredThrowableException(e);
        }
    }
}
Also used : HashMap(java.util.HashMap) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) HttpException(jp.ossc.nimbus.service.http.HttpException) HashMap(java.util.HashMap) Map(java.util.Map) HttpException(jp.ossc.nimbus.service.http.HttpException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Example 5 with HttpException

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

the class HttpTestControllerClientService method setTestPhase.

public void setTestPhase(String phase) {
    Map params = new HashMap();
    params.put("phase", phase);
    try {
        request("setTestPhase", params);
    } catch (HttpException e) {
        throw e;
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new UndeclaredThrowableException(e);
        }
    }
}
Also used : HashMap(java.util.HashMap) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) HttpException(jp.ossc.nimbus.service.http.HttpException) HashMap(java.util.HashMap) Map(java.util.Map) HttpException(jp.ossc.nimbus.service.http.HttpException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 HttpException (jp.ossc.nimbus.service.http.HttpException)5 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 Iterator (java.util.Iterator)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 HttpClient (jp.ossc.nimbus.service.http.HttpClient)1 HttpRequest (jp.ossc.nimbus.service.http.HttpRequest)1 HttpResponse (jp.ossc.nimbus.service.http.HttpResponse)1