本文整理汇总了Java中com.mashape.unirest.http.HttpMethod类的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod类的具体用法?Java HttpMethod怎么用?Java HttpMethod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpMethod类属于com.mashape.unirest.http包,在下文中一共展示了HttpMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapToUnirestHttpMethod
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
public static HttpMethod mapToUnirestHttpMethod(drinkwater.rest.HttpMethod methodAsAnnotation) {
switch (methodAsAnnotation.value().toUpperCase()) {
case "GET":
return HttpMethod.GET;
case "POST":
return HttpMethod.POST;
case "DELETE":
return HttpMethod.DELETE;
case "PUT":
return HttpMethod.PUT;
case "PATCH":
return HttpMethod.PATCH;
default:
throw new RuntimeException(String.format("could not map correct http method : %s", methodAsAnnotation.value()));
}
}
示例2: routesWithoutPathArg_works
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
@Test
public void routesWithoutPathArg_works() throws Exception {
app.routes(() -> {
path("api", () -> {
get(OK_HANDLER);
post(OK_HANDLER);
put(OK_HANDLER);
delete(OK_HANDLER);
patch(OK_HANDLER);
path("user", () -> {
get(OK_HANDLER);
post(OK_HANDLER);
put(OK_HANDLER);
delete(OK_HANDLER);
patch(OK_HANDLER);
});
});
});
HttpMethod[] httpMethods = new HttpMethod[]{HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.PATCH};
for (HttpMethod httpMethod : httpMethods) {
assertThat(call(httpMethod, "/api").getStatus(), is(200));
assertThat(call(httpMethod, "/api/user").getStatus(), is(200));
}
}
示例3: SwaggerGeneratorInput
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
private SwaggerGeneratorInput(String endpoint, HttpMethod method, Map<String, String> pathParams, Map<String, String> headers, Map<String, Object> parameters, String swaggerJSONFilePath,
boolean isAuthentication, String username, String password, String host, String basePath, String apiPath, String apiName, String apiSummary, String apiDescription, List<String> apiTags){
this.endpoint = endpoint;
this.pathParams = pathParams;
this.headers = headers;
this.parameters = parameters;
this.swaggerJSONFile = swaggerJSONFilePath;
this.method = method;
this.authentication = isAuthentication;
this.username = username;
this.password = password;
this.host = host;
this.basePath = basePath;
this.apiPath = apiPath;
this.apiName = apiName;
this.apiSummary = apiSummary;
this.apiDescription = apiDescription;
this.apiTags = apiTags;
}
示例4: toRestdefinition
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
private static RestDefinition toRestdefinition(RouteBuilder builder,
Method method,
HttpMethod httpMethod,
String restPath) {
RestDefinition answer = builder.rest();
String fromPath = restPath;
if (httpMethod == HttpMethod.GET) {
answer = answer.get(fromPath);
} else if (httpMethod == HttpMethod.POST) {
answer = answer.post(fromPath);
} else if (httpMethod == HttpMethod.PUT) {
answer = answer.put(fromPath);
} else if (httpMethod == HttpMethod.DELETE) {
answer = answer.delete(fromPath);
} else if (httpMethod == HttpMethod.PATCH) {
answer = answer.patch(fromPath);
} else {
throw new RuntimeException("method currently not supported in Rest Paths : " + httpMethod);
}
answer = setBodyType(answer, method);
return answer;
}
示例5: testRequestWithoutCustomHeaders
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
@Test
public void testRequestWithoutCustomHeaders() {
// GIVEN a fake url
String remote = "https://fake.kinto.url";
// AND a kintoClient
KintoClient kintoClient = new KintoClient(remote);
// AND an ENDPOINTS
ENDPOINTS endpoint = ENDPOINTS.GROUPS;
// WHEN calling request
GetRequest request = kintoClient.request(endpoint);
// THEN the root part is initialized
assertThat(request.getUrl(), is(remote + "/buckets/{bucket}/groups"));
// AND the get http method is used
assertThat(request.getHttpMethod(), is(HttpMethod.GET));
// AND the default headers are set
assertThat(request.getHeaders(), is(defaultHeaders));
}
示例6: testRequestWithCustomHeaders
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
@Test
public void testRequestWithCustomHeaders() {
// GIVEN a fake url
String remote = "https://fake.kinto.url";
// AND custom headers
Map<String, String> customHeaders = new HashMap<>();
customHeaders.put("Authorization", "Basic supersecurestuff");
customHeaders.put("Warning", "Be careful");
customHeaders.put("Accept", "application/html");
// AND expected headers
Map<String, List<String>> expectedHeaders = new HashMap<>(defaultHeaders);
customHeaders.forEach((k, v) -> expectedHeaders.merge(k, Arrays.asList(v), (a, b) -> a.addAll(b) ? a:a));
// AND a kintoClient
KintoClient kintoClient = new KintoClient(remote, customHeaders);
// AND an ENDPOINTS
ENDPOINTS endpoint = ENDPOINTS.GROUPS;
// WHEN calling request
GetRequest request = kintoClient.request(endpoint);
// THEN the root part is initialized
assertThat(request.getUrl(), is(remote + "/buckets/{bucket}/groups"));
// AND the get http method is used
assertThat(request.getHttpMethod(), is(HttpMethod.GET));
// AND the default headers are set
assertThat(request.getHeaders(), is(expectedHeaders));
}
示例7: request
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
/**
* Perform a request with body to the API
*
* @param httpMethod
* @param url path of request
* @param body content to be sent
* @param opts
* @return the request response
*/
public JsonNode request(HttpMethod httpMethod, String url, JsonNode body, RequestOptions opts) {
if (opts == null) {
opts = RequestOptions.defaults();
}
prepareRequest();
HttpRequestWithBody req = createRequest(httpMethod, url, opts);
if (body != null) {
req.body(body);
}
return tryRequest(req, opts);
}
示例8: get
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
public String get(String key) throws Exception {
HttpRequest request = new HttpRequestWithBody(
HttpMethod.GET,
makeConsulUrl(key) + "?raw"
).getHttpRequest();
authorizeHttpRequest(request);
HttpResponse<String> response;
try {
response = HttpClientHelper.request(request, String.class);
} catch (Exception exception) {
throw new ConsulException("Consul request failed", exception);
}
if (response.getStatus() == 404) {
return null;
}
String encrypted = response.getBody();
return encryption.decrypt(encrypted);
}
示例9: doWork
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
private T doWork() {
try {
setupErrorHandlers();
WorkingContext workingContext = workingContext();
HttpRequest builtRequest = buildUnirest(workingContext)
.queryString(workingContext.getQueryParams())
.headers(workingContext.getHeaders()).header("Ocp-Apim-Subscription-Key", cognitiveContext.subscriptionKey);
if (!workingContext.getHttpMethod().equals(HttpMethod.GET) && workingContext().getPayload().size() > 0) {
buildBody((HttpRequestWithBody) builtRequest);
}
HttpResponse response;
if (typedResponse() == InputStream.class)
response = builtRequest.asBinary();
else
response = builtRequest.asString();
checkForError(response);
return postProcess(typeResponse(response.getBody()));
} catch (UnirestException | IOException e) {
throw new CognitiveException(e);
}
}
示例10: httpMethodFor
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
public static HttpMethod httpMethodFor(Method method) {
HttpMethod defaultHttpMethod = HttpMethod.GET;
drinkwater.rest.HttpMethod methodAsAnnotation = method.getDeclaredAnnotation(drinkwater.rest.HttpMethod.class);
if (methodAsAnnotation != null) {
return mapToUnirestHttpMethod(methodAsAnnotation);
}
return List.ofAll(prefixesMap.entrySet())
.filter(prefix -> startsWithOneOf(method.getName(), prefix.getValue()))
.map(entryset -> entryset.getKey())
.getOrElse(defaultHttpMethod);
}
示例11: restPath
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
private static String restPath(Method method, HttpMethod httpMethod) {
if (httpMethod == HttpMethod.OPTIONS) {
return "";
}
String fromPath = getPathFromAnnotation(method);
if (fromPath == null || fromPath.isEmpty()) {
fromPath = List.of(prefixesMap.get(httpMethod))
.filter(prefix -> method.getName().toLowerCase().startsWith(prefix))
.map(prefix -> method.getName().replace(prefix, "").toLowerCase())
.getOrElse("");
//if still empty
if (fromPath.isEmpty()) {
fromPath = method.getName();
}
}
if (httpMethod == HttpMethod.GET) {
if (fromPath == null || fromPath.isEmpty()) {
fromPath = javaslang.collection.List.of(method.getParameters())
.map(p -> "{" + p.getName() + "}").getOrElse("");
}
}
return fromPath;
}
示例12: init
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
private void init() {
HttpMethod httpMethod = httpMethodFor(method);
List<Parameter> parameterInfos = javaslang.collection.List.of(method.getParameters());
NoBody noBodyAnnotation = method.getAnnotation(NoBody.class);
hasReturn = returnsVoid(method);
if (parameterInfos.size() == 0) {
return;
}
if (httpMethod == HttpMethod.GET) {
hasBody = false;
} else if (httpMethod == HttpMethod.POST || httpMethod == HttpMethod.DELETE || httpMethod == HttpMethod.PUT) {
if (parameterInfos.size() > 0) {
hasBody = true;
}
if (noBodyAnnotation != null) {
hasBody = false;
}
} else {
throw new RuntimeException("come back here : MethodToRestParameters.init()");
}
if (hasBody) { // first parameter of the method will be assigned with the body content
headerNames = parameterInfos.tail().map(p -> mapName(p)).toList();
} else {
headerNames = parameterInfos.map(p -> mapName(p)).toList();
}
}
示例13: test_json_jackson_throwsForBadObject
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
@Test
public void test_json_jackson_throwsForBadObject() throws Exception {
app.get("/hello", ctx -> ctx.status(200).json(new TestObject_NonSerializable()));
HttpResponse<String> response = call(HttpMethod.GET, "/hello");
assertThat(response.getStatus(), is(500));
assertThat(response.getBody(), is("Internal server error"));
}
示例14: test_json_jacksonMapsJsonToObject_throwsForBadObject
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
@Test
public void test_json_jacksonMapsJsonToObject_throwsForBadObject() throws Exception {
app.get("/hello", ctx -> ctx.json(ctx.bodyAsClass(TestObject_NonSerializable.class).getClass().getSimpleName()));
HttpResponse<String> response = call(HttpMethod.GET, "/hello");
assertThat(response.getStatus(), is(500));
assertThat(response.getBody(), is("Internal server error"));
}
示例15: test_justFilters_is404
import com.mashape.unirest.http.HttpMethod; //导入依赖的package包/类
@Test
public void test_justFilters_is404() throws Exception {
Handler emptyHandler = ctx -> {
};
app.before(emptyHandler);
app.after(emptyHandler);
HttpResponse<String> response = call(HttpMethod.GET, "/hello");
assertThat(response.getStatus(), is(404));
assertThat(response.getBody(), is("Not found"));
}