Search in sources :

Example 1 with JoynrProtocolException

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));
}
Also used : JoynrProtocolException(io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException) HttpContext(org.apache.http.protocol.HttpContext) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) IsCreateChannelHttpRequest(io.joynr.messaging.bounceproxy.IsCreateChannelHttpRequest) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 2 with JoynrProtocolException

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));
}
Also used : JoynrProtocolException(io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException) HttpContext(org.apache.http.protocol.HttpContext) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) IsCreateChannelHttpRequest(io.joynr.messaging.bounceproxy.IsCreateChannelHttpRequest) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 3 with JoynrProtocolException

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));
}
Also used : JoynrProtocolException(io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException) HttpContext(org.apache.http.protocol.HttpContext) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) IsCreateChannelHttpRequest(io.joynr.messaging.bounceproxy.IsCreateChannelHttpRequest) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 4 with JoynrProtocolException

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));
}
Also used : JoynrProtocolException(io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException) HttpContext(org.apache.http.protocol.HttpContext) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) IsCreateChannelHttpRequest(io.joynr.messaging.bounceproxy.IsCreateChannelHttpRequest) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 5 with JoynrProtocolException

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();
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) HttpPost(org.apache.http.client.methods.HttpPost) JoynrProtocolException(io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) URI(java.net.URI) IOException(java.io.IOException) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrProtocolException(io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException)

Aggregations

JoynrProtocolException (io.joynr.messaging.bounceproxy.controller.exception.JoynrProtocolException)5 IsCreateChannelHttpRequest (io.joynr.messaging.bounceproxy.IsCreateChannelHttpRequest)4 ControlledBounceProxyInformation (io.joynr.messaging.info.ControlledBounceProxyInformation)4 HttpResponse (org.apache.http.HttpResponse)4 HttpContext (org.apache.http.protocol.HttpContext)4 Test (org.junit.Test)4 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 IOException (java.io.IOException)1 URI (java.net.URI)1 StatusLine (org.apache.http.StatusLine)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1