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()));
}
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()));
}
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);
}
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());
}
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);
}
Aggregations