本文整理汇总了Java中org.springframework.http.HttpMethod.GET属性的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.GET属性的具体用法?Java HttpMethod.GET怎么用?Java HttpMethod.GET使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.springframework.http.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.GET属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserInfoFor
public Map<String, String> getUserInfoFor(OAuth2AccessToken accessToken) {
RestTemplate restTemplate = new RestTemplate();
RequestEntity<Void> requestEntity = new RequestEntity<>(
getHeader(accessToken.getValue()),
HttpMethod.GET,
URI.create(properties.getUserInfoUri())
);
ParameterizedTypeReference<Map<String, String>> typeRef =
new ParameterizedTypeReference<Map<String, String>>() {};
ResponseEntity<Map<String, String>> result = restTemplate.exchange(
requestEntity, typeRef);
if (result.getStatusCode().is2xxSuccessful()) {
return result.getBody();
}
throw new RuntimeException("It wasn't possible to retrieve userInfo");
}
示例2: tryToGetUserProfile
private void tryToGetUserProfile(ModelAndView mv, String token) {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", "Bearer " + token);
String endpoint = "http://localhost:8080/api/profile";
try {
RequestEntity<Object> request = new RequestEntity<>(
headers, HttpMethod.GET, URI.create(endpoint));
ResponseEntity<UserProfile> userProfile = restTemplate.exchange(request, UserProfile.class);
if (userProfile.getStatusCode().is2xxSuccessful()) {
mv.addObject("profile", userProfile.getBody());
} else {
throw new RuntimeException("it was not possible to retrieve user profile");
}
} catch (HttpClientErrorException e) {
throw new RuntimeException("it was not possible to retrieve user profile");
}
}
示例3: main
public static void main(String[] args) throws Exception {
RestTemplate template = new RestTemplate();
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("X-Tenant-Name", "default");
RequestEntity<String> requestEntity = new RequestEntity<String>(headers, HttpMethod.GET,
new URI("http://127.0.0.1:9980/registry/v3/microservices"));
ResponseEntity<String> stringResponseEntity = template.exchange(requestEntity, String.class);
System.out.println(stringResponseEntity.getBody());
ResponseEntity<MicroserviceArray> microseriveResponseEntity = template
.exchange(requestEntity, MicroserviceArray.class);
MicroserviceArray microserives = microseriveResponseEntity.getBody();
System.out.println(microserives.getServices().get(1).getServiceId());
// instance
headers.add("X-ConsumerId", microserives.getServices().get(1).getServiceId());
requestEntity = new RequestEntity<String>(headers, HttpMethod.GET,
new URI("http://127.0.0.1:9980/registry/v3/microservices/" + microserives.getServices().get(1).getServiceId()
+ "/instances"));
ResponseEntity<String> microserviceInstanceResponseEntity = template.exchange(requestEntity, String.class);
System.out.println(microserviceInstanceResponseEntity.getBody());
}
示例4: execute_withHeaders
@Test
public void execute_withHeaders() {
Request request = new MockRequest("http://example.ca", HttpMethod.GET);
request.headers().add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
request.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML_VALUE);
requestExecutor.execute(request);
ClientRequest clientRequest = verifyExchange();
assertThat(clientRequest.url())
.isEqualTo(URI.create("http://example.ca"));
assertThat(clientRequest.method())
.isEqualTo(HttpMethod.GET);
assertThat(clientRequest.headers().getFirst(HttpHeaders.ACCEPT))
.isEqualTo(MediaType.APPLICATION_JSON_VALUE);
assertThat(clientRequest.headers().getFirst(HttpHeaders.CONTENT_TYPE))
.isEqualTo(MediaType.APPLICATION_XML_VALUE);
}
示例5: headers_withReadOnlyHttpHeaders
@Test
public void headers_withReadOnlyHttpHeaders() {
HttpHeaders httpHeaders = HttpHeaders.readOnlyHttpHeaders(new HttpHeaders());
DefaultRequest defaultRequest = new DefaultRequest(new DefaultUriBuilderFactory().builder(),
HttpMethod.GET, httpHeaders, new HashMap<>(), BodyInserters.empty());
defaultRequest.headers().add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
assertThat(defaultRequest.headers().getFirst(HttpHeaders.ACCEPT)).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
}
示例6: buildRequest
public DefaultRequest buildRequest(String headerName, String headerValue) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(headerName, headerValue);
return new DefaultRequest(new DefaultUriBuilderFactory().builder(),
HttpMethod.GET, httpHeaders, new HashMap<>(), BodyInserters.empty());
}
示例7: HttpSamplerBuilder
public HttpSamplerBuilder() {
super();
this.method = HttpMethod.GET;
this.headers = new HashMap<>();
}
示例8: execute
@SuppressWarnings("rawtypes")
@Override
public void execute(final Api api, final WebScriptRequest req, final WebScriptResponse res) throws IOException
{
try
{
final Map<String, Object> respons = new HashMap<String, Object>();
final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
final ResourceWithMetadata resource = locator.locateResource(api,templateVars, httpMethod);
final Params params = paramsExtractor.extractParams(resource.getMetaData(),req);
final boolean isReadOnly = HttpMethod.GET==httpMethod;
//This execution usually takes place in a Retrying Transaction (see subclasses)
final Object toSerialize = execute(resource, params, res, isReadOnly);
//Outside the transaction.
if (toSerialize != null)
{
if (toSerialize instanceof BinaryResource)
{
// TODO review (experimental) - can we move earlier & wrap complete execute ? Also for QuickShare (in MT/Cloud) needs to be tenant for the nodeRef (TBC).
boolean noAuth = false;
if (BinaryResourceAction.Read.class.isAssignableFrom(resource.getResource().getClass()))
{
noAuth = resource.getMetaData().isNoAuth(BinaryResourceAction.Read.class);
}
else if (RelationshipResourceBinaryAction.Read.class.isAssignableFrom(resource.getResource().getClass()))
{
noAuth = resource.getMetaData().isNoAuth(RelationshipResourceBinaryAction.Read.class);
}
else
{
logger.warn("Unexpected");
}
if (noAuth)
{
String networkTenantDomain = TenantUtil.getCurrentDomain();
TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<Void>()
{
public Void doWork() throws Exception
{
streamResponse(req, res, (BinaryResource) toSerialize);
return null;
}
}, networkTenantDomain);
}
else
{
streamResponse(req, res, (BinaryResource) toSerialize);
}
}
else
{
renderJsonResponse(res, toSerialize, assistant.getJsonHelper());
}
}
}
catch (AlfrescoRuntimeException | ApiException | WebScriptException xception )
{
renderException(xception, res, assistant);
}
catch (RuntimeException runtimeException)
{
renderException(runtimeException, res, assistant);
}
}
示例9: httpMethod
protected HttpMethod httpMethod() {
return HttpMethod.GET;
}
示例10: httpMethod
protected HttpMethod httpMethod() {
return HttpMethod.GET;
}
开发者ID:Huawei,项目名称:Server_Management_Common_eSightApi,代码行数:3,代码来源:GetFirmwareTaskDeviceDetailApi.java
示例11: getBooksOwnedDescriptor
private RestRequestDescriptor<BookCollectionDTO> getBooksOwnedDescriptor() {
return new RestRequestDescriptor<>("/shelf", HttpMethod.GET, null, BookCollectionDTO.class);
}
示例12: getBooksReadDescriptor
private RestRequestDescriptor<BookCollectionDTO> getBooksReadDescriptor() {
return new RestRequestDescriptor<>("/read", HttpMethod.GET, null, BookCollectionDTO.class);
}