use of io.joynr.messaging.datatypes.JoynrMessagingError in project joynr by bmwcarit.
the class LongPollChannel method longPoll.
private void longPoll() {
String responseBody = null;
if (shutdown) {
return;
}
final String asciiString = httpget.getURI().toASCIIString();
try {
responseBody = httpclient.execute(httpget, new ResponseHandler<String>() {
@Override
public String handleResponse(HttpResponse response) throws IOException {
HttpEntity entity = response.getEntity();
String body = entity == null ? null : EntityUtils.toString(entity, "UTF-8");
statusCode = response.getStatusLine().getStatusCode();
statusText = response.getStatusLine().getReasonPhrase();
logger.debug("Long poll returned: {} reason: url {}", statusCode, asciiString);
return body;
}
});
} catch (IllegalStateException e) {
logger.error("IllegalStateException in long poll: {} message: {}", asciiString, e.getMessage());
throw new JoynrShutdownException(e.getMessage(), e);
} catch (Exception e) {
logger.debug("Exception in long poll: " + asciiString, e);
delay();
return;
}
switch(statusCode) {
case HttpStatus.SC_OK:
notifyDispatcher(responseBody);
break;
case HttpStatus.SC_NOT_FOUND:
logger.error(responseBody);
delay();
throw new JoynrChannelMissingException("Not found");
case HttpStatus.SC_BAD_REQUEST:
if (responseBody != null) {
try {
JoynrMessagingError error = objectMapper.readValue(responseBody, JoynrMessagingError.class);
JoynrMessagingErrorCode joynrMessagingErrorCode = JoynrMessagingErrorCode.getJoynrMessagingErrorCode(error.getCode());
logger.error(error.toString());
switch(joynrMessagingErrorCode) {
case JOYNRMESSAGINGERROR_CHANNELNOTFOUND:
throw new JoynrChannelMissingException(error.getReason());
default:
throw new JoynrCommunicationException(error.getReason());
}
} catch (IOException e) {
throw new JoynrCommunicationException(statusText, e);
}
}
default:
delay();
break;
}
}
Aggregations