List of usage examples for org.springframework.http.converter FormHttpMessageConverter FormHttpMessageConverter
public FormHttpMessageConverter()
From source file:com.taxamo.example.ec.ApplicationController.java
/** * This method is invoked after Taxamo has successfully verified tax location evidence and * created a transaction./*from w ww . j a v a 2 s . c o m*/ * * Two things happen then: * - first, the express checkout token is used to capture payment in PayPal * - next, transaction is confirmed with Taxamo * * After that, confirmation page is displayed to the customer. * * @param payerId * @param token * @param transactionKey * @param model * @return */ @RequestMapping(value = "/confirm") public String confirm(@RequestParam("PayerID") String payerId, @RequestParam("token") String token, @RequestParam("taxamo_transaction_key") String transactionKey, 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", "DoExpressCheckoutPayment"); map.add("PAYERID", payerId); map.add("TOKEN", token); GetTransactionOut transaction; //more transaction details should be verified in real-life implementation try { transaction = taxamoApi.getTransaction(transactionKey); } catch (ApiException e) { e.printStackTrace(); model.addAttribute("error", "ERROR result: " + e.getMessage()); return "error"; } map.add("PAYMENTREQUEST_0_CURRENCYCODE", "EUR"); map.add("PAYMENTREQUEST_0_AMT", transaction.getTransaction().getTotalAmount().toString()); map.add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale"); 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 { try { ConfirmTransactionOut transactionOut = taxamoApi.confirmTransaction(transactionKey, new ConfirmTransactionIn()); model.addAttribute("status", transactionOut.getTransaction().getStatus()); } catch (ApiException ae) { ae.printStackTrace(); model.addAttribute("error", "ERROR result: " + ae.getMessage()); return "error"; } model.addAttribute("taxamo_transaction_key", transactionKey); return "redirect:/success-checkout"; } }
From source file:com.catalog.core.Api.java
@Override public StudentMark addStudentMark(int studentId, int stfcId, int grade, boolean finalExam, long date) { setStartTime();/*from www . j av a 2 s. co m*/ HttpEntity<?> requestEntity = getAuthHttpEntity(); RestTemplate restTemplate = new RestTemplate(); // Add the Jackson message converter restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); restTemplate.getMessageConverters().add(new FormHttpMessageConverter()); int finalExamInt = finalExam ? 1 : 0; String url = "http://" + IP + EXTENSION + "/teacher/formStudentMarkT/" + studentId + "," + stfcId + "," + grade + "," + finalExamInt + "," + date + ".json"; ResponseEntity<StudentMarkVM> responseEntity = null; StudentMarkVM response = null; try { responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, StudentMarkVM.class); response = responseEntity.getBody(); } catch (RestClientException e) { return null; } Log.d("TAAAG", response.toString()); getElapsedTime("addStudentMark - "); return response.getStudentMark(); }
From source file:org.appverse.web.framework.backend.frontfacade.websocket.IntegrationWebsocketTest.java
private static void loginAndSaveJsessionIdCookie(final String user, final String password, final HttpHeaders headersToUpdate) { String url = "http://localhost:" + port + "/"; new RestTemplate().execute(url, HttpMethod.POST, new RequestCallback() { @Override/*w w w. j a va 2 s . c om*/ public void doWithRequest(ClientHttpRequest request) throws IOException { MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); map.add("username", user); map.add("password", password); new FormHttpMessageConverter().write(map, MediaType.APPLICATION_FORM_URLENCODED, request); } }, new ResponseExtractor<Object>() { @Override public Object extractData(ClientHttpResponse response) throws IOException { headersToUpdate.add("Cookie", response.getHeaders().getFirst("Set-Cookie")); return null; } }); }
From source file:org.starfishrespect.myconsumption.android.ui.ChartChoiceFragment.java
private void deleteSensor(int index) { AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setTitle(R.string.dialog_title_confirmation); builder.setMessage(//from w w w . j ava 2 s.c om String.format(getResources().getString(R.string.dialog_message_confirmation_delete_sensor), sensors.get(lastLongClickItem).getName())); builder.setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setPositiveButton(R.string.button_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new AsyncTask<Void, Boolean, Void>() { @Override protected Void doInBackground(Void... params) { RestTemplate template = new RestTemplate(); HttpHeaders httpHeaders = CryptoUtils.createHeadersCurrentUser(); template.getMessageConverters().add(new FormHttpMessageConverter()); template.getMessageConverters().add(new StringHttpMessageConverter()); String url = SingleInstance.getServerUrl() + "users/" + SingleInstance.getUserController().getUser().getName() + "/sensor/" + sensors.get(lastLongClickItem).getSensorId(); template.exchange(url, HttpMethod.DELETE, new HttpEntity<>(httpHeaders), String.class); try { SingleInstance.getDatabaseHelper().getSensorDao() .delete(sensors.get(lastLongClickItem)); new SensorValuesDao(SingleInstance.getDatabaseHelper()) .removeSensor(sensors.get(lastLongClickItem).getSensorId()); } catch (SQLException e) { publishProgress(false); } publishProgress(true); return null; } @Override protected void onProgressUpdate(Boolean... values) { for (boolean b : values) { if (b) { new AlertDialog.Builder(mActivity).setTitle(R.string.dialog_title_information) .setMessage(R.string.dialog_message_information_sensor_deleted) .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { EventBus.getDefault().post(new ReloadUserEvent(false)); dialog.dismiss(); } }) .show(); } else { new AlertDialog.Builder(mActivity).setTitle(R.string.dialog_title_information) .setMessage("unknown error while deleting from DB").setPositiveButton( R.string.button_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .show(); } } } }.execute(); dialog.dismiss(); } }); builder.show(); }
From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.CrowdClient.java
/** * Sets a single key in Crowdflowers job with a given value * @param job//w ww.j a va 2s. c o m * @param key * @param value */ void updateVariable(CrowdJob job, String Url, String key, String value) { MultiValueMap<String, String> argumentMap = new LinkedMultiValueMap<String, String>(); argumentMap.add(key, value); RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new FormHttpMessageConverter()); restTemplate.put(Url, argumentMap, job.getId(), apiKey); }
From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.CrowdClient.java
/** * Orders the job given by its jobid. Pay is per assigment, which is by default 5 units. * * @param job as CrowdJob/* w ww.j av a 2 s .c o m*/ * @param channels : a vector of channels, in which the job should be made available * @param units : number of units to order * @param payPerAssigment : pay in (dollar) cents for each assignments * @return JsonNode that Crowdflower returns */ JsonNode orderJob(CrowdJob job, Vector<String> channels, int units, int payPerAssigment) { Log LOG = LogFactory.getLog(getClass()); RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); restTemplate.getMessageConverters().add(new FormHttpMessageConverter()); MultiValueMap<String, String> argumentMap = new LinkedMultiValueMap<String, String>(); argumentMap.add(debitKey, String.valueOf(units)); for (String channel : channels) { argumentMap.add(channelKey + "[]", channel); } updateVariable(job, jobPaymentKey, String.valueOf(payPerAssigment)); LOG.info("Order Job: #" + job.getId() + " with " + units + " judgments for " + payPerAssigment + " cents (dollar) per assigment."); JsonNode result = restTemplate.postForObject(orderJobURL, argumentMap, JsonNode.class, job.getId(), apiKey); return result; }
From source file:org.starfishrespect.myconsumption.android.ui.AddSensorActivity.java
private boolean create() { DatabaseHelper db = new DatabaseHelper(this); String user = null;//from ww w . j a va 2 s. c om KeyValueData userJson = db.getValueForKey("user"); ObjectMapper mapper = new ObjectMapper(); if (userJson != null) { try { user = mapper.readValue(userJson.getValue(), UserData.class).getName(); } catch (IOException e) { return false; } } if (user == null) { return false; } RestTemplate template = new RestTemplate(); HttpHeaders httpHeaders = CryptoUtils.createHeadersCurrentUser(); ResponseEntity<String> responseEnt; template.getMessageConverters().add(new FormHttpMessageConverter()); template.getMessageConverters().add(new StringHttpMessageConverter()); try { UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(SingleInstance.getServerUrl() + "sensors/") .queryParam("name", editTextSensorName.getText().toString()) .queryParam("type", selectedSensorType).queryParam("user", user) .queryParam("settings", mapper.writeValueAsString(sensorView.getSensorSettings())); responseEnt = template.exchange(builder.build().encode().toUri(), HttpMethod.POST, new HttpEntity<>(httpHeaders), String.class); String result = responseEnt.getBody(); Log.d(TAG, result); SimpleResponseDTO response = mapper.readValue(result, SimpleResponseDTO.class); if (response.getStatus() == 0) { return true; } } catch (HttpClientErrorException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return false; }
From source file:org.starfishrespect.myconsumption.android.ui.AddSensorActivity.java
private boolean edit() { ObjectMapper mapper = new ObjectMapper(); RestTemplate template = new RestTemplate(); HttpHeaders httpHeaders = CryptoUtils.createHeadersCurrentUser(); ResponseEntity<String> responseEnt; template.getMessageConverters().add(new FormHttpMessageConverter()); template.getMessageConverters().add(new StringHttpMessageConverter()); try {/* ww w . jav a 2s . com*/ UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(SingleInstance.getServerUrl() + "sensors/" + editSensor.getSensorId()) .queryParam("name", editTextSensorName.getText().toString()) .queryParam("type", selectedSensorType) .queryParam("settings", mapper.writeValueAsString(sensorView.getSensorSettings())); responseEnt = template.exchange(builder.build().encode().toUri(), HttpMethod.POST, new HttpEntity<>(httpHeaders), String.class); String result = responseEnt.getBody(); Log.d(TAG, result); SimpleResponseDTO response = mapper.readValue(result, SimpleResponseDTO.class); if (response.getStatus() == 0) { return true; } } catch (HttpClientErrorException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } return false; }
From source file:org.encuestame.oauth1.support.OAuth1Support.java
/** * Constructs an OAuth1Template./*from ww w . java2 s. com*/ * @param oauth10a if true this template operates against an OAuth 1.0a provider. If false, it works in OAuth 1.0 mode. */ public OAuth1Support(String consumerKey, String consumerSecret, String requestTokenUrl, String authorizeUrl, String accessTokenUrl, boolean oauth10a) { super(Arrays.<HttpMessageConverter<?>>asList(new StringHttpMessageConverter(), new FormHttpMessageConverter())); this.consumerKey = consumerKey; this.consumerSecret = consumerSecret; this.requestTokenUrl = requestTokenUrl; this.oauth10a = oauth10a; this.authorizeUrlTemplate = new UriTemplate(authorizeUrl); this.accessTokenUrl = accessTokenUrl; }
From source file:org.encuestame.oauth2.support.OAuth2Support.java
/** * OAuth2 Constructor./*from w w w.j a v a 2 s .c om*/ * @param clientId * @param clientSecret * @param authorizeUrl * @param accessTokenUrl */ public OAuth2Support(String clientId, String clientSecret, String authorizeUrl, String accessTokenUrl) { super(Arrays.<HttpMessageConverter<?>>asList(new FormHttpMessageConverter() { public boolean canRead(Class<?> clazz, MediaType mediaType) { return clazz.equals(Map.class) && mediaType != null && mediaType.getType().equals("text") && mediaType.getSubtype().equals("plain"); } }, new MappingJackson2HttpMessageConverter())); this.clientId = clientId; this.clientSecret = clientSecret; this.authorizeUrlTemplate = new UriTemplate(authorizeUrl); this.accessTokenUrl = accessTokenUrl; }