List of usage examples for org.springframework.web.client RestTemplate exchange
@Override public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException
From source file:org.apache.servicecomb.demo.jaxrs.client.JaxrsClient.java
private static void testValidatorSayHiSuccess(RestTemplate template, String cseUrlPrefix) { ResponseEntity<String> responseEntity = template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "world"); TestMgr.check(202, responseEntity.getStatusCode()); TestMgr.check("world sayhi", responseEntity.getBody()); }
From source file:org.apache.servicecomb.demo.jaxrs.client.JaxrsClient.java
@SuppressWarnings({ "rawtypes" }) private static void testValidatorSayHiFail(RestTemplate template, String cseUrlPrefix) { boolean isExcep = false; try {//from www . ja v a 2 s . c om template.exchange(cseUrlPrefix + "sayhi/{name}", HttpMethod.PUT, null, String.class, "te"); } catch (InvocationException e) { isExcep = true; TestMgr.check(400, e.getStatus().getStatusCode()); TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase()); // Message dependends on locale, so just check the short part. Map data = (Map) e.getErrorData(); TestMgr.check(true, data.get("message").toString().contains("propertyPath=sayHi.name")); } TestMgr.check(true, isExcep); }
From source file:com.rsa.redchallenge.standaloneapp.utils.RestInteractor.java
/** * Function to call GET interface for a REST server * * @param response Format in this the response of the call needs to be parsed * @param path path of the interface in the REST server to be called * @param params parameter for the call * @param <T> template class according to which response needs to be parsed * @return returns the response in format specified * @throws RestClientException throws in case of error *//*from w w w . j a v a2 s. co m*/ public static <T> T performGet(Class<T> response, String path, Map<String, Object> params, String jsessionId) throws SecurityException { RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory()); setFactory(restTemplate); HttpHeaders headers = new HttpHeaders(); headers.add("Cookie", "RSA_SA_LICENSE=true; " + jsessionId); String uri = populatePath(params, path); logger.info("performing get request for uri:" + uri); HttpEntity<String> request = new HttpEntity<>(headers); try { T result = restTemplate.exchange(uri, HttpMethod.GET, request, response, getObjectParams(params)) .getBody(); return result; } catch (HttpClientErrorException e) { throw e; } }
From source file:com.wmfsystem.eurekaserver.broadcast.Server.java
public void run() { try {//from w w w . j a v a2 s. c o m socket = new DatagramSocket(DEFAULT_PORT); } catch (Exception ex) { System.out.println("Problem creating socket on port: " + DEFAULT_PORT); } packet = new DatagramPacket(new byte[1], 1); while (true) { try { socket.receive(packet); System.out.println("Received from: " + packet.getAddress() + ":" + packet.getPort()); byte[] outBuffer = new java.util.Date().toString().getBytes(); packet.setData(outBuffer); packet.setLength(outBuffer.length); socket.setBroadcast(true); socket.send(packet); Set<InetAddress> localAddress = getLocalAddress(); Set<String> ips = localAddress.stream().map(ad -> ad.getHostAddress()).collect(Collectors.toSet()) .stream().sorted().collect(Collectors.toSet()); RestTemplate template = new RestTemplate(); ips.forEach(ip -> { template.exchange("http://" + packet.getAddress().getHostAddress().concat(":8000?ip={ip}"), HttpMethod.GET, HttpEntity.EMPTY, Void.class, ip.concat(":8000")); try { template.exchange("http://" + packet.getAddress().getHostAddress().concat(":8000?ip={ip}"), HttpMethod.GET, HttpEntity.EMPTY, Void.class, ip.concat(":8000")); } catch (Exception e) { e.printStackTrace(); } }); System.out.println("Message ----> " + packet.getAddress().getHostAddress()); } catch (IOException ie) { ie.printStackTrace(); } } }
From source file:org.cloudfoundry.identity.uaa.integration.util.IntegrationTestUtils.java
public static BaseClientDetails updateClient(RestTemplate template, String url, BaseClientDetails client) throws Exception { ResponseEntity<BaseClientDetails> response = template.exchange(url + "/oauth/clients/{clientId}", HttpMethod.PUT, new HttpEntity<>(client), BaseClientDetails.class, client.getClientId()); return response.getBody(); }
From source file:com.wisemapping.test.rest.RestAccountITCase.java
private ResponseEntity<RestUser> findUserByEmail(HttpHeaders requestHeaders, RestTemplate templateRest, final String email) { HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders); // Add extension only to avoid the fact that the last part is extracted ... final String url = BASE_REST_URL + "/admin/users/email/{email}.json"; return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class, email); }
From source file:se.vgregion.alfrescoclient.service.AlfrescoService.java
/** * This method returns the Alfresco sites that a user is a member of. * * @param user - user id/*from w ww .j a v a 2 s . c o m*/ * @param csIframePage the url to the page holding the Alfresco CSIframe * @param portletInstance the id of the CSIframe portletInstance * @return Alfresco sites for a user. */ public List<Site> getPublicSites(String user, String csIframePage, String portletInstance) { RestTemplate template = initJsonRestTemplate(); String apiURL = server + PUBLIC_SITES; HttpEntity<String> httpEntity = setUpHttpEntity(user); ResponseEntity<Site[]> httpResponseEntity = template.exchange(apiURL, HttpMethod.GET, httpEntity, Site[].class, new HashMap<String, String>()); List<Site> sites = Arrays.asList(httpResponseEntity.getBody()); List<Site> sitesWithDashboardURLs = addAlfrescoShareDashboardURLs(sites, csIframePage, portletInstance); return sitesWithDashboardURLs; }
From source file:se.vgregion.alfrescoclient.service.AlfrescoService.java
/** * This method returns the Alfresco sites that a user is a member of. * * @param user user id// w w w. j av a2 s .c o m * @param csIframePage the url to the page holding the Alfresco CSIframe * @param portletInstance the id of the CSIframe portletInstance * @return Alfresco sites for a user. */ public List<Site> getSitesByUser(String user, String csIframePage, String portletInstance) { RestTemplate template = initJsonRestTemplate(); String apiURL = server + API_PEOPLE + user + SITES; HttpEntity<String> httpEntity = setUpHttpEntity(user); ResponseEntity<Site[]> httpResponseEntity = template.exchange(apiURL, HttpMethod.GET, httpEntity, Site[].class, new HashMap<String, String>()); List<Site> sites = Arrays.asList(httpResponseEntity.getBody()); List<Site> sitesWithDashboardURLs = addAlfrescoShareDashboardURLs(sites, csIframePage, portletInstance); return sitesWithDashboardURLs; }
From source file:se.vgregion.alfrescoclient.service.AlfrescoService.java
/** * Get a list of recently modified {@link Document}s which the given user is allowed to see and which is filtered * so that only documents from the given site is returned. * * @param user the user//from w w w. j ava 2s .c om * @param site the site which the {@link Document}s should exist in * @return a list of {@link Document}s */ public List<Document> getRecentlyModified(String user, String site) { RestTemplate template = initJsonRestTemplate(); String apiURL = server + RECENTLY_MODIFIED + site + RECENTLY_MODIFIED_2; HttpEntity<String> httpEntity = setUpHttpEntity(user); ResponseEntity<RecentModifiedDocuments> recentModifiedDocuments = template.exchange(apiURL, HttpMethod.GET, httpEntity, RecentModifiedDocuments.class, new HashMap<String, String>()); return recentModifiedDocuments.getBody().getItems(); }
From source file:se.vgregion.alfrescoclient.service.AlfrescoService.java
/** * Get {@link Events} for a user from a given date. * @param user the user//from ww w . java 2s.co m * @param fromDate the earliest point in time the events should start * @return the {@link Events} */ public Events getUserEvents(String user, DateTime fromDate) { RestTemplate template = initJsonRestTemplate(); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd"); String fromDateString = fmt.print(fromDate); String apiURL = server + EVENT_URL + fromDateString; HttpEntity<String> httpEntity = setUpHttpEntity(user); ResponseEntity<Events> httpResponseEntity = template.exchange(apiURL, HttpMethod.GET, httpEntity, Events.class, new HashMap<String, String>()); Events events = httpResponseEntity.getBody(); return events; }