List of usage examples for org.springframework.web.client RestTemplate getForObject
@Override @Nullable public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException
From source file:org.openinfinity.sso.common.ss.sp.filters.PreAuthenticatedTokenAuthenticationFilter.java
private org.springframework.security.core.Authentication springAuthenticationBy(final String ssoID) { LOG.debug("Building the authentication context by token"); org.springframework.security.core.Authentication springAuthentication = cache.authenticationBy(ssoID); if (springAuthentication != null) { LOG.debug("Auth {} found in cache by token {}", springAuthentication, ssoID); return springAuthentication; }// w w w . j a va 2s . c o m RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new SpringAuthenticationMessageConverter()); LOG.debug("No luck in cache, calling IDP by REST"); springAuthentication = restTemplate.getForObject(attributeURL, org.springframework.security.core.Authentication.class, ssoID); LOG.debug("Got authentication {} from IDP via REST", springAuthentication); cache.put(ssoID, springAuthentication); return springAuthentication; }
From source file:com.oneops.controller.cms.CMSClientTest.java
@SuppressWarnings("unchecked") @Test(priority = 11)// www . j a va2 s. c o m public void checkDeploymentTest() throws Exception { DelegateExecution delegateExecution = mock(DelegateExecution.class); CmsDeployment cmsDeployment = new CmsDeployment(); cmsDeployment.setCreatedBy("created-by-mock"); when(delegateExecution.getVariable("dpmt")).thenReturn(cmsDeployment); RestTemplate restTemplate = mock(RestTemplate.class); when(restTemplate.getForObject(anyString(), any(Class.class), anyLong())).thenReturn(cmsDeployment); try { cc.checkDpmt(delegateExecution); CmsDeployment cmsDeploymentPost = (CmsDeployment) delegateExecution.getVariable("dpmt"); assertEquals(cmsDeploymentPost.getCreatedBy(), "created-by-mock", "object mutated unexpectedly"); } catch (GeneralSecurityException e) { logger.warn("unexpected to catch here", e); throw e; } }
From source file:com.mycompany.story.StoryEditor.java
private void initData() throws IOException { RestTemplate restTemplate = new RestTemplate(); Properties properties = new Properties(); properties.load(new InputStreamReader(getClass().getResourceAsStream("/story.ini"))); String host = properties.getProperty("host"); String url = host + "/story"; restTemplate.getForObject(host, TopicResult.class, ImmutableMap.of("topicId", "1")); }
From source file:com.skipjaq.awspricing.pricing.AwsPricing.java
private PricingInfo getAwsPricing(String awsTemplatesUrl, String offerCode) { RestTemplate restTemplate = new RestTemplate(); MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); converter.setSupportedMediaTypes(/*from w w w .j av a 2 s . c om*/ Arrays.asList(new MediaType[] { MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM })); restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter())); return restTemplate.getForObject(awsTemplatesUrl, PricingInfo.class, offerCode); }
From source file:org.apigw.authserver.web.controller.MonitoringController.java
@RequestMapping(method = RequestMethod.GET, params = { "clientId", "state" }) public ModelAndView list(@RequestParam("clientId") String clientId, @RequestParam("state") String state, Authentication authentication) { Application application = appManagement.getApplicationByClientId(clientId); UserDetails user = (UserDetails) authentication.getPrincipal(); if (application == null) { throw new IllegalArgumentException("No application found with client id " + clientId); }//from ww w.j av a 2 s .co m if (!user.getUsername().equals(application.getDeveloper().getResidentIdentificationNumber())) { throw new IllegalArgumentException("Application developer is not the same as the logged in user"); } if (!state.toUpperCase().equals("SERVER_FAILURE") && !state.toUpperCase().equals("CLIENT_FAILURE") && !state.toUpperCase().equals("SUCCESS")) { throw new IllegalArgumentException("Provided state not recogonized: " + state); } TreeMap<String, Object> model = new TreeMap<String, Object>(); RestTemplate template = new RestTemplate(); long from = System.currentTimeMillis() - 24 * 3600 * 1000; Map<String, Object> params = new HashMap<String, Object>(); params.put("from", from); params.put("client", clientId); params.put("state", state); // Load list of last 100 failed requests List<Map<String, Object>> requests = template.getForObject( location + "/api/timeline/resourceRequest?from={from}&state={state}&client={client}", List.class, params); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (Map<String, Object> request : requests) { long timestamp = (Long) request.get("timestamp"); Date date = new Date(timestamp); request.put("datetime", format.format(date)); } model.put("requests", requests); model.put("client", clientId); model.put("state", state); return new ModelAndView("monitoring", model); }
From source file:com.oneops.controller.cms.CMSClientTest.java
@SuppressWarnings("unchecked") @Test/*from w w w . ja v a2s .c o m*/ public void checkDeploymentTestWithRestTemplateThrowExceptionShouldSucced() throws Exception { DelegateExecution delegateExecution = mock(DelegateExecution.class); CmsDeployment cmsDeployment = new CmsDeployment(); cmsDeployment.setCreatedBy("created-by-mock"); when(delegateExecution.getVariable("dpmt")).thenReturn(cmsDeployment); RestTemplate restTemplate = mock(RestTemplate.class); //when(restTemplate.getForObject(anyString(), any(Class.class) , anyLong())).thenThrow(new RestClientException("test")).thenReturn(cmsDeployment); when(restTemplate.getForObject(anyString(), any(Class.class), anyLong())) .thenThrow(new RestClientException("test")).thenThrow(new RestClientException("test")) .thenReturn(cmsDeployment); cc.setRestTemplate(restTemplate); try { cc.setRetryTemplate(cc.getRetryTemplate(3, 2000, 1000)); cc.checkDpmt(delegateExecution); CmsDeployment cmsDeploymentPost = (CmsDeployment) delegateExecution.getVariable("dpmt"); assertEquals(cmsDeploymentPost.getCreatedBy(), "created-by-mock", "object mutated unexpectedly"); } catch (GeneralSecurityException e) { logger.warn("unexpected to catch here", e); throw e; } }
From source file:com.wisemapping.rest.MindmapController.java
private MindMapVO fecthMindMap(int idMindmap, final Long concetpUserId) { RestTemplate restTemplate = new RestTemplate(); Map<String, String> vars = new HashMap<String, String>(); vars.put("id", Integer.toString(idMindmap)); vars.put("uid", Long.toString(concetpUserId)); // 69?uid=3/*w w w . ja v a 2s .c o m*/ // String myUrl = mindmapService.getUrlFetch() + userId; String myUrl = mindmapService.getUrlFetch(); ResponseVO responseVO = restTemplate.getForObject(myUrl, ResponseVO.class, vars); logger.debug(responseVO); logger.debug(responseVO.getReturnobject().getContent()); // String xmlStr = mindmap.getXmlStr(); MindMapVO mindMapVO = responseVO.getReturnobject(); return mindMapVO; }
From source file:nl.uva.mediamosa.impl.MediaMosaImpl.java
/** * @param url/*from w w w . java2 s .co m*/ * @param properties * @param parameters * @return * @throws IOException */ public Response doPostRequestWithParameters(String url, Map properties, Map parameters) throws IOException { RestTemplate template = new RestTemplate(); String uri = template.getForObject(url, String.class, properties); String paramstring = ""; if (parameters != null) { // iterate over key value pairs Iterator it = parameters.entrySet().iterator(); StringBuilder sb = new StringBuilder(); while (it.hasNext()) { sb.append('&'); Map.Entry pairs = (Map.Entry) it.next(); sb.append(pairs.getKey()).append('=').append(pairs.getValue()); } paramstring = sb.toString(); } return doPostRequest(uri, paramstring); }
From source file:nl.uva.mediamosa.impl.MediaMosaImpl.java
/** * @param url/* w ww . ja v a2 s. co m*/ * @param properties * @param parameters * @return * @throws IOException */ public Response doGetRequestWithParameters(String url, Map properties, Map parameters) throws IOException { RestTemplate template = new RestTemplate(); String uri = template.getForObject(url, String.class, properties); String paramstring = ""; if (parameters != null) { // iterate over key value pairs Iterator it = parameters.entrySet().iterator(); StringBuilder sb = new StringBuilder(); while (it.hasNext()) { sb.append('&'); Map.Entry pairs = (Map.Entry) it.next(); sb.append(pairs.getKey()).append('=').append(pairs.getValue()); } paramstring += "?" + sb.toString(); } return doGetRequest(uri + paramstring); }