Example usage for io.netty.handler.codec.http HttpMethod DELETE

List of usage examples for io.netty.handler.codec.http HttpMethod DELETE

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpMethod DELETE.

Prototype

HttpMethod DELETE

To view the source code for io.netty.handler.codec.http HttpMethod DELETE.

Click Source Link

Document

The DELETE method requests that the origin server delete the resource identified by the Request-URI.

Usage

From source file:com.nike.cerberus.endpoints.category.DeleteCategoryTest.java

License:Apache License

@Test
public void requestMatcher_is_http_delete() {
    final Matcher matcher = subject.requestMatcher();
    assertThat(matcher.matchingMethods()).containsOnly(HttpMethod.DELETE);
}

From source file:com.nike.cerberus.endpoints.sdb.DeleteSafeDepositBox.java

License:Apache License

@Override
public Matcher requestMatcher() {
    return Matcher.match("/v1/safe-deposit-box/{id}", HttpMethod.DELETE);
}

From source file:com.rackspacecloud.blueflood.http.RouteMatcher.java

License:Apache License

public void route(ChannelHandlerContext context, FullHttpRequest request) {
    final String method = request.getMethod().name();
    final String URI = request.getUri();

    // Method not implemented for any resource. So return 501.
    if (method == null || !implementedVerbs.contains(method)) {
        route(context, request, unsupportedVerbsHandler);
        return;//w  w w .  j  a  v a2 s  .  c om
    }

    final Pattern pattern = getMatchingPatternForURL(URI);

    // No methods registered for this pattern i.e. URL isn't registered. Return 404.
    if (pattern == null) {
        route(context, request, noRouteHandler);
        return;
    }

    final Set<String> supportedMethods = getSupportedMethods(pattern);
    if (supportedMethods == null) {
        log.warn("No supported methods registered for a known pattern " + pattern);
        route(context, request, noRouteHandler);
        return;
    }

    // The method requested is not available for the resource. Return 405.
    if (!supportedMethods.contains(method)) {
        route(context, request, unsupportedMethodHandler);
        return;
    }
    PatternRouteBinding binding = null;
    if (method.equals(HttpMethod.GET.name())) {
        binding = getBindings.get(pattern);
    } else if (method.equals(HttpMethod.PUT.name())) {
        binding = putBindings.get(pattern);
    } else if (method.equals(HttpMethod.POST.name())) {
        binding = postBindings.get(pattern);
    } else if (method.equals(HttpMethod.DELETE.name())) {
        binding = deleteBindings.get(pattern);
    } else if (method.equals(HttpMethod.PATCH.name())) {
        binding = deleteBindings.get(pattern);
    } else if (method.equals(HttpMethod.OPTIONS.name())) {
        binding = optionsBindings.get(pattern);
    } else if (method.equals(HttpMethod.HEAD.name())) {
        binding = headBindings.get(pattern);
    } else if (method.equals(HttpMethod.TRACE.name())) {
        binding = traceBindings.get(pattern);
    } else if (method.equals(HttpMethod.CONNECT.name())) {
        binding = connectBindings.get(pattern);
    }

    if (binding != null) {
        request = updateRequestHeaders(request, binding);
        route(context, request, binding.handler);
    } else {
        throw new RuntimeException("Cannot find a valid binding for URL " + URI);
    }
}

From source file:com.rackspacecloud.blueflood.http.RouteMatcher.java

License:Apache License

public void delete(String pattern, HttpRequestHandler handler) {
    addBinding(pattern, HttpMethod.DELETE.name(), handler, deleteBindings);
}

From source file:com.spotify.google.cloud.pubsub.client.Pubsub.java

License:Apache License

/**
 * Make a DELETE request.//www .ja  v a 2 s .  c  o m
 */
private <T> PubsubFuture<T> delete(final String operation, final String path,
        final ResponseReader<T> responseReader) {
    return request(operation, HttpMethod.DELETE, path, responseReader);
}

From source file:com.spotify.google.cloud.pubsub.client.Pubsub.java

License:Apache License

/**
 * Make an HTTP request.//from   w  w  w.  j  a  v a2  s.c  o m
 */
private <T> PubsubFuture<T> request(final String operation, final HttpMethod method, final String path,
        final Object payload, final ResponseReader<T> responseReader) {

    final String uri = baseUri + path;
    final RequestBuilder builder = new RequestBuilder().setUrl(uri).setMethod(method.toString())
            .setHeader("Authorization", "Bearer " + accessToken).setHeader(CONNECTION, KEEP_ALIVE)
            .setHeader("User-Agent", USER_AGENT);

    final long payloadSize;
    if (payload != NO_PAYLOAD) {
        final byte[] json = gzipJson(payload);
        payloadSize = json.length;
        builder.setHeader(CONTENT_ENCODING, GZIP);
        builder.setHeader(CONTENT_LENGTH, String.valueOf(json.length));
        builder.setHeader(CONTENT_TYPE, APPLICATION_JSON_UTF8);
        builder.setBody(json);
    } else {
        builder.setHeader(CONTENT_LENGTH, String.valueOf(0));
        payloadSize = 0;
    }

    final Request request = builder.build();

    final RequestInfo requestInfo = RequestInfo.builder().operation(operation).method(method.toString())
            .uri(uri).payloadSize(payloadSize).build();

    final PubsubFuture<T> future = new PubsubFuture<>(requestInfo);
    client.executeRequest(request, new AsyncHandler<Void>() {
        private final ByteArrayOutputStream bytes = new ByteArrayOutputStream();

        @Override
        public void onThrowable(final Throwable t) {
            future.fail(t);
        }

        @Override
        public State onBodyPartReceived(final HttpResponseBodyPart bodyPart) throws Exception {
            bytes.write(bodyPart.getBodyPartBytes());
            return State.CONTINUE;
        }

        @Override
        public State onStatusReceived(final HttpResponseStatus status) {

            // Return null for 404'd GET & DELETE requests
            if (status.getStatusCode() == 404 && method == HttpMethod.GET || method == HttpMethod.DELETE) {
                future.succeed(null);
                return State.ABORT;
            }

            // Fail on non-2xx responses
            final int statusCode = status.getStatusCode();
            if (!(statusCode >= 200 && statusCode < 300)) {
                future.fail(new RequestFailedException(status.getStatusCode(), status.getStatusText()));
                return State.ABORT;
            }

            if (responseReader == VOID) {
                future.succeed(null);
                return State.ABORT;
            }

            return State.CONTINUE;
        }

        @Override
        public State onHeadersReceived(final io.netty.handler.codec.http.HttpHeaders headers) {
            return State.CONTINUE;
        }

        @Override
        public Void onCompleted() throws Exception {
            if (future.isDone()) {
                return null;
            }
            try {
                future.succeed(responseReader.read(bytes.toByteArray()));
            } catch (Exception e) {
                future.fail(e);
            }
            return null;
        }
    });

    return future;
}

From source file:com.spotify.google.cloud.pubsub.client.Pubsub.java

License:Apache License

/**
 * Make an HTTP request using {@link java.net.HttpURLConnection}.
 *//*w w  w.jav a  2s.c o  m*/
private <T> PubsubFuture<T> requestJavaNet(final String operation, final HttpMethod method, final String path,
        final Object payload, final ResponseReader<T> responseReader) {

    final HttpRequestFactory requestFactory = transport.createRequestFactory();

    final String uri = baseUri + path;

    final HttpHeaders headers = new HttpHeaders();
    final HttpRequest request;
    try {
        request = requestFactory.buildRequest(method.name(), new GenericUrl(URI.create(uri)), null);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }

    headers.setAuthorization("Bearer " + accessToken);
    headers.setUserAgent("Spotify");

    final long payloadSize;
    if (payload != NO_PAYLOAD) {
        final byte[] json = gzipJson(payload);
        payloadSize = json.length;
        headers.setContentEncoding(GZIP.toString());
        headers.setContentLength((long) json.length);
        headers.setContentType(APPLICATION_JSON_UTF8);
        request.setContent(new ByteArrayContent(APPLICATION_JSON_UTF8, json));
    } else {
        payloadSize = 0;
    }

    request.setHeaders(headers);

    final RequestInfo requestInfo = RequestInfo.builder().operation(operation).method(method.toString())
            .uri(uri).payloadSize(payloadSize).build();

    final PubsubFuture<T> future = new PubsubFuture<>(requestInfo);

    executor.execute(() -> {
        final HttpResponse response;
        try {
            response = request.execute();
        } catch (IOException e) {
            future.fail(e);
            return;
        }

        // Return null for 404'd GET & DELETE requests
        if (response.getStatusCode() == 404 && method == HttpMethod.GET || method == HttpMethod.DELETE) {
            future.succeed(null);
            return;
        }

        // Fail on non-2xx responses
        final int statusCode = response.getStatusCode();
        if (!(statusCode >= 200 && statusCode < 300)) {
            future.fail(new RequestFailedException(response.getStatusCode(), response.getStatusMessage()));
            return;
        }

        if (responseReader == VOID) {
            future.succeed(null);
            return;
        }

        try {

            future.succeed(responseReader.read(ByteStreams.toByteArray(response.getContent())));
        } catch (Exception e) {
            future.fail(e);
        }
    });

    return future;
}

From source file:com.strategicgains.restexpress.plugin.cache.DateHeaderPostprocessorTest.java

License:Apache License

@Test
public void shouldNotAddDateHeaderOnDelete() {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE,
            "/foo?param1=bar&param2=blah&yada");
    httpRequest.headers().add("Host", "testing-host");
    Response response = new Response();
    processor.process(new Request(httpRequest, null), response);
    assertFalse(response.hasHeader(HttpHeaders.Names.DATE));
}

From source file:com.strategicgains.restexpress.plugin.swagger.SwaggerPluginTest.java

License:Apache License

@BeforeClass
public static void intialize() {
    RestAssured.port = PORT;//from ww w  . j  a va 2  s .  co m

    DummyController controller = new DummyController();
    SERVER.setBaseUrl(BASE_URL);

    SERVER.uri("/", controller).action("health", HttpMethod.GET).name("root");

    SERVER.uri("/anothers/{userId}", controller).action("readAnother", HttpMethod.GET);

    SERVER.uri("/users.{format}", controller).action("readAll", HttpMethod.GET)
            .action("options", HttpMethod.OPTIONS).method(HttpMethod.POST).name("Users Collection");

    SERVER.uri("/users/{userId}.{format}", controller).method(HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE)
            .action("options", HttpMethod.OPTIONS).name("Individual User");

    SERVER.uri("/users/{userId}/orders.{format}", controller).action("readAll", HttpMethod.GET)
            .method(HttpMethod.POST).name("User Orders Collection");

    SERVER.uri("/orders.{format}", controller).action("readAll", HttpMethod.GET).method(HttpMethod.POST)
            .name("Orders Collection");

    SERVER.uri("/orders/{orderId}.{format}", controller)
            .method(HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE).name("Individual Order");

    SERVER.uri("/orders/{orderId}/items.{format}", controller).action("readAll", HttpMethod.GET)
            .method(HttpMethod.POST).name("Order Line-Items Collection");

    SERVER.uri("/orders/{orderId}/items/{itemId}.{format}", controller)
            .method(HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE).name("Individual Order Line-Item");

    SERVER.uri("/products.{format}", controller).action("readAll", HttpMethod.GET).method(HttpMethod.POST)
            .name("Orders Collection");

    SERVER.uri("/products/{orderId}.{format}", controller)
            .method(HttpMethod.GET, HttpMethod.PUT, HttpMethod.DELETE).name("Individual Order");

    SERVER.uri("/health", controller).flag("somevalue").action("health", HttpMethod.GET).name("health");

    SERVER.uri("/nicknametest", controller).method(HttpMethod.GET).name(" |nickName sh0uld_str1p-CHARS$. ");

    SERVER.uri("/annotations/{userId}/users", controller)
            .action("readWithApiOperationAnnotation", HttpMethod.GET).method(HttpMethod.GET)
            .name("Read with Annotations");

    SERVER.uri("/annotations/hidden", controller).action("thisIsAHiddenAPI", HttpMethod.GET)
            .method(HttpMethod.GET).name("thisIsAHiddenAPI");

    SERVER.uri("/annotations/{userId}", controller).action("updateWithApiResponse", HttpMethod.PUT)
            .method(HttpMethod.PUT).name("Update with Annotations");

    SERVER.uri("/annotations/{userId}/users/list", controller)
            .action("createWithApiImplicitParams", HttpMethod.POST).method(HttpMethod.POST)
            .name("Create with Implicit Params");

    SERVER.uri("/annotations/{userId}/users/newlist", controller).action("createWithApiParam", HttpMethod.POST)
            .method(HttpMethod.POST).name("Create with Api Param");

    SERVER.uri("/annotations/{userId}/users/list2", controller)
            .action("createWithApiModelRequest", HttpMethod.POST).method(HttpMethod.POST)
            .name("Create with Implicit Params");

    new SwaggerPlugin().apiVersion("1.0").swaggerVersion("1.2").flag("flag1").flag("flag2")
            .parameter("parm1", "value1").parameter("parm2", "value2").register(SERVER);

    SERVER.bind(PORT);
}

From source file:com.titilink.camel.rest.client.CamelClient.java

License:LGPL

/**
 * delete/*from  w ww .  j  a  v  a2s.c om*/
 *
 * @param uri               
 * @param additionalHeaders header????token 
 * @param challengeResponse
 * @param msTimeout         ?0?10s
 * @return
 */
public static RestResponse handleDelete(URI uri, Map<String, String> additionalHeaders,
        ChallengeResponse challengeResponse, long msTimeout) {
    return handle(HttpMethod.DELETE, uri, null, additionalHeaders, challengeResponse, true, msTimeout);
}