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 = RegistryUtils.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());
}
use of org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity in project java-chassis by ServiceComb.
the class TestDateTimeSchema method testDateTimeSchemaMulticastRestTemplate.
private void testDateTimeSchemaMulticastRestTemplate() throws Exception {
DiscoveryContext context = new DiscoveryContext();
VersionedCache serversVersionedCache = discoveryTree.discovery(context, "springmvctest", "springmvc", "0+");
List<String> enpoints = serversVersionedCache.data();
RestTemplate restTemplate = RestTemplateBuilder.create();
for (String endpoint : enpoints) {
CseHttpEntity<?> entity = new CseHttpEntity<>(null);
InvocationContext invocationContext = new InvocationContext();
invocationContext.addLocalContext(LoadbalanceHandler.SERVICECOMB_SERVER_ENDPOINT, endpoint);
entity.setContext(invocationContext);
Date date = new Date();
String dateValue = RestObjectMapperFactory.getRestObjectMapper().convertToString(date);
TestMgr.check(date.getTime(), restTemplate.exchange("cse://springmvc/dateTime/getDate?date={1}", HttpMethod.GET, entity, Date.class, dateValue).getBody().getTime());
entity = new CseHttpEntity<>(null);
invocationContext = new InvocationContext();
invocationContext.addLocalContext(LoadbalanceHandler.SERVICECOMB_SERVER_ENDPOINT, parseEndpoint(endpoint));
entity.setContext(invocationContext);
date = new Date();
dateValue = RestObjectMapperFactory.getRestObjectMapper().convertToString(date);
TestMgr.check(date.getTime(), restTemplate.exchange("cse://springmvc/dateTime/getDate?date={1}", HttpMethod.GET, entity, Date.class, dateValue).getBody().getTime());
}
}
use of org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity in project java-chassis by ServiceComb.
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 java-chassis by ServiceComb.
the class TestContentType method testApiOperation.
private void testApiOperation() {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
CseHttpEntity<String> requestEntity = new CseHttpEntity<>("from testApiOperation", requestHeaders);
ResponseEntity<String> responseEntity = restTemplate.exchange("cse://springmvc/contentTypeSpringmvc/testApiOperation", HttpMethod.POST, requestEntity, String.class);
TestMgr.check("testApiOperation: name=[from testApiOperation], 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 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