use of io.joynr.exceptions.JoynrHttpException in project joynr by bmwcarit.
the class SerializationTest method serializeReplyWithJoynrHttpException.
@Test
public void serializeReplyWithJoynrHttpException() throws IOException {
JoynrHttpException error = new JoynrHttpException(404, "detail message: JoynrHttpException");
Reply reply = new Reply(UUID.randomUUID().toString(), error);
String writeValueAsString = objectMapper.writeValueAsString(reply);
System.out.println(writeValueAsString);
Reply receivedReply = objectMapper.readValue(writeValueAsString, Reply.class);
Assert.assertEquals(reply, receivedReply);
}
use of io.joynr.exceptions.JoynrHttpException in project joynr by bmwcarit.
the class BounceProxyPerformanceReporter method sendPerformanceReportAsHttpRequest.
/**
* Sends an HTTP request to the monitoring service to report performance
* measures of a bounce proxy instance.
*
* @throws IOException
*/
private void sendPerformanceReportAsHttpRequest() throws IOException {
final String url = bounceProxyControllerUrl.buildReportPerformanceUrl();
logger.debug("Using monitoring service URL: {}", url);
Map<String, Integer> performanceMap = bounceProxyPerformanceMonitor.getAsKeyValuePairs();
String serializedMessage = objectMapper.writeValueAsString(performanceMap);
HttpPost postReportPerformance = new HttpPost(url.trim());
// using http apache constants here because JOYNr constants are in
// libjoynr which should not be included here
postReportPerformance.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");
postReportPerformance.setEntity(new StringEntity(serializedMessage, "UTF-8"));
CloseableHttpResponse response = null;
try {
response = httpclient.execute(postReportPerformance);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode != HttpURLConnection.HTTP_NO_CONTENT) {
logger.error("Failed to send performance report: {}", response);
throw new JoynrHttpException(statusCode, "Failed to send performance report.");
}
} finally {
if (response != null) {
response.close();
}
}
}
use of io.joynr.exceptions.JoynrHttpException in project joynr by bmwcarit.
the class BounceProxyShutdownReporter method reportEventAsHttpRequest.
protected void reportEventAsHttpRequest() throws IOException {
final String url = bounceProxyControllerUrl.buildReportShutdownUrl();
logger.debug("Using monitoring service URL: {}", url);
HttpPut putReportShutdown = new HttpPut(url.trim());
CloseableHttpResponse response = null;
try {
response = httpclient.execute(putReportShutdown);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode != HttpURLConnection.HTTP_NO_CONTENT) {
// unexpected response
logger.error("Failed to send shutdown notification: {}", response);
throw new JoynrHttpException(statusCode, "Failed to send shutdown notification. Bounce Proxy still registered at Monitoring Service.");
} else {
logger.debug("Successfully sent shutdown notification");
}
} finally {
if (response != null) {
response.close();
}
}
}
use of io.joynr.exceptions.JoynrHttpException in project joynr by bmwcarit.
the class BounceProxyStartupReporter method reportEventAsHttpRequest.
/**
* Reports the lifecycle event to the monitoring service as HTTP request.
*
* @throws IOException
* if the connection with the bounce proxy controller could not
* be established
* @throws JoynrHttpException
* if the bounce proxy responded that registering the bounce
* proxy did not succeed
*/
private void reportEventAsHttpRequest() throws IOException {
final String url = bounceProxyControllerUrl.buildReportStartupUrl(controlledBounceProxyUrl);
logger.debug("Using monitoring service URL: {}", url);
HttpPut putReportStartup = new HttpPut(url.trim());
CloseableHttpResponse response = null;
try {
response = httpclient.execute(putReportStartup);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
switch(statusCode) {
case HttpURLConnection.HTTP_NO_CONTENT:
// bounce proxy instance was already known at the bounce proxy
// controller
// nothing else to do
logger.info("Bounce proxy was already registered with the controller");
break;
case HttpURLConnection.HTTP_CREATED:
// bounce proxy instance was registered for the very first time
// TODO maybe read URL
logger.info("Registered bounce proxy with controller");
break;
default:
logger.error("Failed to send startup notification: {}", response);
throw new JoynrHttpException(statusCode, "Failed to send startup notification. Bounce Proxy won't get any channels assigned.");
}
} finally {
if (response != null) {
response.close();
}
}
}
Aggregations