use of io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException in project joynr by bmwcarit.
the class RemoteBounceProxyFacadeTest method testBounceProxyRejectsChannelCreation.
@Test
public void testBounceProxyRejectsChannelCreation() throws Exception {
setMockedHttpRequestHandlerResponse(HttpStatus.SC_NO_CONTENT, "http://www.joynX.de/channels", "X.Y");
ControlledBounceProxyInformation bpInfo = new ControlledBounceProxyInformation("X.Y", URI.create(serverUrl));
try {
bpFacade.createChannel(bpInfo, "channel-123", "trackingId-123");
Assert.fail();
} catch (JoynrProtocolException e) {
}
Mockito.verify(handler).handle(Mockito.argThat(new IsCreateChannelHttpRequest("channel-123", "trackingId-123")), Mockito.any(HttpResponse.class), Mockito.any(HttpContext.class));
}
use of io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException in project joynr by bmwcarit.
the class RemoteBounceProxyFacadeTest method testBounceProxyReturnsNoLocation.
@Test
public void testBounceProxyReturnsNoLocation() throws Exception {
setMockedHttpRequestHandlerResponse(HttpStatus.SC_CREATED, null, "X.Y");
ControlledBounceProxyInformation bpInfo = new ControlledBounceProxyInformation("X.Y", URI.create(serverUrl));
try {
bpFacade.createChannel(bpInfo, "channel-123", "trackingId-123");
Assert.fail();
} catch (JoynrProtocolException e) {
}
Mockito.verify(handler).handle(Mockito.argThat(new IsCreateChannelHttpRequest("channel-123", "trackingId-123")), Mockito.any(HttpResponse.class), Mockito.any(HttpContext.class));
}
use of io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException in project joynr by bmwcarit.
the class RemoteBounceProxyFacadeTest method testBounceProxyReturnsNoBounceProxyId.
@Test
public void testBounceProxyReturnsNoBounceProxyId() throws Exception {
setMockedHttpRequestHandlerResponse(HttpStatus.SC_CREATED, "http://www.joynX.de/channels", null);
ControlledBounceProxyInformation bpInfo = new ControlledBounceProxyInformation("X.Y", URI.create(serverUrl));
try {
bpFacade.createChannel(bpInfo, "channel-123", "trackingId-123");
Assert.fail();
} catch (JoynrProtocolException e) {
}
Mockito.verify(handler).handle(Mockito.argThat(new IsCreateChannelHttpRequest("channel-123", "trackingId-123")), Mockito.any(HttpResponse.class), Mockito.any(HttpContext.class));
}
use of io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException in project joynr by bmwcarit.
the class RemoteBounceProxyFacadeTest method testBounceProxyReturnsUnexpectedBounceProxyId.
@Test
public void testBounceProxyReturnsUnexpectedBounceProxyId() throws Exception {
setMockedHttpRequestHandlerResponse(HttpStatus.SC_CREATED, "http://www.joynX.de/channels", "A.B");
ControlledBounceProxyInformation bpInfo = new ControlledBounceProxyInformation("X.Y", URI.create(serverUrl));
try {
bpFacade.createChannel(bpInfo, "channel-123", "trackingId-123");
Assert.fail();
} catch (JoynrProtocolException e) {
}
Mockito.verify(handler).handle(Mockito.argThat(new IsCreateChannelHttpRequest("channel-123", "trackingId-123")), Mockito.any(HttpResponse.class), Mockito.any(HttpContext.class));
}
use of io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException in project joynr by bmwcarit.
the class RemoteBounceProxyFacade method sendCreateChannelHttpRequest.
private URI sendCreateChannelHttpRequest(ControlledBounceProxyInformation bpInfo, String ccid, String trackingId) throws IOException, JoynrProtocolException {
// TODO jsessionid handling
final String url = bpInfo.getLocationForBpc().toString() + "channels/?ccid=" + ccid;
logger.debug("Using bounce proxy channel service URL: {}", url);
HttpPost postCreateChannel = new HttpPost(url.trim());
postCreateChannel.addHeader(ChannelServiceConstants.X_ATMOSPHERE_TRACKING_ID, trackingId);
CloseableHttpResponse response = null;
try {
response = httpclient.execute(postCreateChannel);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == HttpURLConnection.HTTP_CREATED) {
// check if bounce proxy ID header was sent correctly
if (response.containsHeader("bp")) {
String bounceProxyId = response.getFirstHeader("bp").getValue();
if (bounceProxyId == null || !bounceProxyId.equals(bpInfo.getId())) {
throw new JoynrProtocolException("Bounce proxy ID '" + bounceProxyId + "' returned by bounce proxy '" + bpInfo.getId() + "' does not match.");
}
} else {
throw new JoynrProtocolException("No bounce proxy ID returned by bounce proxy '" + bpInfo.getId() + "'");
}
// get URI of newly created channel
if (!response.containsHeader("Location")) {
throw new JoynrProtocolException("No channel location returned by bounce proxy '" + bpInfo.getId() + "'");
}
String locationValue = response.getFirstHeader("Location").getValue();
if (locationValue == null || locationValue.isEmpty()) {
throw new JoynrProtocolException("Bounce proxy '" + bpInfo.getId() + "' didn't return a channel location.");
}
try {
URI channelLocation = new URI(locationValue);
logger.info("Successfully created channel '{}' on bounce proxy '{}'", ccid, bpInfo.getId());
return channelLocation;
} catch (Exception e) {
throw new JoynrProtocolException("Cannot parse channel location '" + locationValue + "' returned by bounce proxy '" + bpInfo.getId() + "'", e);
}
}
// the bounce proxy is not excepted to reject this call as it was
// chosen based on performance measurements sent by it
logger.error("Failed to create channel on bounce proxy '{}'. Response: {}", bpInfo.getId(), response);
throw new JoynrProtocolException("Bounce Proxy " + bpInfo.getId() + " rejected channel creation (Response: " + response + ")");
} finally {
if (response != null) {
response.close();
}
}
}
Aggregations