List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:com.nextbook.config.ConfigurableStringHttpMessageConverter.java
@Override protected Long getContentLength(String s, MediaType contentType) { Charset charset = getContentTypeCharset(contentType); try {/* www . ja v a2 s. com*/ return (long) s.getBytes(charset.name()).length; } catch (UnsupportedEncodingException ex) { // should not occur throw new InternalError(ex.getMessage()); } }
From source file:com.halzhang.android.apps.startupnews.snkit.SNApi.java
/** * //from www .j a va 2 s . c o m * * @param fnid * @param text * @param responseHandler */ public void comment(Context context, String fnid, String text, AsyncHttpResponseHandler responseHandler) { ArrayList<NameValuePair> valuePairs = new ArrayList<NameValuePair>(2); valuePairs.add(new BasicNameValuePair("fnid", fnid)); valuePairs.add(new BasicNameValuePair("text", text)); try { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(valuePairs, HTTP.UTF_8); mAsyncHttpClient.post(context, context.getString(R.string.host, "/r"), entity, "application/x-www-form-urlencoded", responseHandler); } catch (UnsupportedEncodingException e) { CDLog.e(LOG_TAG, e.getMessage()); } }
From source file:org.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java
public static Map<String, Object> paymentAuthentication(DispatchContext ctx, Map<String, Object> context) { Debug.logInfo("SagePay - Entered paymentAuthentication", module); Debug.logInfo("SagePay paymentAuthentication context : " + context, module); Delegator delegator = ctx.getDelegator(); Map<String, Object> resultMap = new HashMap<String, Object>(); Map<String, String> props = buildSagePayProperties(context, delegator); String vendorTxCode = (String) context.get("vendorTxCode"); String cardHolder = (String) context.get("cardHolder"); String cardNumber = (String) context.get("cardNumber"); String expiryDate = (String) context.get("expiryDate"); String cardType = (String) context.get("cardType"); String cv2 = (String) context.get("cv2"); String amount = (String) context.get("amount"); String currency = (String) context.get("currency"); String description = (String) context.get("description"); String billingSurname = (String) context.get("billingSurname"); String billingFirstnames = (String) context.get("billingFirstnames"); String billingAddress = (String) context.get("billingAddress"); String billingAddress2 = (String) context.get("billingAddress2"); String billingCity = (String) context.get("billingCity"); String billingPostCode = (String) context.get("billingPostCode"); String billingCountry = (String) context.get("billingCountry"); String billingState = (String) context.get("billingState"); String billingPhone = (String) context.get("billingPhone"); Boolean isBillingSameAsDelivery = (Boolean) context.get("isBillingSameAsDelivery"); String deliverySurname = (String) context.get("deliverySurname"); String deliveryFirstnames = (String) context.get("deliveryFirstnames"); String deliveryAddress = (String) context.get("deliveryAddress"); String deliveryAddress2 = (String) context.get("deliveryAddress2"); String deliveryCity = (String) context.get("deliveryCity"); String deliveryPostCode = (String) context.get("deliveryPostCode"); String deliveryCountry = (String) context.get("deliveryCountry"); String deliveryState = (String) context.get("deliveryState"); String deliveryPhone = (String) context.get("deliveryPhone"); String startDate = (String) context.get("startDate"); String issueNumber = (String) context.get("issueNumber"); String basket = (String) context.get("basket"); String clientIPAddress = (String) context.get("clientIPAddress"); HttpClient httpClient = SagePayUtil.getHttpClient(); HttpHost host = SagePayUtil.getHost(props); //start - authentication parameters Map<String, String> parameters = new HashMap<String, String>(); String vpsProtocol = props.get("protocolVersion"); String vendor = props.get("vendor"); String txType = props.get("authenticationTransType"); //start - required parameters parameters.put("VPSProtocol", vpsProtocol); parameters.put("TxType", txType); parameters.put("Vendor", vendor); if (vendorTxCode != null) { parameters.put("VendorTxCode", vendorTxCode); }/*from w w w . j a v a 2 s. c om*/ if (amount != null) { parameters.put("Amount", amount); } if (currency != null) { parameters.put("Currency", currency); } //GBP/USD if (description != null) { parameters.put("Description", description); } if (cardHolder != null) { parameters.put("CardHolder", cardHolder); } if (cardNumber != null) { parameters.put("CardNumber", cardNumber); } if (expiryDate != null) { parameters.put("ExpiryDate", expiryDate); } if (cardType != null) { parameters.put("CardType", cardType); } //start - billing details if (billingSurname != null) { parameters.put("BillingSurname", billingSurname); } if (billingFirstnames != null) { parameters.put("BillingFirstnames", billingFirstnames); } if (billingAddress != null) { parameters.put("BillingAddress", billingAddress); } if (billingAddress2 != null) { parameters.put("BillingAddress2", billingAddress2); } if (billingCity != null) { parameters.put("BillingCity", billingCity); } if (billingPostCode != null) { parameters.put("BillingPostCode", billingPostCode); } if (billingCountry != null) { parameters.put("BillingCountry", billingCountry); } if (billingState != null) { parameters.put("BillingState", billingState); } if (billingPhone != null) { parameters.put("BillingPhone", billingPhone); } //end - billing details //start - delivery details if (isBillingSameAsDelivery != null && isBillingSameAsDelivery) { if (billingSurname != null) { parameters.put("DeliverySurname", billingSurname); } if (billingFirstnames != null) { parameters.put("DeliveryFirstnames", billingFirstnames); } if (billingAddress != null) { parameters.put("DeliveryAddress", billingAddress); } if (billingAddress2 != null) { parameters.put("DeliveryAddress2", billingAddress2); } if (billingCity != null) { parameters.put("DeliveryCity", billingCity); } if (billingPostCode != null) { parameters.put("DeliveryPostCode", billingPostCode); } if (billingCountry != null) { parameters.put("DeliveryCountry", billingCountry); } if (billingState != null) { parameters.put("DeliveryState", billingState); } if (billingPhone != null) { parameters.put("DeliveryPhone", billingPhone); } } else { if (deliverySurname != null) { parameters.put("DeliverySurname", deliverySurname); } if (deliveryFirstnames != null) { parameters.put("DeliveryFirstnames", deliveryFirstnames); } if (deliveryAddress != null) { parameters.put("DeliveryAddress", deliveryAddress); } if (deliveryAddress2 != null) { parameters.put("DeliveryAddress2", deliveryAddress2); } if (deliveryCity != null) { parameters.put("DeliveryCity", deliveryCity); } if (deliveryPostCode != null) { parameters.put("DeliveryPostCode", deliveryPostCode); } if (deliveryCountry != null) { parameters.put("DeliveryCountry", deliveryCountry); } if (deliveryState != null) { parameters.put("DeliveryState", deliveryState); } if (deliveryPhone != null) { parameters.put("DeliveryPhone", deliveryPhone); } } //end - delivery details //end - required parameters //start - optional parameters if (cv2 != null) { parameters.put("CV2", cv2); } if (startDate != null) { parameters.put("StartDate", startDate); } if (issueNumber != null) { parameters.put("IssueNumber", issueNumber); } if (basket != null) { parameters.put("Basket", basket); } if (clientIPAddress != null) { parameters.put("ClientIPAddress", clientIPAddress); } //end - optional parameters //end - authentication parameters try { String successMessage = null; HttpPost httpPost = SagePayUtil.getHttpPost(props.get("authenticationUrl"), parameters); HttpResponse response = httpClient.execute(host, httpPost); Map<String, String> responseData = SagePayUtil.getResponseData(response); String status = responseData.get("Status"); String statusDetail = responseData.get("StatusDetail"); resultMap.put("status", status); resultMap.put("statusDetail", statusDetail); //returning the below details back to the calling code, as it not returned back by the payment gateway resultMap.put("vendorTxCode", vendorTxCode); resultMap.put("amount", amount); resultMap.put("transactionType", txType); //start - transaction authorized if ("OK".equals(status)) { resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("txAuthNo", responseData.get("TxAuthNo")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); successMessage = "Payment authorized"; } //end - transaction authorized if ("NOTAUTHED".equals(status)) { resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); successMessage = "Payment not authorized"; } if ("MALFORMED".equals(status)) { //request not formed properly or parameters missing resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); } if ("INVALID".equals(status)) { //invalid information in request resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); } if ("REJECTED".equals(status)) { //invalid information in request resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); } resultMap.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); resultMap.put(ModelService.SUCCESS_MESSAGE, successMessage); } catch (UnsupportedEncodingException uee) { //exception in encoding parameters in httpPost String errorMsg = "Error occured in encoding parameters for HttpPost (" + uee.getMessage() + ")"; Debug.logError(uee, errorMsg, module); resultMap = ServiceUtil.returnError(errorMsg); } catch (ClientProtocolException cpe) { //from httpClient execute String errorMsg = "Error occured in HttpClient execute(" + cpe.getMessage() + ")"; Debug.logError(cpe, errorMsg, module); resultMap = ServiceUtil.returnError(errorMsg); } catch (IOException ioe) { //from httpClient execute or getResponsedata String errorMsg = "Error occured in HttpClient execute or getting response (" + ioe.getMessage() + ")"; Debug.logError(ioe, errorMsg, module); resultMap = ServiceUtil.returnError(errorMsg); } finally { httpClient.getConnectionManager().shutdown(); } return resultMap; }
From source file:org.ez.flickr.api.CommandArguments.java
public MultipartEntity getBody(Map<String, String> additionalParameters) { try {// w ww . j av a2s.c om MultipartEntity entity = new MultipartEntity(); for (Parameter param : params) { if (!param.internal) { if (param.value instanceof File) { entity.addPart(param.key, new FileBody((File) param.value)); } else if (param.value instanceof String) { entity.addPart(param.key, new StringBody((String) param.value, UTF8)); } } } for (Map.Entry<String, String> entry : additionalParameters.entrySet()) { entity.addPart(entry.getKey(), new StringBody(entry.getValue(), UTF8)); } return entity; } catch (UnsupportedEncodingException ex) { throw new UnsupportedOperationException(ex.getMessage(), ex); } }
From source file:org.fcrepo.client.PostBuilder.java
/** * Provide a content disposition header which will be used as the filename * //from w ww.j a v a 2 s . c o m * @param filename the name of the file being provided in the body of the request * @return this builder * @throws FcrepoOperationFailedException if unable to encode filename */ public PostBuilder filename(final String filename) throws FcrepoOperationFailedException { if (filename != null) { try { final String encodedFilename = URLEncoder.encode(filename, "utf-8"); final String disposition = "attachment; filename=\"" + encodedFilename + "\""; request.addHeader(CONTENT_DISPOSITION, disposition); } catch (UnsupportedEncodingException e) { throw new FcrepoOperationFailedException(request.getURI(), -1, e.getMessage()); } } return this; }
From source file:com.rsmart.rfabric.jasperreports.auth.Signature.java
/** * Calculate an RFC2104 compliant HMAC (Hash-based Message Authentication * Code)/*from w ww . java 2s .c o m*/ * * @param data * The data to be signed. This data is pushed through a hex * converter in this method, so there is no need to do this * before generating the HMAC. * @param key * The signing key. * @param urlSafe * true if the token needs to be URL safe. * @return The Base64-encoded RFC 2104-compliant HMAC signature. * @throws InvalidKeyException * This is the exception for invalid Keys (invalid encoding, * wrong length, uninitialized, etc). */ @SuppressWarnings("PMD.DataflowAnomalyAnalysis") public String calculateRFC2104HMACWithEncoding(final String data, final String key, final boolean urlSafe) throws InvalidKeyException { if (data == null) { throw new IllegalArgumentException("String data == null"); } if (key == null) { throw new IllegalArgumentException("String key == null"); } String result = null; try { // Get an hmac_sha1 key from the raw key bytes final byte[] keyBytes = key.getBytes("UTF-8"); final SecretKeySpec signingKey = new SecretKeySpec(keyBytes, hmacSha1Algorithm); // initialize with the signing key mac.init(signingKey); // Compute the hmac on input data bytes final byte[] rawHmac = mac.doFinal(data.getBytes()); // Convert raw bytes to Hex byte[] hexBytes = new Hex().encode(rawHmac); // Convert raw bytes to encoding final byte[] base64Bytes = Base64.encodeBase64(hexBytes, false, urlSafe); result = new String(base64Bytes, "UTF-8"); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage(), e); } return result; }
From source file:org.guanxi.sp.engine.service.saml2.DiscoveryProfileService.java
/** @see org.guanxi.sp.engine.service.generic.ProfileService#doProfile(javax.servlet.http.HttpServletRequest, String, String, org.guanxi.xal.saml2.metadata.GuardRoleDescriptorExtensions, String, org.guanxi.common.entity.EntityFarm) */ public ModelAndView doProfile(HttpServletRequest request, String guardID, String guardSessionID, GuardRoleDescriptorExtensions guardNativeMetadata, String entityID, EntityFarm farm) throws GuanxiException { ModelAndView mAndV = new ModelAndView(); mAndV.setViewName(viewName);//from w w w . j ava2 s .co m try { String edsURL = edsBaseURL + "?entityID=" + URLEncoder.encode(guardID, "UTF-8"); edsURL += "&return=" + URLEncoder.encode(request.getRequestURL() + "?" + Guanxi.WAYF_PARAM_GUARD_ID + "=" + guardID + "&" + Guanxi.WAYF_PARAM_SESSION_ID + "=" + guardSessionID, "UTF-8"); edsURL += "&returnIDParam=" + URLEncoder.encode("edsEntityID", "UTF-8"); mAndV.getModel().put("edsURL", edsURL); } catch (UnsupportedEncodingException use) { logger.error("Could not encode EDS URL", use); mAndV.getModel().put("edsError", use.getMessage()); } return mAndV; }
From source file:ch.sbb.releasetrain.utils.http.HttpUtilImpl.java
/** * set user and password for basic authentication *///from ww w . j a v a 2 s.c o m public String postContentToUrl(String url, String content) { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost post = new HttpPost(url); post.setHeader("Content-Type", "application/xml"); HttpEntity entity = null; HttpClientContext context = initAuthIfNeeded(url); try { entity = new StringEntity(content); } catch (UnsupportedEncodingException e) { log.error(e.getMessage(), e); } post.setEntity(entity); HttpResponse response; try { response = httpclient.execute(post, context); if (response.getStatusLine().getStatusCode() != 200) { log.error("response code not ok: " + response.getStatusLine().getStatusCode()); } entity = response.getEntity(); return EntityUtils.toString(entity); } catch (IOException e) { log.error(e.getMessage(), e); } return ""; }
From source file:com.aliyun.android.oss.task.PostObjectGroupTask.java
/** * HttpPut/*from www. j av a2 s.c om*/ */ protected HttpUriRequest generateHttpRequest() { // ?Http String requestUri = this.getOSSEndPoint() + httpTool.generateCanonicalizedResource("/" + objectGroup.getName()); ; HttpPut httpPut = new HttpPut(requestUri); // HttpPut String resource = httpTool .generateCanonicalizedResource("/" + objectGroup.getBucketName() + "/" + objectGroup.getName()); String authorization = OSSHttpTool.generateAuthorization(accessId, accessKey, httpMethod.toString(), "", objectGroupMetaData.getContentType(), Helper.getGMTDate(), OSSHttpTool.generateCanonicalizedHeader(objectGroupMetaData.getAttrs()), resource); httpPut.setHeader(AUTHORIZATION, authorization); httpPut.setHeader(DATE, Helper.getGMTDate()); httpPut.setHeader(HOST, OSS_HOST); try { httpPut.setEntity(new StringEntity(generateHttpEntity())); } catch (UnsupportedEncodingException e) { Log.e(this.getClass().getName(), e.getMessage()); } return httpPut; }
From source file:com.servioticy.restclient.RestClient.java
public FutureRestResponse restRequest(String url, String body, int method, Map<String, String> headers) throws RestClientException, RestClientErrorCodeException { HttpRequestBase httpMethod;//from w ww .j a v a 2 s . c o m StringEntity input; switch (method) { case POST: try { input = new StringEntity(body); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); throw new RestClientException(e.getMessage()); } input.setContentType("application/json"); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(input); httpMethod = httpPost; break; case PUT: try { input = new StringEntity(body); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); throw new RestClientException(e.getMessage()); } input.setContentType("application/json"); HttpPut httpPut = new HttpPut(url); httpPut.setEntity(input); httpMethod = httpPut; break; case DELETE: httpMethod = new HttpDelete(url); break; case GET: httpMethod = new HttpGet(url); break; default: return null; } if (headers != null) { for (Map.Entry<String, String> header : headers.entrySet()) { httpMethod.addHeader(header.getKey(), header.getValue()); } } Future<HttpResponse> response; try { response = httpClient.execute(httpMethod, null); } catch (Exception e) { logger.error(e.getMessage()); throw new RestClientException(e.getMessage()); } // TODO Check the errors nicely FutureRestResponse rr = new FutureRestResponse(response); return rr; }