List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:org.kuali.mobility.knowledgebase.service.KnowledgeBaseServiceImpl.java
public KnowledgeBaseSearchResultContainer searchKnowledgeBase(String query, int index, int size) { KnowledgeBaseSearchResultContainer container = null; try {//from ww w .ja v a 2 s . c om // We could probably just return a document for this and use an XSL to transform it in the mobile service implementation. // String url = this.getCacheService().findConfigParamValueByName(PARAM_KB_URL_SEARCH); // String url = "http://remote.kb.iu.edu/REST/v0.2/document/search//"; String url = this.configParamService.findValueByName(PARAM_KB_URL_SEARCH); String content = "query=" + URLEncoder.encode(query, "UTF-8"); if (index > 0) { content = content + "&start=" + index; } if (size > 0) { content = content + "&size=" + size; } RequestEntity requestEntity = new StringRequestEntity(content, null, "UTF-8"); // Document doc = this.callKnowledgeBase(url, requestEntity, true); String searchXml = this.callKnowledgeBase(url, requestEntity, true); SAXBuilder builder = new SAXBuilder(); StringReader reader = new StringReader(searchXml); Document doc = builder.build(reader); container = convertSearchDocument(doc); container.setCount(size); } catch (UnsupportedEncodingException e) { LOG.error(e.getMessage(), e); } catch (JDOMException e) { LOG.error(e.getMessage(), e); } catch (IOException e) { LOG.error(e.getMessage(), e); } catch (Exception e) { LOG.error(e.getMessage(), e); } return container; }
From source file:com.ntsync.android.sync.client.NetworkUtilities.java
public static boolean savePwdSalt(Context context, String accountName, String authtoken, String newSalt, String oldSalt, boolean clearData, String pwdCheck) throws AuthenticationException, ServerException, NetworkErrorException { final HttpPost post = new HttpPost(PWDSALT_URI); List<BasicNameValuePair> values = new ArrayList<BasicNameValuePair>(); values.add(new BasicNameValuePair("newSalt", newSalt == null ? "" : newSalt)); values.add(new BasicNameValuePair("oldSalt", oldSalt == null ? "" : oldSalt)); values.add(new BasicNameValuePair("clearData", String.valueOf(clearData))); values.add(new BasicNameValuePair("pwdCheck", pwdCheck == null ? "" : pwdCheck)); HttpResponse resp = null;/*from w w w .j a va 2s.c om*/ final String respStr; HttpEntity entity = null; try { HttpEntity postEntity = new UrlEncodedFormEntity(values, SyncDataHelper.DEFAULT_CHARSET_NAME); post.setHeader(postEntity.getContentEncoding()); post.setEntity(postEntity); resp = getHttpClient(context).execute(post, createHttpContext(accountName, authtoken)); entity = resp.getEntity(); respStr = EntityUtils.toString(entity); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex); } catch (IOException ex) { throw new NetworkErrorException(ex); } finally { if (entity != null) { try { entity.consumeContent(); } catch (IOException ex) { LogHelper.logD(TAG, "Close Entity failed with: " + ex.getMessage(), ex); } } } boolean saltSaved = true; StatusLine statusLine = resp.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode != HttpStatus.SC_OK) { if (statusCode == HttpStatus.SC_UNAUTHORIZED) { throw new AuthenticationException(statusLine.toString()); } else if (statusCode == HttpStatus.SC_BAD_REQUEST) { saltSaved = false; } else { throw new ServerException("Server error in query savePwdSalt: " + statusLine); } } else { if (respStr != null && !respStr.startsWith("OK")) { Log.w(TAG, "SaltSaved failed with: " + respStr); saltSaved = false; } } return saltSaved; }
From source file:com.shenit.commons.utils.HttpUtils.java
/** * Encode url to specific character set/* w w w.j ava2 s. com*/ * * @param str * @param charset * @return */ public static String encodeUrl(String str, String charset) { if (str == null) return null; charset = charset == null ? ENC_UTF8 : charset; String url = str; try { url = URLEncoder.encode(str, charset); } catch (UnsupportedEncodingException e) { LOG.warn("[encodeUrl]Could not encode url. Error >>> {}", e.getMessage()); } return url; }
From source file:com.securekey.sdk.sample.VerifyQuickCodeActivity.java
/** * Implements AssertUserListener.assertUserComplete * <p>/*w ww . j a va 2 s. c o m*/ * If successful, will forward received JWT data for a final usage for a third party * */ @Override public void assertUserComplete(int status, Vector<SKAudienceJwt> audiences) { if (status == Briidge.STATUS_OK) { // The JWT should be provide to a third party to be verify // It could be parse to see what's inside dismissProgressDialog(); for (SKAudienceJwt skAudienceJwt : audiences) { String[] jwtSegment = getJWSSegments(skAudienceJwt.getJwt()); try { final StringBuilder message = new StringBuilder(); message.append(new String(Base64.decode(jwtSegment[0], Base64.NO_WRAP), "UTF-8") + "\n"); message.append(new String(Base64.decode(jwtSegment[1], Base64.NO_WRAP), "UTF-8") + "\n\n\n"); showDialog(message.toString()); verifyJWT(skAudienceJwt.getJwt()); } catch (UnsupportedEncodingException e) { Log.e(VerifyQuickCodeActivity.class.toString(), e.getMessage()); } } } else if (status == Briidge.STATUS_TRY_LATER_TOO_MANY_INVALID_ATTEMPTS) { showDialog("User suspended!"); } else if (status == Briidge.STATUS_WRONG_CODE) { showDialog("Invalid code!"); } else { dismissProgressDialog(); showDialog("Failed during verification process."); } }
From source file:com.wso2telco.dep.mediator.ResponseHandler.java
/** * Make sms send response.//from w w w . j a v a 2 s .co m * * @param mc * the mc * @param requestBody * the request body * @param responseMap * the response map * @param requestid * the requestid * @return the string */ public String makeSmsSendResponse(MessageContext mc, String requestBody, Map<String, SendSMSResponse> responseMap, String requestid) { log.info("Building Send SMS Response: " + requestBody + " Request ID: " + UID.getRequestID(mc)); Gson gson = new GsonBuilder().create(); SendSMSResponse finalResponse = gson.fromJson(requestBody, SendSMSResponse.class); DeliveryInfoList deliveryInfoListObj = new DeliveryInfoList(); List<DeliveryInfo> deliveryInfoList = new ArrayList<DeliveryInfo>(responseMap.size()); for (Map.Entry<String, SendSMSResponse> entry : responseMap.entrySet()) { SendSMSResponse smsResponse = entry.getValue(); if (smsResponse != null) { DeliveryInfoList resDeliveryInfoList = smsResponse.getOutboundSMSMessageRequest() .getDeliveryInfoList(); DeliveryInfo[] resDeliveryInfos = resDeliveryInfoList.getDeliveryInfo(); Collections.addAll(deliveryInfoList, resDeliveryInfos); } else { DeliveryInfo deliveryInfo = new DeliveryInfo(); deliveryInfo.setAddress(entry.getKey()); deliveryInfo.setDeliveryStatus("DeliveryImpossible"); deliveryInfoList.add(deliveryInfo); } } deliveryInfoListObj.setDeliveryInfo(deliveryInfoList.toArray(new DeliveryInfo[deliveryInfoList.size()])); String senderAddress = finalResponse.getOutboundSMSMessageRequest().getSenderAddress(); try { senderAddress = URLEncoder.encode(senderAddress, "UTF-8"); } catch (UnsupportedEncodingException e) { log.error(e.getMessage(), e); } String resourceURL = getResourceURL(mc, senderAddress) + "/requests/" + requestid; deliveryInfoListObj.setResourceURL(resourceURL + "/deliveryInfos"); finalResponse.getOutboundSMSMessageRequest().setDeliveryInfoList(deliveryInfoListObj); finalResponse.getOutboundSMSMessageRequest().setResourceURL(resourceURL); ((Axis2MessageContext) mc).getAxis2MessageContext().setProperty("HTTP_SC", 201); // Set Location Header Object headers = ((Axis2MessageContext) mc).getAxis2MessageContext() .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null && headers instanceof Map) { Map headersMap = (Map) headers; headersMap.put("Location", resourceURL); } return gson.toJson(finalResponse); }
From source file:cn.isif.util_plus.http.RequestParams.java
/** * Returns an HttpEntity containing all request parameters *//*from w w w. j ava 2 s. c o m*/ public HttpEntity getEntity() { if (bodyEntity != null) { return bodyEntity; } HttpEntity result = null; if (fileParams != null && !fileParams.isEmpty()) { MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.STRICT, null, Charset.forName(charset)); if (bodyParams != null && !bodyParams.isEmpty()) { for (NameValuePair param : bodyParams) { try { multipartEntity.addPart(param.getName(), new StringBody(param.getValue())); } catch (UnsupportedEncodingException e) { LogUtils.e(e.getMessage(), e); } } } for (ConcurrentHashMap.Entry<String, ContentBody> entry : fileParams.entrySet()) { multipartEntity.addPart(entry.getKey(), entry.getValue()); } result = multipartEntity; } else if (bodyParams != null && !bodyParams.isEmpty()) { result = new BodyParamsEntity(bodyParams, charset); } return result; }
From source file:com.securekey.sdk.sample.VerifyQuickCodeActivity.java
/** * Implements VerifyQuickCodeListener.verifyQuickCodeComplete * <p>// ww w.j a va 2 s . co m * If successful, will forward received txnId for final verification by the RP Server * */ @Override public void verifyQuickCodeComplete(int status, String transactionId) { if (status == Briidge.STATUS_OK) { if (this.jwsExpected) { // The JWT should be provide to a third party to be verify // It could be parse to see what's inside dismissProgressDialog(); String[] jwtSegment = getJWSSegments(transactionId); try { final StringBuilder message = new StringBuilder(); message.append(new String(Base64.decode(jwtSegment[0], Base64.NO_WRAP), "UTF-8") + "\n"); message.append(new String(Base64.decode(jwtSegment[1], Base64.NO_WRAP), "UTF-8") + "\n\n\n"); showDialog(message.toString()); verifyJWT(transactionId); } catch (UnsupportedEncodingException e) { Log.e(VerifyQuickCodeActivity.class.toString(), e.getMessage()); } } else { rpQuickCodeVerify(transactionId); } } else if (status == Briidge.STATUS_TRY_LATER_TOO_MANY_INVALID_ATTEMPTS) { showDialog("User suspended!"); } else if (status == Briidge.STATUS_WRONG_CODE) { showDialog("Invalid code!"); } else { dismissProgressDialog(); showDialog("Failed during verification process."); } }
From source file:com.rvl.android.getnzb.GetNZB.java
public void login() { // Login to www.nzbs.org and go to search-activity. // The return values from nzbs.org are stored in the cookiestore for later use. new Thread() { public void run() { if (!LOGGEDIN) { Log.d(Tags.LOG, "- login()"); SharedPreferences pref = getSharedPreferences(Tags.PREFS, 0); Log.d(Tags.LOG,//from www. ja v a 2s . co m "Using login name: '" + pref.getString("nzbsusername", "No value given.") + "'"); HttpPost post = new HttpPost(Tags.NZBS_LOGINPAGE); List<NameValuePair> nvp = new ArrayList<NameValuePair>(2); nvp.add(new BasicNameValuePair("username", pref.getString("nzbsusername", ""))); nvp.add(new BasicNameValuePair("password", pref.getString("nzbspassword", ""))); nvp.add(new BasicNameValuePair("action", "dologin")); try { post.setEntity(new UrlEncodedFormEntity(nvp)); HttpResponse response = httpclient.execute(post); HttpEntity entity = response.getEntity(); if (entity != null) entity.consumeContent(); List<Cookie> cookielist = httpclient.getCookieStore().getCookies(); // If we are logged in we got three cookies. A a php-sessionid, username and a id-hash. if (cookielist.isEmpty()) { Log.d(Tags.LOG, "No cookies, not logged in."); } else { Log.d(Tags.LOG, "Received " + cookielist.size() + " cookies: "); for (int i = 0; i < cookielist.size(); i++) { Log.d(Tags.LOG, "- " + cookielist.get(i).toString()); } LOGGEDIN = true; } } catch (UnsupportedEncodingException e) { Log.d(Tags.LOG, "login(): UnsupportedEncodingException: " + e.getMessage()); } catch (ClientProtocolException e) { Log.d(Tags.LOG, "login(): ClientProtocolException: " + e.getMessage()); } catch (IOException e) { httpclient = new DefaultHttpClient(); Log.d(Tags.LOG, "login(): IO Exception: " + e.getMessage()); Log.d(Tags.LOG, "login(): " + e.toString()); } } pd_handler.sendEmptyMessage(0); } }.start(); }
From source file:org.envirocar.app.application.UploadManager.java
/** * Uploads the json object to the server * /* w w w . j av a 2s .c om*/ * @param url * Url * @param contents * The Json Object * @param xToken * Token * @param xUser * Username * @return Server response status code */ private String sendHttpPost(String url, File contents, String xToken, String xUser) { try { HttpPost httpPostRequest = new HttpPost(url); FileEntity se = new FileEntity(contents, "application/json"); se.setContentType("application/json"); // Set HTTP parameters httpPostRequest.setEntity(se); httpPostRequest.setHeader("Content-type", "application/json"); httpPostRequest.setHeader("X-Token", xToken); httpPostRequest.setHeader("X-User", xUser); HttpResponse response = (HttpResponse) HTTPClient.execute(httpPostRequest); String location = ""; Header[] h = response.getAllHeaders(); for (int i = 0; i < h.length; i++) { if (h[i].getName().equals("Location")) { location += h[i].getValue(); break; } } String trackid = location.substring(location.lastIndexOf("/") + 1, location.length()); int statusCode = response.getStatusLine().getStatusCode(); logger.debug("Status Code: " + statusCode); if (statusCode < HttpStatus.SC_MULTIPLE_CHOICES) { HTTPClient.consumeEntity(response.getEntity()); return trackid; } else { String errorResponse = HTTPClient.readResponse(response.getEntity()); logger.warn("Server response: " + errorResponse); return GENERAL_ERROR; } } catch (UnsupportedEncodingException e) { logger.warn(e.getMessage(), e); return GENERAL_ERROR; } catch (IOException e) { logger.warn(e.getMessage(), e); return NET_ERROR; } }
From source file:com.iia.giveastick.util.RestClient.java
private HttpEntity buildMultipartEntity(JSONObject jsonParams) { MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); try {//from w w w .j a v a 2s.c om String path = jsonParams.getString("file"); if (debugWeb && GiveastickApplication.DEBUG) { Log.d(TAG, "key : file value :" + path); } if (!TextUtils.isEmpty(path)) { // File entry File file = new File(path); FileBody fileBin = new FileBody(file, "application/octet"); entity.addPart("file", fileBin); try { entity.addPart("file", new StringBody(path, "text/plain", Charset.forName(HTTP.UTF_8))); } catch (UnsupportedEncodingException e) { e.printStackTrace(); Log.e(TAG, e.getMessage()); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return entity; }