List of usage examples for org.springframework.http HttpEntity HttpEntity
public HttpEntity(MultiValueMap<String, String> headers)
From source file:org.appverse.web.framework.backend.frontfacade.rest.MvcExceptionHandlerTests.java
@Test public void testNotFound() throws Exception { // Login first TestLoginInfo loginInfo = login();//www. j a v a 2s . 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 + "/badurl") .queryParam(DEFAULT_CSRF_PARAMETER_NAME, loginInfo.getXsrfToken()); ResponseEntity<String> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.GET, entity, String.class); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchDiseases.java
/** * Method, where all diseases are read from server. * All heavy lifting is made here./*from w w w. j av a 2 s.c om*/ * * @param params omitted here * @return list of fetched diseases */ @Override protected List<Disease> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_DISEASES; setState(RUNNING, R.string.working_ws_disease); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<DiseaseList> response = restTemplate.exchange(url, HttpMethod.GET, entity, DiseaseList.class); DiseaseList body = response.getBody(); if (body != null) { return body.getDiseases(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:com.xyxy.platform.examples.showcase.functional.rest.UserRestFT.java
/** * exchange()?Headers./* ww w . j av a2 s . c o m*/ * xml??. * jdk connection. */ @Test public void getUserAsXML() { // Http Basic? HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(com.google.common.net.HttpHeaders.AUTHORIZATION, Servlets.encodeHttpBasic("admin", "admin")); System.out.println("Http header is" + requestHeaders); HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); try { HttpEntity<UserDTO> response = jdkTemplate.exchange(resourceUrl + "/{id}.xml", HttpMethod.GET, requestEntity, UserDTO.class, 1L); assertThat(response.getBody().getLoginName()).isEqualTo("admin"); assertThat(response.getBody().getName()).isEqualTo("?"); assertThat(response.getBody().getTeamId()).isEqualTo(1); // ?XML HttpEntity<String> xml = jdkTemplate.exchange(resourceUrl + "/{id}.xml", HttpMethod.GET, requestEntity, String.class, 1L); System.out.println("xml output is " + xml.getBody()); } catch (HttpStatusCodeException e) { fail(e.getMessage()); } }
From source file:com.wisemapping.test.rest.RestAccountITCase.java
private ResponseEntity<RestUser> findUser(HttpHeaders requestHeaders, RestTemplate templateRest, URI location) { HttpEntity<RestUser> findUserEntity = new HttpEntity<RestUser>(requestHeaders); final String url = HOST_PORT + location; return templateRest.exchange(url, HttpMethod.GET, findUserEntity, RestUser.class); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchArtifacts.java
/** * Method, where all artifacts are read from server. * All heavy lifting is made here./*from w w w . j av a2 s . c o m*/ * * @param params omitted here * @return list of fetched artifacts */ @Override protected List<Artifact> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_ARTIFACTS; setState(RUNNING, R.string.working_ws_artifacts); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<ArtifactList> response = restTemplate.exchange(url, HttpMethod.GET, entity, ArtifactList.class); ArtifactList body = response.getBody(); if (body != null) { return body.getArtifacts(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchHardwareList.java
/** * Method, where all hardwareList are read from server. * All heavy lifting is made here.// w w w. j a va 2s . c o m * * @param params omitted here * @return list of fetched hardware */ @Override protected List<Hardware> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_HARDWARE; setState(RUNNING, R.string.working_ws_hardware); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<HardwareList> response = restTemplate.exchange(url, HttpMethod.GET, entity, HardwareList.class); HardwareList body = response.getBody(); if (body != null) { return body.getHardwareList(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchSoftwareList.java
/** * Method, where all softwareList are read from server. * All heavy lifting is made here./*from w w w . j a v a 2 s . c o m*/ * * @param params omitted here * @return list of fetched software */ @Override protected List<Software> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_SOFTWARE; setState(RUNNING, R.string.working_ws_software); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<SoftwareList> response = restTemplate.exchange(url, HttpMethod.GET, entity, SoftwareList.class); SoftwareList body = response.getBody(); if (body != null) { return body.getSoftwareList(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:com.ctrip.infosec.rule.rest.RuleEngineRESTfulControllerTest.java
@Test @Ignore/*ww w .j a v a 2s .c om*/ public void testQuery() throws Exception { System.out.println("query"); String response = Request.Post("http://10.2.10.77:8080/ruleenginews/rule/query") .body(new StringEntity(JSON.toJSONString(fact), "UTF-8")).connectTimeout(1000).socketTimeout(5000) .execute().returnContent().asString(); System.out.println("response: " + response); ResponseEntity<String> responseEntity = rt.exchange("http://10.2.10.77:8080/ruleenginews/rule/query", HttpMethod.POST, new HttpEntity<String>(JSON.toJSONString(fact)), String.class); System.out.println("response: " + responseEntity.getBody()); }
From source file:com.acc.test.UserWebServiceTest.java
@Test() public void testGetUser_Success_JSON_Deep() { final HttpEntity<String> requestEntity = new HttpEntity<String>(getJSONHeaders()); final ResponseEntity<CustomerData> response = template.exchange( "http://localhost:9001/rest/v1/users/{userid}", HttpMethod.GET, requestEntity, CustomerData.class, TestConstants.USERNAME);/* ww w . ja v a 2s .c o m*/ assertEquals("application/json;charset=UTF-8", response.getHeaders().getContentType().toString()); final CustomerData customer = response.getBody(); assertEquals("Klaus Demokunde", customer.getName()); assertEquals("demo", customer.getUid()); assertNotNull(customer.getCurrency()); assertNotNull(customer.getLanguage()); assertNotNull(customer.getDefaultBillingAddress()); assertNotNull(customer.getDefaultShippingAddress()); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchDigitizations.java
/** * Method, where all digitizations are read from server. * All heavy lifting is made here./*from w w w . j a v a 2 s .c o m*/ * * @param params omitted here * @return list of fetched digitizations */ @Override protected List<Digitization> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_DIGITIZATIONS; setState(RUNNING, R.string.working_ws_digitization); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<DigitizationList> response = restTemplate.exchange(url, HttpMethod.GET, entity, DigitizationList.class); DigitizationList body = response.getBody(); if (body != null) { return body.getDigitizations(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }