List of usage examples for org.springframework.http.converter StringHttpMessageConverter StringHttpMessageConverter
public StringHttpMessageConverter()
From source file:com.music.web.AuthenticationController.java
public AuthenticationController() { HttpMessageConverter<?> formHttpMessageConverter = new FormHttpMessageConverter(); HttpMessageConverter<?> stringHttpMessageConverternew = new StringHttpMessageConverter(); restTemplate.getMessageConverters().add(formHttpMessageConverter); restTemplate.getMessageConverters().add(stringHttpMessageConverternew); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.UploadDataFile.java
/** * Method, where data file information is pushed to server in order to create data file record. * All heavy lifting is made here./* w w w . j a v a2s .c om*/ * * @param dataFileContents must be three params in order - experiment id, description, path to file * @return URI of uploaded file */ @Override protected URI doInBackground(String... dataFileContents) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_DATAFILE; setState(RUNNING, R.string.working_ws_upload_data_file); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); //so files wont buffer in memory factory.setBufferRequestBody(false); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); restTemplate.getMessageConverters().add(new FormHttpMessageConverter()); try { Log.d(TAG, url); FileSystemResource toBeUploadedFile = new FileSystemResource(dataFileContents[2]); MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>(); form.add("experimentId", dataFileContents[0]); form.add("description", dataFileContents[1]); form.add("file", toBeUploadedFile); HttpEntity<Object> entity = new HttpEntity<Object>(form, requestHeaders); // Make the network request return restTemplate.postForLocation(url, entity); } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return null; }
From source file:com.github.cherimojava.orchidae.config.WebMvcConfig.java
@Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { converters.add(entityConverter(factory)); converters.add(new StringHttpMessageConverter()); converters.add(new ResourceHttpMessageConverter()); // converters.add(new ByteArrayHttpMessageConverter()); super.configureMessageConverters(converters); }
From source file:uy.edu.ort.fachada.FachadaOperaciones.java
/** * Operaciones sobre la Entidad Arribo/*from w ww .ja va 2 s . c om*/ */ public static void generarReporteArribosMes(String mes) { String url = ManejoPropiedades.obtenerInstancia().obtenerPropiedad("restService") + "restarribo/arribos.htm?mes=" + mes; RestTemplate restTemplate1 = new RestTemplate(); restTemplate1.getMessageConverters().add(new StringHttpMessageConverter()); restTemplate1.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); Arribo[] arribosResultado = restTemplate1.getForObject(url, Arribo[].class); System.out.println("\tId \t\tOrigen \t\tFecha \t\tDescripcion \t\tBarco \t\tContenedores"); for (Arribo arribo : arribosResultado) { String fechaString = new SimpleDateFormat("dd-MM-yyyy").format(arribo.getFecha()); String codigoConts = ""; for (Object c : arribo.getContenedores()) { codigoConts += " - " + ((LinkedHashMap) c).get("codigo"); } codigoConts += " - "; System.out.println("\t" + arribo.getId() + "\t\t" + arribo.getOrigen() + " \t\t" + fechaString + " \t\t" + arribo.getDescripcion() + " \t\t" + arribo.getBarco().getCodigo() + " \t\t" + codigoConts); } }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateScenario.java
/** * Method, where scenario information is pushed to server in order to new scenario. * All heavy lifting is made here.//from w w w . j a va 2 s . co m * * @param scenarios only one scenario is accepted - scenario to be uploaded * @return scenario stored */ @Override protected Scenario doInBackground(Scenario... scenarios) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_SCENARIOS; setState(RUNNING, R.string.working_ws_create_scenario); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); //so files wont buffer in memory factory.setBufferRequestBody(false); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); restTemplate.getMessageConverters().add(new FormHttpMessageConverter()); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); Scenario scenario = scenarios[0]; try { Log.d(TAG, url); FileSystemResource toBeUploadedFile = new FileSystemResource(scenario.getFilePath()); //due to multipart file, MultiValueMap is the simplest approach for performing the post request MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>(); form.add("scenarioName", scenario.getScenarioName()); form.add("researchGroupId", scenario.getResearchGroupId()); form.add("description", scenario.getDescription()); form.add("mimeType", scenario.getMimeType()); form.add("private", Boolean.toString(scenario.isPrivate())); form.add("file", toBeUploadedFile); HttpEntity<Object> entity = new HttpEntity<Object>(form, requestHeaders); // Make the network request ResponseEntity<Scenario> response = restTemplate.postForEntity(url, entity, Scenario.class); return response.getBody(); } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return null; }
From source file:org.jnrain.mobile.service.JNRainSpiceService.java
@Override public RestTemplate createRestTemplate() { RestTemplate restTemplate = new GzipRestTemplate(); // find more complete examples in RoboSpice Motivation app // to enable Gzip compression and setting request timeouts. // web services support json responses MappingJacksonHttpMessageConverter jsonConverter = new MappingJacksonHttpMessageConverter(); FormHttpMessageConverter formHttpMessageConverter = new FormHttpMessageConverter(); StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(); final List<HttpMessageConverter<?>> listHttpMessageConverters = restTemplate.getMessageConverters(); listHttpMessageConverters.add(jsonConverter); listHttpMessageConverters.add(formHttpMessageConverter); listHttpMessageConverters.add(stringHttpMessageConverter); restTemplate.setMessageConverters(listHttpMessageConverters); // timeout/*from w w w . ja va 2s . co m*/ manageTimeOuts(restTemplate); // session interceptor restTemplate.setInterceptors(_interceptors); return restTemplate; }
From source file:com.taxamo.example.ec.ApplicationController.java
/** * This method initializes Express Checkout token with PayPal and then redirects to Taxamo checkout form. * * Please note that only Express Checkout token is provided to Taxamo - and Taxamo will use * provided PayPal credentials to get order details from it and render the checkout form. * * * @param model// ww w . j a v a 2 s . com * @return */ @RequestMapping("/express-checkout") public String expressCheckout(Model model) { RestTemplate template = new RestTemplate(); MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.add("USER", ppUser); map.add("PWD", ppPass); map.add("SIGNATURE", ppSign); map.add("VERSION", "117"); map.add("METHOD", "SetExpressCheckout"); map.add("returnUrl", properties.getProperty(PropertiesConstants.STORE) + properties.getProperty(PropertiesConstants.CONFIRM_LINK)); map.add("cancelUrl", properties.getProperty(PropertiesConstants.STORE) + properties.getProperty(PropertiesConstants.CANCEL_LINK)); //shopping item(s) map.add("PAYMENTREQUEST_0_AMT", "20.00"); // total amount map.add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale"); map.add("PAYMENTREQUEST_0_CURRENCYCODE", "EUR"); map.add("L_PAYMENTREQUEST_0_NAME0", "ProdName"); map.add("L_PAYMENTREQUEST_0_DESC0", "ProdName desc"); map.add("L_PAYMENTREQUEST_0_AMT0", "20.00"); map.add("L_PAYMENTREQUEST_0_QTY0", "1"); map.add("L_PAYMENTREQUEST_0_ITEMCATEGORY0", "Digital"); List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); messageConverters.add(new FormHttpMessageConverter()); messageConverters.add(new StringHttpMessageConverter()); template.setMessageConverters(messageConverters); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, requestHeaders); ResponseEntity<String> res = template.exchange( URI.create(properties.get(PropertiesConstants.PAYPAL_NVP).toString()), HttpMethod.POST, request, String.class); Map<String, List<String>> params = parseQueryParams(res.getBody()); String ack = params.get("ACK").get(0); if (!ack.equals("Success")) { model.addAttribute("error", params.get("L_LONGMESSAGE0").get(0)); return "error"; } else { String token = params.get("TOKEN").get(0); return "redirect:" + properties.get(PropertiesConstants.TAXAMO) + "/checkout/index.html?" + "token=" + token + "&public_token=" + publicToken + "&cancel_url=" + new String( Base64.encodeBase64((properties.getProperty(PropertiesConstants.STORE) + properties.getProperty(PropertiesConstants.CANCEL_LINK)).getBytes())) + "&return_url=" + new String(Base64.encodeBase64((properties.getProperty(PropertiesConstants.STORE) + properties.getProperty(PropertiesConstants.CONFIRM_LINK)).getBytes())) + "#/paypal_express_checkout"; } }
From source file:com.github.cherimojava.orchidae.controller._PictureController.java
@Before public void setup() { controller = new PictureController(); controller.userUtil = userUtil;/*from w ww . j a va 2 s. com*/ controller.factory = factory; controller.fileUtil = fileUtil; controller.latestPictureLimit = 10; mvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(new EntityConverter(factory), new StringHttpMessageConverter(), new ResourceHttpMessageConverter()).build(); setAuthentication(owner); factory.create(User.class).setUsername(ownr).setPassword("1").setMemberSince(DateTime.now()).save(); session = new MockHttpSession(); session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext()); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.RemoveReservation.java
/** * Method, where reservation information is pushed to server in order to remove it. * All heavy lifting is made here.//from w w w.j a v a2 s . co m * * @param params only one Reservation object is accepted * @return true if reservation is removed */ @Override protected Boolean doInBackground(Reservation... params) { Reservation data = params[0]; //nothing to remove if (data == null) return false; try { setState(RUNNING, R.string.working_ws_remove); SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_RESERVATION + data.getReservationId(); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); HttpEntity<Reservation> entity = new HttpEntity<Reservation>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); Log.d(TAG, url + "\n" + entity); restTemplate.exchange(url, HttpMethod.DELETE, entity, String.class); return true; } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage()); setState(ERROR, e); } finally { setState(DONE); } return false; }
From source file:au.org.ala.fielddata.mobile.service.FieldDataServiceClient.java
public List<Survey> downloadSurveys(FieldDataService.SurveyDownloadCallback callback) { String url = getServerUrl() + surveyUrl + ident; RestTemplate restTemplate = getRestTemplate(); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); Log.d("URL", url); UserSurveyResponse[] result = restTemplate.getForObject(url, UserSurveyResponse[].class); url = getServerUrl() + surveyDetails; List<Survey> surveys = new ArrayList<Survey>(); List<Integer> speciesIdList = new ArrayList<Integer>(); //List<Species> species = new ArrayList<Species>(); int count = 0; int total = result.length; for (UserSurveyResponse userSurvey : result) { String downloadedSurveys = jsonSurveyIds(surveys); if (callback != null) { callback.surveysDownloaded(++count, total); }// w w w. java2 s.c o m Log.d("URL", String.format(url, userSurvey.id, ident, downloadedSurveys)); DownloadSurveyResponse surveyResponse = restTemplate.getForObject( String.format(url, userSurvey.id, ident, downloadedSurveys), DownloadSurveyResponse.class); Survey survey = mapSurvey(surveyResponse); surveys.add(survey); List<Integer> speciesIds = surveyResponse.details.speciesIds; if (speciesIds != null) { speciesIdList.addAll(surveyResponse.details.speciesIds); } //species.addAll(downloadSpecies(survey)); } System.out.println(speciesIdList); return surveys; }