Java 类org.apache.http.client.methods.HttpPatch 实例源码

项目:datarouter    文件:DatarouterHttpRequest.java   
private HttpRequestBase getRequest(String url){
    switch(method){
    case DELETE:
        return new HttpDelete(url);
    case GET:
        return new HttpGet(url);
    case HEAD:
        return new HttpHead(url);
    case PATCH:
        return new HttpPatch(url);
    case POST:
        return new HttpPost(url);
    case PUT:
        return new HttpPut(url);
    default:
        throw new IllegalArgumentException("Invalid or null HttpMethod: " + method);
    }
}
项目:aws-sdk-java-v2    文件:ApacheHttpRequestFactory.java   
private HttpRequestBase createApacheRequest(SdkHttpFullRequest request, String uri) {
    switch (request.method()) {
        case HEAD:
            return new HttpHead(uri);
        case GET:
            return new HttpGet(uri);
        case DELETE:
            return new HttpDelete(uri);
        case OPTIONS:
            return new HttpOptions(uri);
        case PATCH:
            return wrapEntity(request, new HttpPatch(uri));
        case POST:
            return wrapEntity(request, new HttpPost(uri));
        case PUT:
            return wrapEntity(request, new HttpPut(uri));
        default:
            throw new RuntimeException("Unknown HTTP method name: " + request.method());
    }
}
项目:elasticsearch_my    文件:RestClient.java   
private static HttpRequestBase createHttpRequest(String method, URI uri, HttpEntity entity) {
    switch(method.toUpperCase(Locale.ROOT)) {
        case HttpDeleteWithEntity.METHOD_NAME:
            return addRequestBody(new HttpDeleteWithEntity(uri), entity);
        case HttpGetWithEntity.METHOD_NAME:
            return addRequestBody(new HttpGetWithEntity(uri), entity);
        case HttpHead.METHOD_NAME:
            return addRequestBody(new HttpHead(uri), entity);
        case HttpOptions.METHOD_NAME:
            return addRequestBody(new HttpOptions(uri), entity);
        case HttpPatch.METHOD_NAME:
            return addRequestBody(new HttpPatch(uri), entity);
        case HttpPost.METHOD_NAME:
            HttpPost httpPost = new HttpPost(uri);
            addRequestBody(httpPost, entity);
            return httpPost;
        case HttpPut.METHOD_NAME:
            return addRequestBody(new HttpPut(uri), entity);
        case HttpTrace.METHOD_NAME:
            return addRequestBody(new HttpTrace(uri), entity);
        default:
            throw new UnsupportedOperationException("http method not supported: " + method);
    }
}
项目:elasticsearch_my    文件:RequestLoggerTests.java   
private static HttpUriRequest randomHttpRequest(URI uri) {
    int requestType = randomIntBetween(0, 7);
    switch(requestType) {
        case 0:
            return new HttpGetWithEntity(uri);
        case 1:
            return new HttpPost(uri);
        case 2:
            return new HttpPut(uri);
        case 3:
            return new HttpDeleteWithEntity(uri);
        case 4:
            return new HttpHead(uri);
        case 5:
            return new HttpTrace(uri);
        case 6:
            return new HttpOptions(uri);
        case 7:
            return new HttpPatch(uri);
        default:
            throw new UnsupportedOperationException();
    }
}
项目:DraytonWiser    文件:DraytonWiserConnection.java   
public void setRoomTemperature(String WEBSERVICE_URL, String AUTHTOKEN, String roomName, int newTemp) {
    try {

        // Find room ID based on name
        String roomId = getRoomID(WEBSERVICE_URL, AUTHTOKEN, roomName);

        CloseableHttpClient http = HttpClientBuilder.create().build();

        String payload = "{\"RequestOverride\":{\"Type\":\"Manual\",\"SetPoint\":" + Integer.toString(newTemp)
                + " }}";
        HttpPatch updateRequest = new HttpPatch("http://192.168.3.6/data/domain/Room/" + roomId);
        updateRequest.setEntity(new StringEntity(payload, ContentType.APPLICATION_JSON));
        updateRequest.setHeader("SECRET", AUTHTOKEN);

        HttpResponse response = http.execute(updateRequest);
        String out = response.getEntity().toString();
        logger.debug(out);

    } catch (IOException e) {
        logger.warn("Communication error occurred while getting your Drayton Wiser information: {}",
                e.getMessage());
    }
}
项目:lams    文件:HttpComponentsClientHttpRequestFactory.java   
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
    switch (httpMethod) {
        case GET:
            return new HttpGet(uri);
        case DELETE:
            return new HttpDelete(uri);
        case HEAD:
            return new HttpHead(uri);
        case OPTIONS:
            return new HttpOptions(uri);
        case POST:
            return new HttpPost(uri);
        case PUT:
            return new HttpPut(uri);
        case TRACE:
            return new HttpTrace(uri);
        case PATCH:
            return new HttpPatch(uri);
        default:
            throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
    }
}
项目:spring4-understanding    文件:HttpComponentsClientHttpRequestFactory.java   
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
    switch (httpMethod) {
        case GET:
            return new HttpGet(uri);
        case HEAD:
            return new HttpHead(uri);
        case POST:
            return new HttpPost(uri);
        case PUT:
            return new HttpPut(uri);
        case PATCH:
            return new HttpPatch(uri);
        case DELETE:
            return new HttpDelete(uri);
        case OPTIONS:
            return new HttpOptions(uri);
        case TRACE:
            return new HttpTrace(uri);
        default:
            throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
    }
}
项目:AuxiliumLib    文件:MattpRequestEnvoy.java   
private HttpUriRequest getRawMethodRequest()
{
    AbstractURL url = request.getUrl();

    switch(request.getMattpMethod())
    {
        case GET:
            return new HttpGet(url.toString());
        case HEAD:
            return new HttpHead(url.toString());
        case POST:
            return new HttpPost(url.toString());
        case PUT:
            return new HttpPut(url.toString());
        case DELETE:
            return new HttpDelete(url.toString());
        case TRACE:
            return new HttpTrace(url.toString());
        case OPTIONS:
            return new HttpOptions(url.toString());
        case PATCH:
            return new HttpPatch(url.toString());
    }

    throw new ShouldNeverHappenError();
}
项目:AuxiliumLib    文件:HttpFetch.java   
private HttpUriRequest getRequest(AbstractURL url)
{
    switch(this)
    {
        case GET:
            return new HttpGet(url.toString());
        case HEAD:
            return new HttpHead(url.toString());
        case POST:
            return new HttpPost(url.toString());
        case PUT:
            return new HttpPut(url.toString());
        case DELETE:
            return new HttpDelete(url.toString());
        case TRACE:
            return new HttpTrace(url.toString());
        case OPTIONS:
            return new HttpOptions(url.toString());
        case PATCH:
            return new HttpPatch(url.toString());
    }

    throw new ShouldNeverHappenError();
}
项目:fcrepo-api-x    文件:JenaServiceRegistry.java   
@Override
public void register(final URI uri) {
    init.await();
    try {
        LOG.debug("Registering service {} ", uri);

        final HttpPatch patch = new HttpPatch(registryContainer);
        patch.setHeader(HttpHeaders.CONTENT_TYPE, SPARQL_UPDATE);
        patch.setEntity(new InputStreamEntity(patchAddService(uri)));

        try (CloseableHttpResponse resp = execute(patch)) {
            LOG.info("Adding service {} to registry {}", uri, registryContainer);
        }
    } catch (final Exception e) {
        throw new RuntimeException(String.format("Could not add <%s> to service registry <%s>", uri,
                registryContainer), e);
    }

    update(uri);
}
项目:product-ei    文件:ODataTestUtils.java   
public static int sendPATCH(String endpoint, String content, Map<String, String> headers) throws IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPatch httpPatch = new HttpPatch(endpoint);
    for (String headerType : headers.keySet()) {
        httpPatch.setHeader(headerType, headers.get(headerType));
    }
    if (null != content) {
        HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8"));
        if (headers.get("Content-Type") == null) {
            httpPatch.setHeader("Content-Type", "application/json");
        }
        httpPatch.setEntity(httpEntity);
    }
    HttpResponse httpResponse = httpClient.execute(httpPatch);
    return httpResponse.getStatusLine().getStatusCode();
}
项目:vespa    文件:JDiscHttpServletTest.java   
@Test
public void requireThatServerRespondsToAllMethods() throws Exception {
    final TestDriver driver = TestDrivers.newInstance(newEchoHandler());
    final URI uri = driver.client().newUri("/status.html");
    driver.client().execute(new HttpGet(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpPost(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpHead(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpPut(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpDelete(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpOptions(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpTrace(uri))
          .expectStatusCode(is(OK));
    driver.client().execute(new HttpPatch(uri))
            .expectStatusCode(is(OK));
    assertThat(driver.close(), is(true));
}
项目:fahrschein    文件:HttpComponentsRequestFactory.java   
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param method the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
private static HttpUriRequest createHttpUriRequest(String method, URI uri) {
    switch (method) {
        case "GET":
            return new HttpGet(uri);
        case "HEAD":
            return new HttpHead(uri);
        case "POST":
            return new HttpPost(uri);
        case "PUT":
            return new HttpPut(uri);
        case "PATCH":
            return new HttpPatch(uri);
        case "DELETE":
            return new HttpDelete(uri);
        case "OPTIONS":
            return new HttpOptions(uri);
        case "TRACE":
            return new HttpTrace(uri);
        default:
            throw new IllegalArgumentException("Invalid HTTP method: " + method);
    }
}
项目:here-aaa-java-sdk    文件:ApacheHttpClientProviderTest.java   
@Test
public void test_methods() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException {
    verifyApacheType("GET", HttpGet.class);
    verifyApacheType("POST", HttpPost.class);
    verifyApacheType("PUT", HttpPut.class);
    verifyApacheType("DELETE", HttpDelete.class);
    verifyApacheType("HEAD", HttpHead.class);
    verifyApacheType("OPTIONS", HttpOptions.class);
    verifyApacheType("TRACE", HttpTrace.class);
    verifyApacheType("PATCH", HttpPatch.class);
    try {
        verifyApacheType("BROKENMETHOD", null);
        fail("BROKENMETHOD should have thrown IllegalArgumentException, but didn't");
    } catch (IllegalArgumentException e) {
        // expected
        String message = e.getMessage();
        String expectedContains = "no support for request method=BROKENMETHOD";
        assertTrue("expected contains "+expectedContains+", actual "+message, message.contains(expectedContains));
    }
}
项目:PrintNode-Java    文件:APIClient.java   
/**
 * Given an Account object, modifies an account.
 * This can only be used when a child account is specified by email, id or creatorRef.
 *
 * @param accountInfo account object. Requires atleast one value set.
 * Having id set will throw an exception, unless set to -1.
 * @return Whoami object of the modified account.
 * @throws IOException if HTTP client is given bad values
 * @see Account
 * @see Whoami
 * */
public final Whoami modifyAccount(final Account accountInfo) throws IOException {
    CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credentials).build();
    Whoami account;
    try {
        HttpPatch httppost = new HttpPatch(apiUrl + "/account/");
        httppost.addHeader(childHeaders[0], childHeaders[1]);
        httppost.addHeader("Content-Type", "application/json");
        Gson gson = gsonWithAdapters();
        String json = gson.toJson(accountInfo);
        StringEntity jsonEntity = new StringEntity(json);
        httppost.setEntity(jsonEntity);
        CloseableHttpResponse response = client.execute(httppost);
        try {
            JsonObject responseParse = responseToJsonElement(response).getAsJsonObject();
            account = new Whoami(responseParse);
        } finally {
            response.close();
        }
    } finally {
        client.close();
    }
    return account;
}
项目:hapi-fhir    文件:PatchDstu3Test.java   
@Test
public void testPatchValidJson() throws Exception {
    String requestContents = "[ { \"op\": \"add\", \"path\": \"/a/b/c\", \"value\": [ \"foo\", \"bar\" ] } ]";
    HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
    httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse(Constants.CT_JSON_PATCH)));
    CloseableHttpResponse status = ourClient.execute(httpPatch);

    try {
        String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
        ourLog.info(responseContent);
        assertEquals(200, status.getStatusLine().getStatusCode());
        assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><text><div xmlns=\"http://www.w3.org/1999/xhtml\">OK</div></text></OperationOutcome>", responseContent);
    } finally {
        IOUtils.closeQuietly(status.getEntity().getContent());
    }

    assertEquals("patientPatch", ourLastMethod);
    assertEquals("Patient/123", ourLastId.getValue());
    assertEquals(requestContents, ourLastBody);
    assertEquals(PatchTypeEnum.JSON_PATCH, ourLastPatchType);
}
项目:hapi-fhir    文件:PatchDstu3Test.java   
@Test
public void testPatchValidXml() throws Exception {
    String requestContents = "<root/>";
    HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
    httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse(Constants.CT_XML_PATCH)));
    CloseableHttpResponse status = ourClient.execute(httpPatch);

    try {
        String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
        ourLog.info(responseContent);
        assertEquals(200, status.getStatusLine().getStatusCode());
        assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><text><div xmlns=\"http://www.w3.org/1999/xhtml\">OK</div></text></OperationOutcome>", responseContent);
    } finally {
        IOUtils.closeQuietly(status.getEntity().getContent());
    }

    assertEquals("patientPatch", ourLastMethod);
    assertEquals("Patient/123", ourLastId.getValue());
    assertEquals(requestContents, ourLastBody);
    assertEquals(PatchTypeEnum.XML_PATCH, ourLastPatchType);
}
项目:hapi-fhir    文件:PatchDstu3Test.java   
@Test
public void testPatchValidJsonWithCharset() throws Exception {
    String requestContents = "[ { \"op\": \"add\", \"path\": \"/a/b/c\", \"value\": [ \"foo\", \"bar\" ] } ]";
    HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
    httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse(Constants.CT_JSON_PATCH + Constants.CHARSET_UTF8_CTSUFFIX)));
    CloseableHttpResponse status = ourClient.execute(httpPatch);

    try {
        String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
        ourLog.info(responseContent);
        assertEquals(200, status.getStatusLine().getStatusCode());
    } finally {
        IOUtils.closeQuietly(status.getEntity().getContent());
    }

    assertEquals("patientPatch", ourLastMethod);
    assertEquals("Patient/123", ourLastId.getValue());
    assertEquals(requestContents, ourLastBody);
}
项目:hapi-fhir    文件:PatchDstu3Test.java   
@Test
public void testPatchInvalidMimeType() throws Exception {
    String requestContents = "[ { \"op\": \"add\", \"path\": \"/a/b/c\", \"value\": [ \"foo\", \"bar\" ] } ]";
    HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
    httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse("text/plain; charset=UTF-8")));
    CloseableHttpResponse status = ourClient.execute(httpPatch);

    try {
        String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
        ourLog.info(responseContent);
        assertEquals(400, status.getStatusLine().getStatusCode());
        assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><issue><severity value=\"error\"/><code value=\"processing\"/><diagnostics value=\"Invalid Content-Type for PATCH operation: text/plain; charset=UTF-8\"/></issue></OperationOutcome>", responseContent);
    } finally {
        IOUtils.closeQuietly(status.getEntity().getContent());
    }

}
项目:hapi-fhir    文件:PatchDstu2_1Test.java   
@Test
public void testPatchValidJson() throws Exception {
    String requestContents = "[ { \"op\": \"add\", \"path\": \"/a/b/c\", \"value\": [ \"foo\", \"bar\" ] } ]";
    HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
    httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse(Constants.CT_JSON_PATCH)));
    CloseableHttpResponse status = ourClient.execute(httpPatch);

    try {
        String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
        ourLog.info(responseContent);
        assertEquals(200, status.getStatusLine().getStatusCode());
        assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><text><div xmlns=\"http://www.w3.org/1999/xhtml\">OK</div></text></OperationOutcome>", responseContent);
    } finally {
        IOUtils.closeQuietly(status.getEntity().getContent());
    }

    assertEquals("patientPatch", ourLastMethod);
    assertEquals("Patient/123", ourLastId.getValue());
    assertEquals(requestContents, ourLastBody);
    assertEquals(PatchTypeEnum.JSON_PATCH, ourLastPatchType);
}
项目:hapi-fhir    文件:PatchDstu2_1Test.java   
@Test
public void testPatchValidXml() throws Exception {
    String requestContents = "<root/>";
    HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
    httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse(Constants.CT_XML_PATCH)));
    CloseableHttpResponse status = ourClient.execute(httpPatch);

    try {
        String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
        ourLog.info(responseContent);
        assertEquals(200, status.getStatusLine().getStatusCode());
        assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><text><div xmlns=\"http://www.w3.org/1999/xhtml\">OK</div></text></OperationOutcome>", responseContent);
    } finally {
        IOUtils.closeQuietly(status.getEntity().getContent());
    }

    assertEquals("patientPatch", ourLastMethod);
    assertEquals("Patient/123", ourLastId.getValue());
    assertEquals(requestContents, ourLastBody);
    assertEquals(PatchTypeEnum.XML_PATCH, ourLastPatchType);
}
项目:hapi-fhir    文件:PatchDstu2_1Test.java   
@Test
public void testPatchValidJsonWithCharset() throws Exception {
    String requestContents = "[ { \"op\": \"add\", \"path\": \"/a/b/c\", \"value\": [ \"foo\", \"bar\" ] } ]";
    HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
    httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse(Constants.CT_JSON_PATCH + Constants.CHARSET_UTF8_CTSUFFIX)));
    CloseableHttpResponse status = ourClient.execute(httpPatch);

    try {
        String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
        ourLog.info(responseContent);
        assertEquals(200, status.getStatusLine().getStatusCode());
    } finally {
        IOUtils.closeQuietly(status.getEntity().getContent());
    }

    assertEquals("patientPatch", ourLastMethod);
    assertEquals("Patient/123", ourLastId.getValue());
    assertEquals(requestContents, ourLastBody);
}
项目:hapi-fhir    文件:PatchDstu2_1Test.java   
@Test
public void testPatchInvalidMimeType() throws Exception {
    String requestContents = "[ { \"op\": \"add\", \"path\": \"/a/b/c\", \"value\": [ \"foo\", \"bar\" ] } ]";
    HttpPatch httpPatch = new HttpPatch("http://localhost:" + ourPort + "/Patient/123");
    httpPatch.setEntity(new StringEntity(requestContents, ContentType.parse("text/plain; charset=UTF-8")));
    CloseableHttpResponse status = ourClient.execute(httpPatch);

    try {
        String responseContent = IOUtils.toString(status.getEntity().getContent(), StandardCharsets.UTF_8);
        ourLog.info(responseContent);
        assertEquals(400, status.getStatusLine().getStatusCode());
        assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><issue><severity value=\"error\"/><code value=\"processing\"/><diagnostics value=\"Invalid Content-Type for PATCH operation: text/plain; charset=UTF-8\"/></issue></OperationOutcome>", responseContent);
    } finally {
        IOUtils.closeQuietly(status.getEntity().getContent());
    }

}
项目:detective    文件:HttpClientTask.java   
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
  switch (httpMethod) {
    case GET:
      return new HttpGet(uri);
    case DELETE:
      return new HttpDeleteWithBody(uri);
    case HEAD:
      return new HttpHead(uri);
    case OPTIONS:
      return new HttpOptions(uri);
    case POST:
      return new HttpPost(uri);
    case PUT:
      return new HttpPut(uri);
    case TRACE:
      return new HttpTrace(uri);
    case PATCH:
      return new HttpPatch(uri);
    default:
      throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
  }
}
项目:class-guard    文件:HttpComponentsClientHttpRequestFactory.java   
/**
 * Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
 * @param httpMethod the HTTP method
 * @param uri the URI
 * @return the Commons HttpMethodBase object
 */
protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
    switch (httpMethod) {
        case GET:
            return new HttpGet(uri);
        case DELETE:
            return new HttpDelete(uri);
        case HEAD:
            return new HttpHead(uri);
        case OPTIONS:
            return new HttpOptions(uri);
        case POST:
            return new HttpPost(uri);
        case PUT:
            return new HttpPut(uri);
        case TRACE:
            return new HttpTrace(uri);
        case PATCH:
            return new HttpPatch(uri);
        default:
            throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
    }
}
项目:camunda-connect    文件:HttpRequestTest.java   
@Test
public void setHttpMethod() {
  HttpRequest request = connector.createRequest().get();
  assertThat(request.getMethod()).isEqualTo(HttpGet.METHOD_NAME);

  request = connector.createRequest().post();
  assertThat(request.getMethod()).isEqualTo(HttpPost.METHOD_NAME);

  request = connector.createRequest().put();
  assertThat(request.getMethod()).isEqualTo(HttpPut.METHOD_NAME);

  request = connector.createRequest().delete();
  assertThat(request.getMethod()).isEqualTo(HttpDelete.METHOD_NAME);

  request = connector.createRequest().patch();
  assertThat(request.getMethod()).isEqualTo(HttpPatch.METHOD_NAME);

  request = connector.createRequest().head();
  assertThat(request.getMethod()).isEqualTo(HttpHead.METHOD_NAME);

  request = connector.createRequest().options();
  assertThat(request.getMethod()).isEqualTo(HttpOptions.METHOD_NAME);

  request = connector.createRequest().trace();
  assertThat(request.getMethod()).isEqualTo(HttpTrace.METHOD_NAME);
}
项目:ldp4j    文件:ServerFrontendITest.java   
@Test
@Category({
    ExceptionPath.class
})
@OperateOnDeployment(DEPLOYMENT)
public void testNoPatchSupport(@ArquillianResource final URL url) throws Exception {
    LOGGER.info("Started {}",testName.getMethodName());
    HELPER.base(url);
    HELPER.setLegacy(false);

    HttpPatch patch = HELPER.newRequest(MyApplication.ROOT_PERSON_CONTAINER_PATH,HttpPatch.class);
    patch.setEntity(
        new StringEntity(
            TEST_SUITE_BODY,
            ContentType.create("text/turtle", "UTF-8"))
    );
    Metadata patchResponse=HELPER.httpRequest(patch);
    assertThat(patchResponse.status,equalTo(HttpStatus.SC_METHOD_NOT_ALLOWED));
    assertThat(patchResponse.body,notNullValue());
    assertThat(patchResponse.contentType,startsWith("text/plain"));
    assertThat(patchResponse.language,equalTo(Locale.ENGLISH));
}
项目:iot-java    文件:APIClient.java   
private HttpResponse casePatchFromConnect(List<NameValuePair> queryParameters, String url, String method, StringEntity input, String encodedString) throws URISyntaxException, IOException {
    URIBuilder putBuilder = new URIBuilder(url);
    if(queryParameters != null) {
        putBuilder.setParameters(queryParameters);
    }
    HttpPatch patch = new HttpPatch(putBuilder.build());
    patch.setEntity(input);
    patch.addHeader("Content-Type", "application/json");
    patch.addHeader("Accept", "application/json");
    patch.addHeader("Authorization", "Basic " + encodedString);
    try {
        HttpClient client = HttpClientBuilder.create().useSystemProperties().setSslcontext(sslContext).build();
        return client.execute(patch);
    } catch (IOException e) {
        LoggerUtility.warn(CLASS_NAME, method, e.getMessage());
        throw e;
    } 

}
项目:product-dss    文件:ODataTestUtils.java   
public static int sendPATCH(String endpoint, String content, Map<String, String> headers) throws IOException {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPatch httpPatch = new HttpPatch(endpoint);
    for (String headerType : headers.keySet()) {
        httpPatch.setHeader(headerType, headers.get(headerType));
    }
    if (null != content) {
        HttpEntity httpEntity = new ByteArrayEntity(content.getBytes("UTF-8"));
        if (headers.get("Content-Type") == null) {
            httpPatch.setHeader("Content-Type", "application/json");
        }
        httpPatch.setEntity(httpEntity);
    }
    HttpResponse httpResponse = httpClient.execute(httpPatch);
    return httpResponse.getStatusLine().getStatusCode();
}
项目:cloudstack    文件:BrocadeVcsApi.java   
protected HttpRequestBase createMethod(String type, String uri) throws BrocadeVcsApiException {
    String url;
    try {
        url = new URL(Constants.PROTOCOL, _host, Constants.PORT, uri).toString();
    } catch (final MalformedURLException e) {
        s_logger.error("Unable to build Brocade Switch API URL", e);
        throw new BrocadeVcsApiException("Unable to build Brocade Switch API URL", e);
    }

    if ("post".equalsIgnoreCase(type)) {
        return new HttpPost(url);
    } else if ("get".equalsIgnoreCase(type)) {
        return new HttpGet(url);
    } else if ("delete".equalsIgnoreCase(type)) {
        return new HttpDelete(url);
    } else if ("patch".equalsIgnoreCase(type)) {
        return new HttpPatch(url);
    } else {
        throw new BrocadeVcsApiException("Requesting unknown method type");
    }
}
项目:cloudstack    文件:BrocadeVcsApiTest.java   
@Test
public void testCreateNetwork() throws BrocadeVcsApiException, IOException {
    // Prepare

    method = mock(HttpPatch.class);

    response = mock(HttpResponse.class);
    final StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
    when(response.getStatusLine()).thenReturn(statusLine);

    // Execute
    api.createNetwork(VLAN_ID, NETWORK_ID);

    // Assert
    verify(method, times(6)).releaseConnection();
    assertEquals("Wrong URI for Network creation REST service", Constants.URI, uri);
    assertEquals("Wrong HTTP method for Network creation REST service", "patch", type);
}
项目:cloudstack    文件:BrocadeVcsApiTest.java   
@Test
public void testDeleteNetwork() throws BrocadeVcsApiException, IOException {
    // Prepare

    method = mock(HttpPatch.class);

    response = mock(HttpResponse.class);
    final StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
    when(response.getStatusLine()).thenReturn(statusLine);

    // Execute
    api.deleteNetwork(VLAN_ID, NETWORK_ID);

    // Assert
    verify(method, times(3)).releaseConnection();
    assertEquals("Wrong URI for Network creation REST service", Constants.URI, uri);
    assertEquals("Wrong HTTP method for Network creation REST service", "patch", type);
}
项目:cloudstack    文件:BrocadeVcsApiTest.java   
@Test
public void testAssociateMacToNetwork() throws BrocadeVcsApiException, IOException {
    // Prepare

    method = mock(HttpPatch.class);

    response = mock(HttpResponse.class);
    final StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
    when(response.getStatusLine()).thenReturn(statusLine);

    // Execute
    api.associateMacToNetwork(NETWORK_ID, MAC_ADDRESS_32);

    // Assert
    verify(method, times(1)).releaseConnection();
    assertEquals("Wrong URI for Network creation REST service", Constants.URI, uri);
    assertEquals("Wrong HTTP method for Network creation REST service", "patch", type);
}
项目:cloudstack    文件:BrocadeVcsApiTest.java   
@Test
public void testDisassociateMacFromNetwork() throws BrocadeVcsApiException, IOException {
    // Prepare

    method = mock(HttpPatch.class);

    response = mock(HttpResponse.class);
    final StatusLine statusLine = mock(StatusLine.class);
    when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
    when(response.getStatusLine()).thenReturn(statusLine);

    // Execute
    api.disassociateMacFromNetwork(NETWORK_ID, MAC_ADDRESS_32);

    // Assert
    verify(method, times(1)).releaseConnection();
    assertEquals("Wrong URI for Network creation REST service", Constants.URI, uri);
    assertEquals("Wrong HTTP method for Network creation REST service", "patch", type);
}
项目:ZombieLink    文件: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
 *          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();
    }
}
项目:pagerDutySynchronizer    文件:DefaultStatusPageIODao.java   
/**
 * Calls a http Patch with given {@link URI} and returns the response.
 * 
 * @param uri
 * @return
 */
@VisibleForTesting
String doPatchRequest(URI uri) {
   CloseableHttpClient httpclient = null;
   CloseableHttpResponse response = null;
   String responseAsString = "";
   try {
      httpclient = HttpClients.createDefault();
      HttpPatch httpPatch = new HttpPatch(uri);
      httpPatch.addHeader("Content-type", "application/json");
      httpPatch.addHeader("Authorization", statuspageApiKey);
      response = httpclient.execute(httpPatch);
      responseAsString = IOUtils.toString(response.getEntity().getContent());
   } catch (Exception e) {
      logger.error(e.getMessage(), e);
   } finally {
      IOUtils.closeQuietly(httpclient);
      IOUtils.closeQuietly(response);
   }

   return responseAsString;
}
项目:fcrepo4    文件:WebACRecipesIT.java   
@Test
public void testInvalidAccessControlLink() throws IOException {
    final String id = "/rest/" + getRandomUniqueId();
    ingestObj(id);

    final HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "fedoraAdmin");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity(
            "INSERT { <> <" + WEBAC_ACCESS_CONTROL_VALUE + "> \"/rest/acl/badAclLink\" . } WHERE {}"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));

    final HttpGet getReq = getObjMethod(id);
    setAuth(getReq, "fedoraAdmin");
    assertEquals("Non-URI accessControl property did not throw Exception", HttpStatus.SC_BAD_REQUEST,
            getStatus(getReq));
}
项目:fcrepo4    文件:WebACRecipesIT.java   
@Test
public void testRegisterNamespace() throws IOException {
    final String testObj = ingestObj("/rest/test_namespace");
    final String acl1 = ingestAcl("fedoraAdmin", "/acls/13/acl.ttl", "/acls/13/authorization.ttl");
    linkToAcl(testObj, acl1);

    final String id = "/rest/test_namespace/" + getRandomUniqueId();
    ingestObj(id);

    final HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "user13");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity("PREFIX novel: <info://" + getRandomUniqueId() + ">\n"
            + "INSERT DATA { <> novel:value 'test' }"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));
}
项目:fcrepo4    文件:WebACRecipesIT.java   
@Test
public void testRegisterNodeType() throws IOException {
    final String testObj = ingestObj("/rest/test_nodetype");
    final String acl1 = ingestAcl("fedoraAdmin", "/acls/14/acl.ttl", "/acls/14/authorization.ttl");
    linkToAcl(testObj, acl1);

    final String id = "/rest/test_nodetype/" + getRandomUniqueId();
    ingestObj(id);

    final HttpPatch patchReq = patchObjMethod(id);
    setAuth(patchReq, "user14");
    patchReq.addHeader("Content-type", "application/sparql-update");
    patchReq.setEntity(new StringEntity("PREFIX dc: <http://purl.org/dc/elements/1.1/>\n"
            + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            + "INSERT DATA { <> rdf:type dc:type }"));
    assertEquals(HttpStatus.SC_NO_CONTENT, getStatus(patchReq));
}