Example usage for org.apache.http.client.methods HttpPatch HttpPatch

List of usage examples for org.apache.http.client.methods HttpPatch HttpPatch

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpPatch HttpPatch.

Prototype

public HttpPatch() 

Source Link

Usage

From source file:com.github.yongchristophertang.engine.web.request.TestRequestBuilders.java

/**
 * Create a {@link HttpRequestBuilders} for a PATCH request.
 *
 * @param urlTemplate  a URL template; the resulting URL will be encoded
 * @param urlVariables zero or more URL variables
 *///from  www.j  a  v a 2  s  .  c  o m
public static HttpRequestBuilders patch(String urlTemplate, Object... urlVariables) {
    return new HttpRequestBuilders(new HttpPatch(), urlTemplate, "PATCH Request", urlVariables);
}

From source file:net.javacrumbs.restfire.httpcomponents.HttpComponentsRequestFactory.java

public RequestBuilder patch() {
    return createRequestBuilder(new HttpPatch());
}

From source file:com.github.grantjforrester.bdd.rest.httpclient.HttpClientRequest.java

HttpRequestBase getRequestImpl(URI baseUri) {
    HttpRequestBase request = null;/*from   w  w w  . ja  v  a  2s .com*/

    switch (method) {
    case HEAD:
        request = new HttpHead();
        break;
    case OPTIONS:
        request = new HttpOptions();
        break;
    case GET:
        request = new HttpGet();
        break;
    case POST:
        request = new HttpPost();
        break;
    case PUT:
        request = new HttpPut();
        break;
    case DELETE:
        request = new HttpDelete();
        break;
    case PATCH:
        request = new HttpPatch();
    }

    request.setURI(baseUri.resolve(uri));
    request.setHeaders(headers.toArray(new Header[headers.size()]));
    if (content != null) {
        ((HttpEntityEnclosingRequest) request).setEntity(new ByteArrayEntity(content));
    }

    return request;
}

From source file:com.sap.core.odata.fit.ref.AbstractRefTest.java

protected HttpResponse callUri(final ODataHttpMethod httpMethod, final String uri,
        final String additionalHeader, final String additionalHeaderValue, final String requestBody,
        final String requestContentType, final HttpStatusCodes expectedStatusCode) throws Exception {

    HttpRequestBase request = httpMethod == ODataHttpMethod.GET ? new HttpGet()
            : httpMethod == ODataHttpMethod.DELETE ? new HttpDelete()
                    : httpMethod == ODataHttpMethod.POST ? new HttpPost()
                            : httpMethod == ODataHttpMethod.PUT ? new HttpPut() : new HttpPatch();
    request.setURI(URI.create(getEndpoint() + uri));
    if (additionalHeader != null) {
        request.addHeader(additionalHeader, additionalHeaderValue);
    }//from w  w  w  .j a va2  s.  c o  m
    if (requestBody != null) {
        ((HttpEntityEnclosingRequest) request).setEntity(new StringEntity(requestBody));
        request.setHeader(HttpHeaders.CONTENT_TYPE, requestContentType);
    }

    final HttpResponse response = getHttpClient().execute(request);

    assertNotNull(response);
    assertEquals(expectedStatusCode.getStatusCode(), response.getStatusLine().getStatusCode());

    if (expectedStatusCode == HttpStatusCodes.OK) {
        assertNotNull(response.getEntity());
        assertNotNull(response.getEntity().getContent());
    } else if (expectedStatusCode == HttpStatusCodes.CREATED) {
        assertNotNull(response.getEntity());
        assertNotNull(response.getEntity().getContent());
        assertNotNull(response.getFirstHeader(HttpHeaders.LOCATION));
    } else if (expectedStatusCode == HttpStatusCodes.NO_CONTENT) {
        assertTrue(response.getEntity() == null || response.getEntity().getContent() == null);
    }

    return response;
}

From source file:com.lonepulse.zombielink.request.RequestUtils.java

/**
 * <p>Retrieves the proper extension of {@link HttpRequestBase} for the given {@link InvocationContext}. 
 * This implementation is solely dependent upon the {@link RequestMethod} property in the annotated 
 * metdata of the endpoint method definition.</p>
 *
 * @param context/* w w w.j  a  va2 s  . c  o  m*/
 *          the {@link InvocationContext} for which a {@link HttpRequestBase} is to be generated 
 * <br><br>
 * @return the {@link HttpRequestBase} translated from the {@link InvocationContext}'s {@link RequestMethod}
 * <br><br>
 * @throws NullPointerException
 *          if the supplied {@link InvocationContext} was {@code null} 
 * <br><br>
 * @since 1.3.0
 */
static HttpRequestBase translateRequestMethod(InvocationContext context) {

    RequestMethod requestMethod = Metadata.findMethod(assertNotNull(context).getRequest());

    switch (requestMethod) {

    case POST:
        return new HttpPost();
    case PUT:
        return new HttpPut();
    case PATCH:
        return new HttpPatch();
    case DELETE:
        return new HttpDelete();
    case HEAD:
        return new HttpHead();
    case TRACE:
        return new HttpTrace();
    case OPTIONS:
        return new HttpOptions();

    case GET:
    default:
        return new HttpGet();
    }
}

From source file:com.mirth.connect.client.core.ServerConnection.java

private HttpRequestBase createRequestBase(String method) {
    HttpRequestBase requestBase = null;//from  w w w .  j a  v  a2s  .co m

    if (StringUtils.equalsIgnoreCase(HttpGet.METHOD_NAME, method)) {
        requestBase = new HttpGet();
    } else if (StringUtils.equalsIgnoreCase(HttpPost.METHOD_NAME, method)) {
        requestBase = new HttpPost();
    } else if (StringUtils.equalsIgnoreCase(HttpPut.METHOD_NAME, method)) {
        requestBase = new HttpPut();
    } else if (StringUtils.equalsIgnoreCase(HttpDelete.METHOD_NAME, method)) {
        requestBase = new HttpDelete();
    } else if (StringUtils.equalsIgnoreCase(HttpOptions.METHOD_NAME, method)) {
        requestBase = new HttpOptions();
    } else if (StringUtils.equalsIgnoreCase(HttpPatch.METHOD_NAME, method)) {
        requestBase = new HttpPatch();
    }

    requestBase.setConfig(requestConfig);
    return requestBase;
}

From source file:io.restassured.internal.http.HTTPBuilder.java

/**
 * <p>//from  w  ww  .j  ava 2s . co m
 * Convenience method to perform an HTTP form PATCH.  The response closure will be
 * called only on a successful response.</p>
 * <p>
 * <p>A 'failed' response (i.e. any
 * HTTP status code > 399) will be handled by the registered 'failure'
 * handler.  The {@link #defaultFailureHandler(HttpResponseDecorator) default
 * failure handler} throws an {@link HttpResponseException}.</p>
 * <p>
 * <p>The request body (specified by a <code>body</code> named parameter)
 * will be converted to a url-encoded form string unless a different
 * <code>requestContentType</code> named parameter is passed to this method.
 * (See {@link EncoderRegistry#encodeForm(Map)}.) </p>
 *
 * @param args            see {@link RequestConfigDelegate#setPropertiesFromMap(Map)}
 * @param responseClosure code to handle a successful HTTP response
 * @return any value returned by the response closure.
 * @throws ClientProtocolException
 * @throws IOException
 * @throws URISyntaxException      if a uri argument is given which does not
 *                                 represent a valid URI
 */
public Object patch(Map<String, ?> args, Closure responseClosure)
        throws URISyntaxException, ClientProtocolException, IOException {
    RequestConfigDelegate delegate = new RequestConfigDelegate(new HttpPatch(), this.defaultContentType,
            this.defaultRequestHeaders, this.defaultResponseHandlers);

    /* by default assume the request body will be URLEncoded, but allow
     the 'requestContentType' named argument to override this if it is
     given */
    delegate.setRequestContentType(ContentType.URLENC.toString());
    delegate.setPropertiesFromMap(args);

    if (responseClosure != null) {
        delegate.getResponse().put(Status.SUCCESS.toString(), responseClosure);
        delegate.getResponse().put(Status.FAILURE.toString(), responseClosure);
    }

    return this.doRequest(delegate);
}