当前位置: 首页>>代码示例>>Java>>正文


Java HttpMethod.GET属性代码示例

本文整理汇总了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");
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:20,代码来源:UserInfoService.java

示例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");
    }
}
 
开发者ID:PacktPublishing,项目名称:OAuth-2.0-Cookbook,代码行数:21,代码来源:UserDashboard.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:23,代码来源:ServiceCenterExample.java

示例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);
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:17,代码来源:DefaultRequestExecutorTest.java

示例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);
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:9,代码来源:DefaultRequestTest.java

示例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());
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:7,代码来源:DefaultRequestTest.java

示例7: HttpSamplerBuilder

public HttpSamplerBuilder() {
    super();
    this.method = HttpMethod.GET;
    this.headers = new HashMap<>();
}
 
开发者ID:gilles-stragier,项目名称:quickmon,代码行数:5,代码来源:HttpSamplerBuilder.java

示例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);
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:70,代码来源:AbstractResourceWebScript.java

示例9: httpMethod

protected HttpMethod httpMethod() {
  return HttpMethod.GET;
}
 
开发者ID:Huawei,项目名称:Server_Management_Common_eSightApi,代码行数:3,代码来源:GetFirmwareListApi.java

示例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);
}
 
开发者ID:tyro,项目名称:pact-spring-mvc,代码行数:3,代码来源:StatefulConsumerPactTest.java

示例12: getBooksReadDescriptor

private RestRequestDescriptor<BookCollectionDTO> getBooksReadDescriptor() {
    return new RestRequestDescriptor<>("/read", HttpMethod.GET, null, BookCollectionDTO.class);
}
 
开发者ID:tyro,项目名称:pact-spring-mvc,代码行数:3,代码来源:StatefulConsumerPactTest.java


注:本文中的org.springframework.http.HttpMethod.GET属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。