Search in sources :

Example 6 with CseHttpEntity

use of org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity in project incubator-servicecomb-java-chassis by apache.

the class TestContentType method testRequestMapping.

private void testRequestMapping() {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    CseHttpEntity<String> requestEntity = new CseHttpEntity<>("from testRequestMapping", requestHeaders);
    ResponseEntity<String> responseEntity = restTemplate.exchange("cse://springmvc/contentTypeSpringmvc/testRequestMapping", HttpMethod.POST, requestEntity, String.class);
    TestMgr.check("testRequestMapping: name=[from testRequestMapping], request content-type=[" + MediaType.APPLICATION_JSON + "]", responseEntity.getBody());
    TestMgr.check(MediaType.APPLICATION_JSON, extractContentType(responseEntity.getHeaders().getContentType()));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) CseHttpEntity(org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity)

Example 7 with CseHttpEntity

use of org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity in project incubator-servicecomb-java-chassis by apache.

the class TestContentType method testGlobalSetting.

private void testGlobalSetting() {
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN);
    CseHttpEntity<String> requestEntity = new CseHttpEntity<>("from testGlobalSetting", requestHeaders);
    ResponseEntity<String> responseEntity = restTemplate.exchange("cse://springmvc/contentTypeSpringmvc/testGlobalSetting", HttpMethod.POST, requestEntity, String.class);
    TestMgr.check("testGlobalSetting: name=[from testGlobalSetting], request content-type=[" + MediaType.TEXT_PLAIN + "]", responseEntity.getBody());
    TestMgr.check(MediaType.TEXT_PLAIN, extractContentType(responseEntity.getHeaders().getContentType()));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) CseHttpEntity(org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity)

Example 8 with CseHttpEntity

use of org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity in project incubator-servicecomb-java-chassis by apache.

the class CodeFirstRestTemplateSpringmvc method testResponseEntity.

private void testResponseEntity(String microserviceName, RestTemplate template, String cseUrlPrefix) {
    Map<String, Object> body = new HashMap<>();
    Date date = new Date();
    body.put("date", date);
    CseHttpEntity<Map<String, Object>> httpEntity = new CseHttpEntity<>(body);
    httpEntity.addContext("contextKey", "contextValue");
    String srcName = RegistrationManager.INSTANCE.getMicroservice().getServiceName();
    ResponseEntity<Date> responseEntity = template.exchange(cseUrlPrefix + "responseEntity", HttpMethod.POST, httpEntity, Date.class);
    TestMgr.check(date, responseEntity.getBody());
    TestMgr.check("h1v " + srcName, responseEntity.getHeaders().getFirst("h1"));
    TestMgr.check("h2v " + srcName, responseEntity.getHeaders().getFirst("h2"));
    checkStatusCode(microserviceName, 202, responseEntity.getStatusCode());
    responseEntity = template.exchange(cseUrlPrefix + "responseEntity", HttpMethod.PATCH, httpEntity, Date.class);
    TestMgr.check(date, responseEntity.getBody());
    TestMgr.check("h1v " + srcName, responseEntity.getHeaders().getFirst("h1"));
    TestMgr.check("h2v " + srcName, responseEntity.getHeaders().getFirst("h2"));
    checkStatusCode(microserviceName, 202, responseEntity.getStatusCode());
    int retryResult = template.getForObject(cseUrlPrefix + "retrySuccess?a=2&b=3", Integer.class);
    TestMgr.check(retryResult, 5);
    retryResult = template.getForObject(cseUrlPrefix + "retrySuccess?a=2&b=3", Integer.class);
    TestMgr.check(retryResult, 5);
}
Also used : CseHttpEntity(org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Date(java.util.Date)

Example 9 with CseHttpEntity

use of org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity in project incubator-servicecomb-java-chassis by apache.

the class BeanParamRestTemplateClient method testBeanParam.

private void testBeanParam() {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Cookie", "cookieSwaggerLong=11");
    headers.add("headerSwaggerInt", "2");
    HttpEntity<Object> requestEntity1 = new CseHttpEntity<>(headers);
    ResponseEntity<String> result = restTemplate.exchange("cse://jaxrs/beanParamTest/pathSwaggerValue/simple?querySwaggerStr=querySwaggerValue&extraQuery=extra", HttpMethod.GET, requestEntity1, String.class);
    TestMgr.check("invocationContextConsistency=true|testBeanParameter=TestBeanParameter{queryStr='querySwaggerValue', headerInt=2, " + "pathStr='pathSwaggerValue', cookieLong=11}|extraQuery=extra", result.getBody());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) CseHttpEntity(org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity)

Example 10 with CseHttpEntity

use of org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity in project java-chassis by ServiceComb.

the class CodeFirstRestTemplateSpringmvc method testResponseEntity.

private void testResponseEntity(String microserviceName, RestTemplate template, String cseUrlPrefix) {
    Map<String, Object> body = new HashMap<>();
    Date date = new Date();
    body.put("date", date);
    CseHttpEntity<Map<String, Object>> httpEntity = new CseHttpEntity<>(body);
    httpEntity.addContext("contextKey", "contextValue");
    String srcName = RegistrationManager.INSTANCE.getMicroservice().getServiceName();
    ResponseEntity<Date> responseEntity = template.exchange(cseUrlPrefix + "responseEntity", HttpMethod.POST, httpEntity, Date.class);
    TestMgr.check(date, responseEntity.getBody());
    TestMgr.check("h1v " + srcName, responseEntity.getHeaders().getFirst("h1"));
    TestMgr.check("h2v " + srcName, responseEntity.getHeaders().getFirst("h2"));
    checkStatusCode(microserviceName, 202, responseEntity.getStatusCode());
    responseEntity = template.exchange(cseUrlPrefix + "responseEntity", HttpMethod.PATCH, httpEntity, Date.class);
    TestMgr.check(date, responseEntity.getBody());
    TestMgr.check("h1v " + srcName, responseEntity.getHeaders().getFirst("h1"));
    TestMgr.check("h2v " + srcName, responseEntity.getHeaders().getFirst("h2"));
    checkStatusCode(microserviceName, 202, responseEntity.getStatusCode());
    int retryResult = template.getForObject(cseUrlPrefix + "retrySuccess?a=2&b=3", Integer.class);
    TestMgr.check(retryResult, 5);
    retryResult = template.getForObject(cseUrlPrefix + "retrySuccess?a=2&b=3", Integer.class);
    TestMgr.check(retryResult, 5);
}
Also used : CseHttpEntity(org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Date(java.util.Date)

Aggregations

CseHttpEntity (org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity)12 HttpHeaders (org.springframework.http.HttpHeaders)8 Date (java.util.Date)4 LocalDate (java.time.LocalDate)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)2 DiscoveryContext (org.apache.servicecomb.registry.discovery.DiscoveryContext)2 InvocationContext (org.apache.servicecomb.swagger.invocation.context.InvocationContext)2 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)2 MultiValueMap (org.springframework.util.MultiValueMap)2 RestTemplate (org.springframework.web.client.RestTemplate)2