本文整理汇总了Java中org.apache.http.client.methods.HttpPatch类的典型用法代码示例。如果您正苦于以下问题:Java HttpPatch类的具体用法?Java HttpPatch怎么用?Java HttpPatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpPatch类属于org.apache.http.client.methods包,在下文中一共展示了HttpPatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRequest
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
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);
}
}
示例2: createApacheRequest
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
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());
}
}
示例3: createHttpRequest
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
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);
}
}
示例4: randomHttpRequest
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
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();
}
}
示例5: createHttpUriRequest
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
/**
* 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);
}
}
示例6: createHttpUriRequest
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
/**
* 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);
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:29,代码来源:HttpComponentsClientHttpRequestFactory.java
示例7: getRawMethodRequest
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
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();
}
示例8: getRequest
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
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();
}
示例9: register
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
@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);
}
示例10: sendPATCH
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
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();
}
示例11: requireThatServerRespondsToAllMethods
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
@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));
}
示例12: createHttpUriRequest
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
/**
* 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);
}
}
示例13: test_methods
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
@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));
}
}
示例14: modifyAccount
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
/**
* 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;
}
示例15: testPatchValidJson
import org.apache.http.client.methods.HttpPatch; //导入依赖的package包/类
@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);
}