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:org.elasticsearch.http.nio.NioHttpRequest.java

License:Apache License

@Override
public RestRequest.Method method() {
    HttpMethod httpMethod = request.method();
    if (httpMethod == HttpMethod.GET)
        return RestRequest.Method.GET;

    if (httpMethod == HttpMethod.POST)
        return RestRequest.Method.POST;

    if (httpMethod == HttpMethod.PUT)
        return RestRequest.Method.PUT;

    if (httpMethod == HttpMethod.DELETE)
        return RestRequest.Method.DELETE;

    if (httpMethod == HttpMethod.HEAD) {
        return RestRequest.Method.HEAD;
    }//from w  ww  .j  ava 2s  . c o  m

    if (httpMethod == HttpMethod.OPTIONS) {
        return RestRequest.Method.OPTIONS;
    }

    if (httpMethod == HttpMethod.PATCH) {
        return RestRequest.Method.PATCH;
    }

    if (httpMethod == HttpMethod.TRACE) {
        return RestRequest.Method.TRACE;
    }

    if (httpMethod == HttpMethod.CONNECT) {
        return RestRequest.Method.CONNECT;
    }

    throw new IllegalArgumentException("Unexpected http method: " + httpMethod);
}

From source file:org.iotivity.cloud.base.protocols.http.HCProxyProcessor.java

License:Open Source License

/**
 * This function returns a message created by the request,
 * which implements IRequest(used in the cloud)
 * translated from the HTTP request./*from  w w w .  j a  v  a2s.com*/
 * 
 * @return requestMessage
 */
public Message getRequestMessage() {

    Message requestMessage = null;

    String coapUriPath = mTargetCoapPath;
    String coapUriQuery = mTargetCoapQuery;
    ContentFormat coapContentFormat = null;
    if (mContentFormat != null) {
        if (mContentFormat.equalsIgnoreCase(APPLICATION_CBOR)) {
            coapContentFormat = ContentFormat.APPLICATION_CBOR;
        }
    }
    byte[] coapPayload = mCborContent;

    if (mHttpMethod == HttpMethod.POST) {

        CoapRequest coapRequest = new CoapRequest(RequestMethod.POST);
        coapRequest.setToken(createToken());
        coapRequest.setUriPath(coapUriPath);
        if (coapUriQuery != null) {
            coapRequest.setUriQuery(coapUriQuery);
        }
        if (coapPayload != null) {
            coapRequest.setContentFormat(coapContentFormat);
            coapRequest.setPayload(coapPayload);
        }
        requestMessage = coapRequest;

    } else if (mHttpMethod == HttpMethod.PUT) {

        CoapRequest coapRequest = new CoapRequest(RequestMethod.PUT);
        coapRequest.setToken(createToken());
        coapRequest.setUriPath(coapUriPath);
        if (coapUriQuery != null) {
            coapRequest.setUriQuery(coapUriQuery);
        }
        if (coapPayload != null) {
            coapRequest.setContentFormat(coapContentFormat);
            coapRequest.setPayload(coapPayload);
        }
        requestMessage = coapRequest;

    } else if (mHttpMethod == HttpMethod.GET) {

        CoapRequest coapRequest = new CoapRequest(RequestMethod.GET);
        coapRequest.setToken(createToken());
        coapRequest.setUriPath(coapUriPath);
        if (coapUriQuery != null) {
            coapRequest.setUriQuery(coapUriQuery);
        }
        requestMessage = coapRequest;

    } else if (mHttpMethod == HttpMethod.DELETE) {

        CoapRequest coapRequest = new CoapRequest(RequestMethod.DELETE);
        coapRequest.setToken(createToken());
        coapRequest.setUriPath(coapUriPath);
        if (coapUriQuery != null) {
            coapRequest.setUriQuery(coapUriQuery);
        }
        requestMessage = coapRequest;
    }

    return requestMessage;
}

From source file:org.iotivity.cloud.base.protocols.proxy.CoapHttpProxyHandler.java

License:Open Source License

CoapRequest httpRequestToCoAPRequest(String uri, HttpRequest httpRequest) {
    CoapRequest coapRequest;/* w ww  . j a  va  2 s . com*/

    // TODO: coapRequest converter required
    // coapRequest.getOptions().setUriQuery();
    if (httpRequest.getMethod() == HttpMethod.GET) {
        coapRequest = new CoapRequest(CoapMethod.GET);
    } else if (httpRequest.getMethod() == HttpMethod.PUT) {
        coapRequest = new CoapRequest(CoapMethod.PUT);
    } else if (httpRequest.getMethod() == HttpMethod.POST) {
        coapRequest = new CoapRequest(CoapMethod.POST);
    } else if (httpRequest.getMethod() == HttpMethod.DELETE) {
        coapRequest = new CoapRequest(CoapMethod.DELETE);
    } else {
        throw new IllegalArgumentException();
    }

    coapRequest.setUriPath(uri);

    return coapRequest;
}

From source file:org.nosceon.titanite.ControllersTest.java

License:Apache License

@Test
public void test() {
    given().expect().statusCode(200).body(equalTo(HttpMethod.GET.name())).when().get(uri("/a"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.POST.name())).when().post(uri("/a"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PUT.name())).when().put(uri("/a"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.DELETE.name())).when().delete(uri("/a"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PATCH.name())).when().patch(uri("/a"));

    given().expect().statusCode(200).body(equalTo(HttpMethod.GET.name())).when().get(uri("/b"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.POST.name())).when().post(uri("/b"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PUT.name())).when().put(uri("/b"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.DELETE.name())).when().delete(uri("/b"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PATCH.name())).when().patch(uri("/b"));
}

From source file:org.nosceon.titanite.MethodsTest.java

License:Apache License

@Test
public void test() {
    given().expect().statusCode(200).body(equalTo(HttpMethod.GET.name())).when().get(uri("/resource"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.POST.name())).when().post(uri("/resource"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PUT.name())).when().put(uri("/resource"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.DELETE.name())).when().delete(uri("/resource"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PATCH.name())).when().patch(uri("/resource"));

    given().expect().statusCode(200).body(equalTo(HttpMethod.GET.name())).when().get(uri("/controller"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.POST.name())).when().post(uri("/controller"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PUT.name())).when().put(uri("/controller"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.DELETE.name())).when().delete(uri("/controller"));
    given().expect().statusCode(200).body(equalTo(HttpMethod.PATCH.name())).when().patch(uri("/controller"));
}

From source file:org.restexpress.pipeline.JsendWrappedResponseTest.java

License:Apache License

@Test
public void shouldWrapDeleteInJsendJson() {
    sendEvent(HttpMethod.DELETE, "/normal_delete.json", "");
    assertEquals(1, observer.getReceivedCount());
    assertEquals(1, observer.getCompleteCount());
    assertEquals(1, observer.getSuccessCount());
    assertEquals(0, observer.getExceptionCount());
    //      System.out.println(httpResponse.toString());
    assertEquals("{\"code\":200,\"status\":\"success\",\"data\":\"Normal DELETE action\"}",
            httpResponse.toString());//  w w w .  j a  v  a 2 s  . c  om
}

From source file:org.restexpress.pipeline.JsendWrappedResponseTest.java

License:Apache License

@Test
public void shouldWrapDeleteInJsendJsonUsingQueryString() {
    sendEvent(HttpMethod.DELETE, "/normal_delete?format=json", "");
    assertEquals(1, observer.getReceivedCount());
    assertEquals(1, observer.getCompleteCount());
    assertEquals(1, observer.getSuccessCount());
    assertEquals(0, observer.getExceptionCount());
    //      System.out.println(httpResponse.toString());
    assertEquals("{\"code\":200,\"status\":\"success\",\"data\":\"Normal DELETE action\"}",
            httpResponse.toString());//from   w w  w  . ja v a2  s  . c o m
}

From source file:org.restexpress.pipeline.JsendWrappedResponseTest.java

License:Apache License

@Test
public void shouldWrapDeleteInJsendXml() {
    sendEvent(HttpMethod.DELETE, "/normal_delete.xml", "");
    assertEquals(1, observer.getReceivedCount());
    assertEquals(1, observer.getCompleteCount());
    assertEquals(1, observer.getSuccessCount());
    assertEquals(0, observer.getExceptionCount());
    //      System.out.println(httpResponse.toString());
    assertTrue(httpResponse.toString().startsWith("<response>"));
    assertTrue(httpResponse.toString().contains("<code>200</code>"));
    assertTrue(httpResponse.toString().contains("<status>success</status>"));
    assertTrue(httpResponse.toString().contains("<data class=\"string\">Normal DELETE action</data>"));
    assertTrue(httpResponse.toString().endsWith("</response>"));
}

From source file:org.restexpress.pipeline.JsendWrappedResponseTest.java

License:Apache License

@Test
public void shouldWrapDeleteInJsendXmlUsingQueryString() {
    sendEvent(HttpMethod.DELETE, "/normal_delete?format=xml", "");
    assertEquals(1, observer.getReceivedCount());
    assertEquals(1, observer.getCompleteCount());
    assertEquals(1, observer.getSuccessCount());
    assertEquals(0, observer.getExceptionCount());
    //      System.out.println(httpResponse.toString());
    assertTrue(httpResponse.toString().startsWith("<response>"));
    assertTrue(httpResponse.toString().contains("<code>200</code>"));
    assertTrue(httpResponse.toString().contains("<status>success</status>"));
    assertTrue(httpResponse.toString().contains("<data class=\"string\">Normal DELETE action</data>"));
    assertTrue(httpResponse.toString().endsWith("</response>"));
}

From source file:org.restexpress.pipeline.RawWrappedResponseTest.java

License:Apache License

@Test
public void shouldWrapDeleteInRawJson() {
    sendEvent(HttpMethod.DELETE, "/normal_delete.json", "");
    assertEquals(1, observer.getReceivedCount());
    assertEquals(1, observer.getCompleteCount());
    assertEquals(1, observer.getSuccessCount());
    assertEquals(0, observer.getExceptionCount());
    //      System.out.println(httpResponse.toString());
    assertEquals("\"Normal DELETE action\"", httpResponse.toString());
}