List of usage examples for org.springframework.http HttpEntity HttpEntity
public HttpEntity(MultiValueMap<String, String> headers)
From source file:org.energyos.espi.thirdparty.repository.impl.UsagePointRESTRepositoryImpl.java
private HttpEntity<String> getUsagePoints(Authorization authorization) { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("Authorization", "Bearer " + authorization.getAccessToken()); @SuppressWarnings({ "rawtypes", "unchecked" }) HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); return template.exchange(authorization.getResourceURI(), HttpMethod.GET, requestEntity, String.class); }
From source file:org.appverse.web.framework.backend.frontfacade.rest.MvcExceptionHandlerTests.java
@Test public void testExceptionHandler() throws Exception { // Login first TestLoginInfo loginInfo = login();//from ww w . ja va 2 s . c o m HttpHeaders headers = new HttpHeaders(); headers.set("Cookie", loginInfo.getJsessionid()); HttpEntity<String> entity = new HttpEntity<String>(headers); // Calling protected resource - requires CSRF token UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl("http://localhost:" + port + baseApiPath + "/exc") .queryParam(DEFAULT_CSRF_PARAMETER_NAME, loginInfo.getXsrfToken()); ResponseEntity<ResponseDataVO> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, ResponseDataVO.class); ResponseDataVO data = responseEntity.getBody(); assertEquals(500, data.getErrorVO().getCode()); assertTrue("contains message", data.getErrorVO().getMessage().contains("kk")); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); }
From source file:com.github.ffremont.microservices.springboot.manager.nexus.NexusClientApi.java
/** * A METTRE EN CACHE//from w ww. ja va 2 s.c o m * Retourne la donne Nexus correspondant au binaire * * @param groupId * @param artifact * @param classifier * @param version * @param packaging * @return */ public NexusData getData(String groupId, String artifact, String packaging, String classifier, String version) { NexusData data = null; HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.parseMediaType(MediaType.APPLICATION_JSON.toString()))); HttpEntity<NexusDataResult> entity = new HttpEntity<>(headers); String template = nexusProps.getBaseurl() + "/service/local/artifact/maven/resolve?r={r}&g={g}&a={a}&v={v}&p={p}", url; for (String repo : nexusProps.getRepo()) { url = template.replace("{r}", repo).replace("{g}", groupId).replace("{a}", artifact) .replace("{v}", version).replace("{p}", packaging); if (classifier != null) { url = url.concat("&c=" + classifier); } try { LOG.info("nexusClient url {}", url); ResponseEntity<NexusDataResult> response = this.nexusClient.exchange(url, HttpMethod.GET, entity, NexusDataResult.class); data = response.getBody().getData(); LOG.info("Rcupration avec succs de nexus"); break; } catch (HttpClientErrorException hee) { if (!HttpStatus.NOT_FOUND.equals(hee.getStatusCode())) { LOG.warn("Nexus : erreur cliente", hee); throw hee; } } } return data; }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStep.java
/** * CloudFoundry API requires an array of files it already has in cache. * We're sending an empty array here. //from www. ja v a2 s . c o m * * @return */ private HttpEntity<String> prepareResourcesRequestPart() { String resourcesJson = "[]"; return new HttpEntity<>(resourcesJson); }
From source file:com.catalog.core.Api.java
@Override public int login(String username, String password) { setStartTime();/*from ww w . ja va2 s. co m*/ String url = "http://" + IP + EXTENSION + "/resources/j_spring_security_check"; // Set the username and password for creating a Basic Auth request HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); // Make the HTTP GET request, marshaling the response from JSON to // an array of Events try { restTemplate.exchange(url, HttpMethod.GET, requestEntity, Object.class); } catch (Exception e) { // Unauthorized, probably. // maybe check for network status? e.printStackTrace(); if (e.getMessage().contains("Unauthorized")) return UNAUTHORIZED; return BAD_CONNECTION; } // everything went fine setLoginCredentials(username, password); getElapsedTime("login - "); return SUCCESS; }
From source file:org.cloudfoundry.identity.uaa.login.integration.AutologinContollerIntegrationTests.java
@Test public void testClientUnauthorized() { AutologinRequest request = new AutologinRequest(); request.setUsername(testAccounts.getUserName()); request.setPassword(testAccounts.getPassword()); @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/autologin"), HttpMethod.POST, new HttpEntity<AutologinRequest>(request), Map.class); assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); @SuppressWarnings("unchecked") Map<String, Object> result = (Map<String, Object>) entity.getBody(); assertNull(result.get("code")); }
From source file:org.gliderwiki.admin.PatchController.java
/** * ???? . ??? ? . // w ww. ja v a 2 s .c o m * @param request * @param response * @param modelAndView * @return * @throws Throwable */ @RequestMapping(value = "/admin/patch", method = RequestMethod.GET) public ModelAndView adminPatch(HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView) throws Throwable { logger.debug("### adminLogin "); String svcPath = request.getSession().getServletContext() .getRealPath(SystemConst.PROPERTY_FULL_PATH + "version"); boolean isServer = false; // ??? Properties props = PropertyUtil.getVersionPropertyInfo(svcPath, isServer); String clientVersion = props.getProperty("version.info"); // ??? ? config.properties ? . String configPath = request.getSession().getServletContext() .getRealPath(SystemConst.PROPERTY_FULL_PATH + "config"); Properties config = PropertyUtil.getPropertyInfo(configPath, SystemConst.CONFIG_NAME); String weDomain = config.getProperty("we.domain"); String weEmail = config.getProperty("we.email"); String activeKey = config.getProperty("we.active.key"); String serverDomain = config.getProperty("server.domain"); logger.debug("#weDomain : " + weDomain); logger.debug("#weEmail : " + weEmail); logger.debug("#activeKey : " + activeKey); PatchInfoVo vo = new PatchInfoVo(); vo.setWeDomain(weDomain); vo.setWeEmail(weEmail); vo.setWeActiveKey(activeKey); vo.setWeVersionInfo(clientVersion); // RestTemplate GLiDER ? . HttpEntity<PatchInfoVo> entity = new HttpEntity<PatchInfoVo>(vo); String restUrl = REST_SERVER_URL + "/service/patchService"; ResponseEntity<PatchInfoVo> entityResponse = restTemplate.postForEntity(restUrl, entity, PatchInfoVo.class); PatchInfoVo patch = entityResponse.getBody(); logger.debug("###patch : " + patch.toString()); // version 1.1.2 ? ?? rest parameter ? // ? - replace String version = clientVersion.replaceAll("\\.", "-"); ResponseEntity<WeFunction[]> weFunctionList = null; if (!clientVersion.equals(patch.getWeServerVerionInfo())) { String listUrl = REST_SERVER_URL + "/service/patchList/" + version; logger.debug("###listUrl : " + listUrl); weFunctionList = restTemplate.getForEntity(listUrl, WeFunction[].class); } WeFunction[] list = null; if (weFunctionList != null) { list = weFunctionList.getBody(); } modelAndView.addObject("menu", "4"); modelAndView.addObject("serverVersion", patch.getWeServerVerionInfo()); modelAndView.addObject("clientVersion", clientVersion); modelAndView.addObject("list", list); modelAndView.setViewName("admin/extension/patchMgr"); return modelAndView; }
From source file:org.terasoluna.gfw.functionaltest.app.logging.LoggingTest.java
@Test public void test01_06_checkLoggingSameXtrackMDCRequestToLog() { driver.findElement(By.id("xTrackMDCPutFilter")).click(); // create default x-Track MDC driver.findElement(By.id("xTrackMDCPutFilterDefault")).click(); // cut x-Track MDC String targetMdc = driver.findElement(By.id("xTrackMDC")).getText(); // logging same x-track MDC HTTP Request Header HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("X-Track", targetMdc); restTemplate.exchange(applicationContextUrl + "/logging/xTrackMDCPutFilter/1_4", HttpMethod.GET, new HttpEntity<byte[]>(requestHeaders), byte[].class); // check XTrack logging same transaction in HTTP Request Header to logfile // check visually the log file // filename:traceLoggingInterceptorTest.log }
From source file:com.ge.predix.acceptance.test.zone.admin.DefaultZoneAuthorizationIT.java
/** * 1. Create a token from zone issuer with scopes for accessing: a. zone specific resources, AND b. * acs.zones.admin/*from w w w . j a va 2 s . c om*/ * * 2. Try to access a zone specific resource . This should work 3. Try to access /v1/zone - THIS SHOULD FAIL * * @throws Exception */ public void testAccessGlobalResourceWithZoneIssuer() throws Exception { OAuth2RestTemplate zone2AcsTemplate = this.acsRestTemplateFactory.getACSZone2RogueTemplate(); HttpHeaders zoneTwoHeaders = new HttpHeaders(); zoneTwoHeaders.set(PolicyHelper.PREDIX_ZONE_ID, this.zoneHelper.getZone2Name()); // Write a resource to zone2. This should work ResponseEntity<Object> responseEntity = this.privilegeHelper.postResources(zone2AcsTemplate, zoneHelper.getAcsBaseURL(), zoneTwoHeaders, new BaseResource("/sites/sanramon")); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.NO_CONTENT); // Try to get global resource from global/baseUrl. This should FAIL try { zone2AcsTemplate.exchange(this.zoneHelper.getAcsBaseURL() + "/v1/zone/" + this.zone2Name, HttpMethod.GET, null, Zone.class); Assert.fail("Able to access non-zone specific resource with a zone specific issuer token!"); } catch (OAuth2AccessDeniedException e) { // expected } // Try to get global resource from zone2Url. This should FAIL try { zone2AcsTemplate.exchange(this.zoneHelper.getAcsBaseURL() + "/v1/zone/" + this.zone2Name, HttpMethod.GET, new HttpEntity<>(zoneTwoHeaders), Zone.class); Assert.fail("Able to access non-zone specific resource from a zone specific URL, " + "with a zone specific issuer token!"); } catch (InvalidRequestException e) { // expected } }