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


Java HttpMethod类代码示例

本文整理汇总了Java中org.springframework.http.HttpMethod的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod类的具体用法?Java HttpMethod怎么用?Java HttpMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpMethod类属于org.springframework.http包,在下文中一共展示了HttpMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postOrUpdateRightHolder

import org.springframework.http.HttpMethod; //导入依赖的package包/类
public void postOrUpdateRightHolder(String eppn) {	
	if(enable) {
		String url = webUrl + "/rightholders/" + eppn;
		HttpHeaders headers = this.getAuthHeaders();	
		HttpEntity entity = new HttpEntity(headers);		
		try {
			ResponseEntity<RightHolder> response = restTemplate.exchange(url, HttpMethod.GET, entity, RightHolder.class);
			log.info("Getting RightHolder for " + eppn +" : " + response.toString());
			RightHolder oldRightHolder = response.getBody();
			RightHolder newRightHolder = this.computeEsupSgcRightHolder(eppn);
			if(!newRightHolder.fieldWoDueDateEquals(oldRightHolder) || mustUpdateDueDateCrous(oldRightHolder, eppn)) {
				updateRightHolder(eppn);
			} 
		} catch(HttpClientErrorException clientEx) {
			if(HttpStatus.NOT_FOUND.equals(clientEx.getStatusCode())) {
				postRightHolder(eppn);
				return ;
			} else {
				throw clientEx;
			}
		}
	}
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:24,代码来源:ApiCrousService.java

示例2: should_return_cases_as_empty_list_if_patient_not_exist

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@Test
public void should_return_cases_as_empty_list_if_patient_not_exist() {
    //Given
    long patientId = 123123;

    //When
    ResponseEntity<List<Case>> response = testRestTemplate.
            withBasicAuth("1","1").
            exchange("/v1/cases?patientId="+patientId,
                    HttpMethod.GET,
                    null,
                    new ParameterizedTypeReference<List<Case>>() {
                    });
    List<Case> cases = response.getBody();

    //Then
    assertThat(cases).isNotNull();
    assertThat(cases).isEmpty();
}
 
开发者ID:JUGIstanbul,项目名称:second-opinion-api,代码行数:20,代码来源:CaseControllerIT.java

示例3: configure

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
    httpSecurity
            // we don't need CSRF because our token is invulnerable
            .csrf().disable()

            .exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and()

            // no need to create session as JWT auth is stateless and per request
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()

            .authorizeRequests()
            .antMatchers("/auth").permitAll()                   // allow anyone to try and authenticate
            .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() // allow CORS pre-flighting
            .anyRequest().authenticated();                      // lock down everything else

    // Add our custom JWT security filter before Spring Security's Username/Password filter
    httpSecurity.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);

    // Disable page caching in the browser
    httpSecurity.headers().cacheControl().disable();
}
 
开发者ID:gazbert,项目名称:bxbot-ui-server,代码行数:23,代码来源:WebSecurityConfig.java

示例4: execute_withHeaders

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@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,代码行数:18,代码来源:DefaultRequestExecutorTest.java

示例5: attemptAuthentication

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException,
    ServletException {
  if (!HttpMethod.POST.name().equals(request.getMethod()) || !WebUtil.isAjax(request)) {
    if (logger.isDebugEnabled()) {
      logger.debug("Authentication method not supported. Request method: " + request.getMethod());
    }
    throw new AuthMethodNotSupportedException("Authentication method not supported");
  }

  LoginRequest loginRequest = objectMapper.readValue(request.getReader(), LoginRequest.class);

  if (StringUtils.isBlank(loginRequest.getUsername()) || StringUtils.isBlank(loginRequest.getPassword())) {
    throw new AuthenticationServiceException("Username or Password not provided");
  }

  AdminUserAuthenticationToken token = new AdminUserAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword());

  return this.getAuthenticationManager().authenticate(token);
}
 
开发者ID:Apereo-Learning-Analytics-Initiative,项目名称:OpenLRW,代码行数:21,代码来源:AdminUserProcessingFilter.java

示例6: on

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@When("^client_two does a DELETE on (.*?) with (.*?) in zone (.*?)$")
public void client_two_does_a_DELETE_on_api_with_identifier_in_test_zone_dev(final String api,
        final String identifier, final String zone) throws Throwable {

    OAuth2RestTemplate acsTemplate = this.acsZone2Template;
    String zoneName = getZoneName(zone);

    HttpHeaders zoneHeaders = ACSTestUtil.httpHeaders();
    zoneHeaders.set(PolicyHelper.PREDIX_ZONE_ID, zoneName);

    String encodedIdentifier = URLEncoder.encode(identifier, "UTF-8");
    URI uri = URI.create(this.acsUrl + ACS_VERSION + "/" + api + "/" + encodedIdentifier);
    try {
        this.status = acsTemplate
                .exchange(uri, HttpMethod.DELETE, new HttpEntity<>(zoneHeaders), ResponseEntity.class)
                .getStatusCode().value();
    } catch (HttpClientErrorException e) {
        Assert.fail("Unable to DELETE identifier: " + identifier + " for api: " + api);
    }
}
 
开发者ID:eclipse,项目名称:keti,代码行数:21,代码来源:ZoneEnforcementStepsDefinitions.java

示例7: testSubmit

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@Test
public void testSubmit()
    throws ExecutionException, InterruptedException {
  String packageData = "this_is_a_package";

  // This test is *very* limited as Spring doesn't have any easy way to check
  // requests with multipart form data...
  server.expect(requestTo("/tasks.json"))
      .andExpect(method(HttpMethod.POST))
      .andExpect(content().contentTypeCompatibleWith(MediaType.MULTIPART_FORM_DATA))
      .andRespond(withSuccess("{\"status\":\"ok\"}", MediaType.APPLICATION_JSON));

  UUID submissionId = UUID.randomUUID();

  CompletableFuture<SubmissionResponse> responseFuture = sender
      .sendSubmission(submissionId, packageData.getBytes());
  SubmissionResponse response = responseFuture.get();

  assertTrue(response.getStatus().equals(SubmissionResponse.OK));
}
 
开发者ID:tdd-pingis,项目名称:tdd-pingpong,代码行数:21,代码来源:SubmissionSenderServiceTest.java

示例8: getComments

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "defaultComments")
public List<Comment> getComments(Image image, String sessionId) {

	ResponseEntity<List<Comment>> results = restTemplate.exchange(
		"http://COMMENTS/comments/{imageId}",
		HttpMethod.GET,
		new HttpEntity<>(new HttpHeaders() {{
			String credentials = imagesConfiguration.getCommentsUser() + ":" +
				imagesConfiguration.getCommentsPassword();
			String token = new String(Base64Utils.encode(credentials.getBytes()));
			set(AUTHORIZATION, "Basic " + token);
			set("SESSION", sessionId);
		}}),
		new ParameterizedTypeReference<List<Comment>>() {},
		image.getId());
	return results.getBody();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:18,代码来源:CommentHelper.java

示例9: getTopologyFlows

import org.springframework.http.HttpMethod; //导入依赖的package包/类
/**
 * Gets the topology flows.
 *
 * @return the topology flows
 */
public List<TopologyFlowsResponse> getTopologyFlows() {
    List<TopologyFlowsResponse> flowPathList = new ArrayList<TopologyFlowsResponse>();
    try {
        HttpResponse response =
                restClientManager.invoke(applicationProperties.getTopologyFlows(),
                        HttpMethod.GET, "", "", util.kildaAuthHeader());
        if (RestClientManager.isValidResponse(response)) {

            flowPathList =
                    restClientManager.getResponseList(response, TopologyFlowsResponse.class);
        }

    } catch (Exception exception) {
        log.error("Exception in getTopologyFlows " + exception.getMessage());
    }
    return flowPathList;
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:23,代码来源:FlowsIntegrationService.java

示例10: authenticate

import org.springframework.http.HttpMethod; //导入依赖的package包/类
public synchronized void authenticate() {
	if(enable) {
		String url = webUrl + "/authenticate";
		HttpHeaders headers = getJsonHeaders();
		Map<String, String> body = new HashMap<String, String>();
		body.put("login", login);
		body.put("password", password);
		HttpEntity entity = new HttpEntity(body, headers);	
		HttpEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
		HttpHeaders httpHeadersResponse = response.getHeaders();
		log.info("Headers response for crous api authentication : " + httpHeadersResponse);
		List<String> authorizations = httpHeadersResponse.get("authorization");
		if(authorizations!=null && !authorizations.isEmpty()) {
			authToken = authorizations.get(0);
			log.info("Auth Token of Crous API is renew : " + authToken);
		} else {
			throw new SgcRuntimeException("No authorization header when crous authentication : " + httpHeadersResponse, null);
		}
	}
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:21,代码来源:ApiCrousService.java

示例11: should_put_return_406_when_case_not_have_an_id

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@Test
public void should_put_return_406_when_case_not_have_an_id() throws Exception {
    // given
    Case caseEntity = new Case();
    caseEntity.setIllnessStartDate(LocalDate.MAX);
    caseEntity.setNickname("R2-D2");
    caseEntity.setSymptoms("Lorem ipsum dolor sit amet");
    caseEntity.setNote("superiz");
    Case persistedCase = caseRepository.save(caseEntity);
    Long caseId = persistedCase.getId();

    Case updatedCaseOnClientSide = persistedCase;
    updatedCaseOnClientSide.setId(null);

    // when
    ResponseEntity<Void> putResponse = testRestTemplate
            .withBasicAuth("1", "1")
            .exchange("/v1/cases/" + caseId,
                    HttpMethod.PUT,
                    new HttpEntity<>(updatedCaseOnClientSide),
                    Void.class);

    // then
    assertThat(putResponse.getStatusCode()).isEqualTo(HttpStatus.NOT_ACCEPTABLE);
}
 
开发者ID:JUGIstanbul,项目名称:second-opinion-api,代码行数:26,代码来源:CaseControllerIT.java

示例12: getMethod

import org.springframework.http.HttpMethod; //导入依赖的package包/类
/**
 * Gets the HTTP method indicating the operation to perform on the resource identified in the
 * client's HTTP request. This method converts GemFire's HttpMethod enumerated value from the Link
 * into a corresponding Spring HttpMethod enumerated value.
 * <p/>
 * 
 * @return a Spring HttpMethod enumerated value indicating the operation to perform on the
 *         resource identified in the client's HTTP request.
 * @see org.apache.geode.management.internal.web.http.HttpMethod
 * @see org.apache.geode.management.internal.web.domain.Link#getMethod()
 * @see org.springframework.http.HttpMethod
 * @see org.springframework.http.HttpRequest#getMethod()
 */
@Override
public HttpMethod getMethod() {
  switch (getLink().getMethod()) {
    case DELETE:
      return HttpMethod.DELETE;
    case HEAD:
      return HttpMethod.HEAD;
    case OPTIONS:
      return HttpMethod.OPTIONS;
    case POST:
      return HttpMethod.POST;
    case PUT:
      return HttpMethod.PUT;
    case TRACE:
      return HttpMethod.TRACE;
    case GET:
    default:
      return HttpMethod.GET;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:34,代码来源:ClientHttpRequest.java

示例13: whenGetCalledThenExpectEmailAlertsConfigToBeReturned

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@Test
public void whenGetCalledThenExpectEmailAlertsConfigToBeReturned() throws Exception {

    final String emailAlertsConfigInJson = objectMapper.writeValueAsString(someEmailAlertsConfig);

    mockServer.expect(requestTo(REST_ENDPOINT_BASE_URL + EMAIL_ALERTS_RESOURCE_PATH))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess(emailAlertsConfigInJson, MediaType.APPLICATION_JSON));

    final EmailAlertsConfig emailAlertsConfig = restClient.get(botConfig);
    assertThat(emailAlertsConfig.getId()).isEqualTo(BOT_ID);
    assertThat(emailAlertsConfig.isEnabled()).isEqualTo(ENABLED);
    assertThat(emailAlertsConfig.getSmtpConfig().getAccountUsername()).isEqualTo(ACCOUNT_USERNAME);
    assertThat(emailAlertsConfig.getSmtpConfig().getAccountPassword()).isEqualTo(ACCOUNT_PASSWORD);
    assertThat(emailAlertsConfig.getSmtpConfig().getHost()).isEqualTo(HOST);
    assertThat(emailAlertsConfig.getSmtpConfig().getTlsPort()).isEqualTo(TLS_PORT);
    assertThat(emailAlertsConfig.getSmtpConfig().getFromAddress()).isEqualTo(FROM_ADDRESS);
    assertThat(emailAlertsConfig.getSmtpConfig().getToAddress()).isEqualTo(TO_ADDRESS);

    mockServer.verify();
}
 
开发者ID:gazbert,项目名称:bxbot-ui-server,代码行数:22,代码来源:TestEmailAlertsConfigRepository.java

示例14: configure

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@Override
 public void configure(final HttpSecurity http) throws Exception {
 	http
 		.requestMatchers().antMatchers("/doctor/**", "/rx/**", "/account/**")
 		.and()
 		.authorizeRequests()
 		.antMatchers(HttpMethod.GET,"/doctor/**").access("#oauth2.hasScope('doctor') and #oauth2.hasScope('read')")
.antMatchers(HttpMethod.POST,"/doctor/**").access("#oauth2.hasScope('doctor') and #oauth2.hasScope('write')")
.antMatchers(HttpMethod.GET,"/rx/**").access("#oauth2.hasScope('doctor') and #oauth2.hasScope('read')")
.antMatchers(HttpMethod.POST,"/rx/**").access("#oauth2.hasScope('doctor') and #oauth2.hasScope('write')")	
.antMatchers("/account/**").permitAll()
.and()
.exceptionHandling().accessDeniedHandler(new OAuth2AccessDeniedHandler())
.and()
.csrf().disable();

 }
 
开发者ID:PacktPublishing,项目名称:Building-Web-Apps-with-Spring-5-and-Angular,代码行数:18,代码来源:ResourceServerOAuth2Config.java

示例15: whenSaveCalledThenExpectRepositoryToSaveItAndReturnSavedEngineConfig

import org.springframework.http.HttpMethod; //导入依赖的package包/类
@Test
public void whenSaveCalledThenExpectRepositoryToSaveItAndReturnSavedEngineConfig() throws Exception {

    final String engineConfigInJson = objectMapper.writeValueAsString(someEngineConfig);

    mockServer.expect(requestTo(REST_ENDPOINT_BASE_URL + ENGINE_RESOURCE_PATH))
            .andExpect(method(HttpMethod.PUT))
            .andRespond(withSuccess(engineConfigInJson, MediaType.APPLICATION_JSON));

    final EngineConfig engineConfig = restClient.save(botConfig, someEngineConfig);
    assertThat(engineConfig.getId()).isEqualTo(BOT_ID);
    assertThat(engineConfig.getBotName()).isEqualTo(BOT_ALIAS);
    assertThat(engineConfig.getTradeCycleInterval()).isEqualTo(ENGINE_TRADE_CYCLE_INTERVAL);
    assertThat(engineConfig.getEmergencyStopCurrency()).isEqualTo(ENGINE_EMERGENCY_STOP_CURRENCY);
    assertThat(engineConfig.getEmergencyStopBalance()).isEqualTo(ENGINE_EMERGENCY_STOP_BALANCE);

    mockServer.verify();
}
 
开发者ID:gazbert,项目名称:bxbot-ui-server,代码行数:19,代码来源:TestEngineConfigRepository.java


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