org.simpleframework.transport.connect.Connection Java Examples

The following examples show how to use org.simpleframework.transport.connect.Connection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HmacClientFilterTest.java    From jersey-hmac-auth with Apache License 2.0 6 votes vote down vote up
@Test
public void validateSignatureWhenThereIsNoContent() throws Exception {
    Connection connection = null;
    try {
        // Start the server
        ValidatingHttpServer server = new SignatureValidatingHttpServer(port, secretKey);
        connection = server.connect();

        // Create a client with the filter that is under test
        Client client = createClient();
        client.addFilter(new HmacClientFilter(apiKey, secretKey, client.getMessageBodyWorkers()));

        // Send a request with no content in the request body
        client.resource(server.getUri()).get(String.class);

    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
 
Example #2
Source File: ValidatingHttpServer.java    From jersey-hmac-auth with Apache License 2.0 5 votes vote down vote up
public Connection connect() throws Exception {
    Server server = new ContainerServer(this);
    Connection connection = new SocketConnection(server);
    SocketAddress address = new InetSocketAddress(port);
    connection.connect(address);
    return connection;
}
 
Example #3
Source File: HmacClientFilterTest.java    From jersey-hmac-auth with Apache License 2.0 5 votes vote down vote up
@Test
public void validateSignatureWhenContentIsPojo() throws Exception {
    Connection connection = null;
    try {
        // Start the server
        RequestConfiguration requestConfiguration =
            RequestConfiguration.builder().withApiKeyQueryParamName("passkey")
                    .withSignatureHttpHeader("duck-duck-signature-header")
                    .withTimestampHttpHeader("duck-duck-timestamp-header")
                    .withVersionHttpHeader("duck-duck-version-header")
                    .build();
        ValidatingHttpServer server = new SignatureValidatingHttpServer(port, secretKey, requestConfiguration);
        connection = server.connect();

        // Create a client with the filter that is under test
        Client client = createClient();
        client.addFilter(new HmacClientFilter(apiKey, secretKey, client.getMessageBodyWorkers(), requestConfiguration));
        client.addFilter(new GZIPContentEncodingFilter(true));

        // Send a pizza in the request body
        Pizza pizza = new Pizza();
        pizza.setTopping("olive");
        client.resource(server.getUri())
                .type(MediaType.APPLICATION_JSON_TYPE)
                .put(pizza);

    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
 
Example #4
Source File: HmacClientFilterTest.java    From jersey-hmac-auth with Apache License 2.0 5 votes vote down vote up
@Test
public void validateSignatureWhenContentIsBinary() throws Exception {
    Connection connection = null;
    try {
        // Start the server
        RequestConfiguration requestConfiguration =
                RequestConfiguration.builder()
                        .withApiKeyQueryParamName("passkey")
                        .withSignatureHttpHeader("duck-duck-signature-header")
                        .withTimestampHttpHeader("duck-duck-timestamp-header")
                        .withVersionHttpHeader("duck-duck-version-header")
                        .build();

        ValidatingHttpServer server = new SignatureValidatingHttpServer(port, secretKey, requestConfiguration);
        connection = server.connect();

        // Create a client with the filter that is under test
        Client client = createClient();
        client.addFilter(new HmacClientFilter(apiKey, secretKey, client.getMessageBodyWorkers(),requestConfiguration));

        // Send some random binary data in the request body
        byte[] binaryData = new byte[2];
        new Random().nextBytes(binaryData);
        client.resource(server.getUri())
                .type(MediaType.APPLICATION_OCTET_STREAM_TYPE)
                .put(binaryData);

    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
 
Example #5
Source File: HmacClientFilterTest.java    From jersey-hmac-auth with Apache License 2.0 5 votes vote down vote up
@Test
public void validateSignatureWhenPathHasQueryParams() throws Exception {
    Connection connection = null;
    try {
        // Start the server
        RequestConfiguration requestConfiguration =
                RequestConfiguration.builder()
                        .withApiKeyQueryParamName("passkey")
                        .withSignatureHttpHeader("duck-duck-signature-header")
                        .withTimestampHttpHeader("duck-duck-timestamp-header")
                        .withVersionHttpHeader("duck-duck-version-header")
                        .build();
        ValidatingHttpServer server = new SignatureValidatingHttpServer(port, secretKey, requestConfiguration);
        connection = server.connect();

        // Create a client with the filter that is under test
        Client client = createClient();
        client.addFilter(new HmacClientFilter(apiKey, secretKey, client.getMessageBodyWorkers(), requestConfiguration));

        // Send the request to a path other than "/" and that also includes an additional query parameter
        URI uri = UriBuilder.fromUri(server.getUri())
                .segment("api", "v1", "pizza")
                .queryParam("sort", "toppings")
                .build();
        client.resource(uri).get(String.class);

    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}