org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder Java Examples
The following examples show how to use
org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Test3rdPartyInvocation.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void testSyncInvoke_RestTemplate() { RestTemplate restTemplate = RestTemplateBuilder.create(); ResponseEntity<Integer> responseEntity = restTemplate .getForEntity( "cse://" + THIRD_PARTY_MICROSERVICE_NAME + "/v1/dataTypeJaxrs/intAdd?num1=11&num2=22", int.class); Assert.assertEquals(200, responseEntity.getStatusCodeValue()); Assert.assertEquals(33, responseEntity.getBody().intValue()); ResponseEntity<String> stringBodyResponse = restTemplate .exchange("cse://" + THIRD_PARTY_MICROSERVICE_NAME + "/v1/dataTypeJaxrs/stringBody", HttpMethod.POST, new HttpEntity<>("abc"), String.class); Assert.assertEquals(200, stringBodyResponse.getStatusCodeValue()); Assert.assertEquals("abc", stringBodyResponse.getBody()); }
Example #2
Source File: TestMaxHttpUrlLength.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
private void testUrlNotLongerThan4096() { RestTemplate restTemplate = RestTemplateBuilder.create(); String q = Strings.repeat("q", 4096 - "GET /springmvc/controller/sayhi?name=".length() - " HTTP/1.1\r".length()); TestMgr.check("hi " + q + " [" + q + "]", restTemplate.getForObject("cse://springmvc/springmvc/controller/sayhi?name=" + q, String.class)); q = Strings.repeat("q", 4096 + 1 - "GET /springmvc/controller/sayhi?name=".length() - " HTTP/1.1\r".length()); try { restTemplate.getForObject("cse://springmvc/springmvc/controller/sayhi?name=" + q, String.class); TestMgr.check(true, false); } catch (InvocationException e) { TestMgr.check(414, e.getStatusCode()); } }
Example #3
Source File: JaxrsConsumerMain.java From servicecomb-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { BeanUtils.init(); System.out.println(hello.sayHi("Java Chassis")); Person person = new Person(); person.setName("ServiceComb/Java Chassis"); System.out.println(hello.sayHello(person)); RestTemplate restTemplate = RestTemplateBuilder.create(); String result = restTemplate.getForObject("cse://jaxrs/jaxrshello/saybye", String.class); System.out.println(result); }
Example #4
Source File: SpringMvcIntegrationTestBase.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void ableToUploadFileFromConsumer() throws Exception { String file1Content = "hello world"; String file2Content = "bonjour"; String username = "mike"; Map<String, Object> map = new HashMap<>(); map.put("file1", new FileSystemResource(newFile(file1Content).getAbsolutePath())); map.put("someFile", new FileSystemResource(newFile(file2Content).getAbsolutePath())); map.put("name", username); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); String result = RestTemplateBuilder.create().postForObject( "cse://springmvc-tests/codeFirstSpringmvc/upload", new HttpEntity<>(map, headers), String.class); assertThat(result, is(file1Content + file2Content + username)); org.springframework.web.client.AsyncRestTemplate cseAsyncRestTemplate = new CseAsyncRestTemplate(); ListenableFuture<ResponseEntity<String>> listenableFuture = cseAsyncRestTemplate .postForEntity("cse://springmvc-tests/codeFirstSpringmvc/upload", new HttpEntity<>(map, headers), String.class); ResponseEntity<String> responseEntity = listenableFuture.get(); assertThat(responseEntity.getBody(), is(file1Content + file2Content + username)); }
Example #5
Source File: Application.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
public static void runTest() { RestTemplate template = RestTemplateBuilder.create(); TestMgr.check("2", template .getForObject("cse://demo-register-url-prefix-server/hellodemo/register/url/prefix/getName?name=2", String.class)); TestMgr.summary(); }
Example #6
Source File: LocalRegistryServerTest.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
private void testServerGetName() { RestTemplate template = RestTemplateBuilder.create(); TestMgr.check("2", template .getForObject("cse://demo-local-registry-server/register/url/prefix/getName?name=2", String.class)); TestMgr.check("2", template .getForObject("cse://demo-local-registry-server-bean/register/url/prefix/getName?name=2", String.class)); }
Example #7
Source File: CrossappClient.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@SuppressWarnings({"deprecation"}) public static void run() { Object result = InvokerUtils.syncInvoke("appServer:appService", "helloworld", "sayHello", null); TestMgr.check("hello world", result); RestTemplate restTemplate = RestTemplateBuilder.create(); result = restTemplate.getForObject("cse://appServer:appService/helloworld/hello", String.class); TestMgr.check("hello world", result); result = helloWorld.sayHello(); TestMgr.check("hello world", result); testCorsHandler(); }
Example #8
Source File: SpringmvcClient.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
public static void run() throws Exception { testHttpClientsIsOk(); testConfigurationDuplicate(); templateUrlWithServiceName.setRequestFactory(new UrlWithServiceNameClientHttpRequestFactory()); restTemplate = RestTemplateBuilder.create(); templateUrlWithProviderPrefix.setRequestFactory(new UrlWithProviderPrefixClientHttpRequestFactory("/pojo/rest")); controller = BeanUtils.getBean("controller"); String prefix = "cse://springmvc"; String microserviceName = "springmvc"; try { // this test class is intended for retry hanging issue JAV-127 templateUrlWithServiceName.getForObject(prefix + "/controller/sayhi?name=throwexception", String.class); TestMgr.check("true", "false"); } catch (Exception e) { TestMgr.check("true", "true"); } CodeFirstRestTemplateSpringmvc codeFirstClient = BeanUtils.getContext().getBean(CodeFirstRestTemplateSpringmvc.class); codeFirstClient.testCodeFirst(restTemplate, "springmvc", "/codeFirstSpringmvc/"); codeFirstClient.testCodeFirst(templateUrlWithProviderPrefix, "springmvc", "/pojo/rest/codeFirstSpringmvc/"); testAllTransport(microserviceName); testRestTransport(microserviceName, prefix); CategorizedTestCaseRunner.runCategorizedTestCase(microserviceName); }
Example #9
Source File: ServiceCenterDiscoveryConfig.java From servicecomb-saga-actuator with Apache License 2.0 | 4 votes |
@Bean RestTransport restTransport() { return new RestTemplateTransport(RestTemplateBuilder.create(), PROTOCOL); }
Example #10
Source File: BeanParamRestTemplateClient.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
public BeanParamRestTemplateClient() { restTemplate = RestTemplateBuilder.create(); }