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());
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
Aggregations