List of usage examples for java.io UnsupportedEncodingException getMessage
public String getMessage()
From source file:org.deviceconnect.android.manager.test.MultipartTest.java
/** * POST????????.//from ww w . j a v a 2 s. c om */ public void testParsingMutilpartAsRequestParametersMethodPost() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(NotificationProfileConstants.PROFILE_NAME); builder.setAttribute(NotificationProfileConstants.ATTRIBUTE_NOTIFY); try { MultipartEntity entity = new MultipartEntity(); entity.addPart(DConnectProfileConstants.PARAM_DEVICE_ID, new StringBody(getDeviceId())); entity.addPart(NotificationProfileConstants.PARAM_TYPE, new StringBody("0")); entity.addPart(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, new StringBody(getAccessToken())); HttpPost request = new HttpPost(builder.toString()); request.setEntity(entity); JSONObject response = sendRequest(request); assertResultOK(response); } catch (UnsupportedEncodingException e) { fail(e.getMessage()); } catch (JSONException e) { fail(e.getMessage()); } }
From source file:org.deviceconnect.android.manager.test.MultipartTest.java
/** * PUT????????./*w w w . j a va2s . co m*/ */ public void testParsingMutilpartAsRequestParametersMethodPut() { URIBuilder builder = TestURIBuilder.createURIBuilder(); builder.setProfile(DeviceOrientationProfileConstants.PROFILE_NAME); builder.setAttribute(DeviceOrientationProfileConstants.ATTRIBUTE_ON_DEVICE_ORIENTATION); try { MultipartEntity entity = new MultipartEntity(); entity.addPart(DConnectProfileConstants.PARAM_DEVICE_ID, new StringBody(getDeviceId())); entity.addPart(DConnectProfileConstants.PARAM_SESSION_KEY, new StringBody(getClientId())); entity.addPart(AuthorizationProfileConstants.PARAM_ACCESS_TOKEN, new StringBody(getAccessToken())); HttpPut request = new HttpPut(builder.toString()); request.setEntity(entity); JSONObject response = sendRequest(request); assertResultOK(response); } catch (UnsupportedEncodingException e) { fail(e.getMessage()); } catch (JSONException e) { fail(e.getMessage()); } }
From source file:at.sti2.spark.handler.RestHandler.java
@Override public void invoke(Match match) throws SparkwaveHandlerException { String url = handlerProperties.getValue("url"); logger.info("Invoking impactorium at URL " + url); final List<TripleCondition> conditions = handlerProperties.getTriplePatternGraph().getConstruct() .getConditions();//ww w . j a v a 2s. c o m final String ntriplesOutput = match.outputNTriples(conditions); //HTTP PUT the info-object id HttpClient httpclient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); try { StringEntity infoObjectEntityRequest = new StringEntity(ntriplesOutput); httpPost.setEntity(infoObjectEntityRequest); HttpResponse response = httpclient.execute(httpPost); logger.info("[CREATING REPORT] Status code " + response.getStatusLine()); //First invocation succeeded if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity infoObjectEntityResponse = response.getEntity(); //Something has been returned, let's see what is in it if (infoObjectEntityResponse != null) { String infoObjectResponse = EntityUtils.toString(infoObjectEntityResponse); logger.debug("InfoObject response " + infoObjectResponse); } } } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); } catch (ClientProtocolException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:com.aware.utils.Http.java
/** * Make a POST to the URL, with the ArrayList<NameValuePair> data * @param url/* ww w. j a v a 2s . com*/ * @param data * @return HttpEntity with server response. Use EntityUtils to extract values or object */ public HttpResponse dataPOST(String url, ArrayList<NameValuePair> data) { try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(data)); HttpResponse httpResponse = httpClient.execute(httpPost); int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != 200) { if (Aware.DEBUG) { Log.d(TAG, "Status: " + statusCode); Log.e(TAG, "URL:" + url); Log.e(TAG, EntityUtils.toString(httpResponse.getEntity())); } } return httpResponse; } catch (UnsupportedEncodingException e) { Log.e(TAG, e.getMessage()); return null; } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage()); return null; } catch (IOException e) { Log.e(TAG, e.getMessage()); return null; } catch (IllegalStateException e) { Log.e(TAG, e.getMessage()); return null; } }
From source file:com.dubsar_dictionary.Dubsar.model.Search.java
/** * Instantiate a search for the specified term * @param term a search term, specified by the user *//*from www .j a v a2 s .c om*/ public Search(String term) { mTerm = new String(term); // DEBT: Take from strings file try { mPath = new String("/?term=") + URLEncoder.encode(mTerm, "UTF-8"); } catch (UnsupportedEncodingException e) { setErrorMessage(e.getMessage()); } }
From source file:com.dubsar_dictionary.Dubsar.model.Search.java
/** * Request a specific page from a large result * @param term the search term/*from w ww . j a va2s. c om*/ * @param page the page to retrieve */ public Search(String term, int page) { mTerm = new String(term); mCurrentPage = page; try { mPath = new String("/?term=") + URLEncoder.encode(mTerm, "UTF-8") + "&page=" + page; } catch (UnsupportedEncodingException e) { setErrorMessage(e.getMessage()); } }
From source file:net.neurowork.cenatic.centraldir.workers.XMLPusher.java
private void pushOrganization(RestUrlManager restUrl, String token) { HttpClient httpclient = XMLRestWorker.getHttpClient(); PostMethod post = new PostMethod(restUrl.getPushOrganizationUrl()); NameValuePair tokenParam = new NameValuePair("token", token); NameValuePair[] params = new NameValuePair[] { tokenParam }; post.addRequestHeader("Accept", "application/xml"); post.setQueryString(params);/*from ww w . j a v a 2 s .c om*/ String content = XmlPushCreator.getInstance().getPushXml(organizacion); try { RequestEntity entity = new StringRequestEntity(content, PostMethod.FORM_URL_ENCODED_CONTENT_TYPE, null); post.setRequestEntity(entity); int result = httpclient.executeMethod(post); logger.info("Response status code: " + result); logger.info("Response body: "); logger.info(post.getResponseBodyAsString()); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); } catch (HttpException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } finally { post.releaseConnection(); } }
From source file:com.dongfang.net.http.client.entity.BodyParamsEntity.java
private void refreshContent() { if (dirty) {//from w ww . ja va2s .c om try { this.content = URLEncodedUtils.format(params, charset).getBytes(charset); } catch (UnsupportedEncodingException e) { ULog.e(e.getMessage(), e); } dirty = false; } }
From source file:fr.cph.stock.android.web.Connect.java
public JSONObject getJSONObject() throws AppException { String data;// ww w. j av a2 s . c o m JSONObject json; try { data = connectUrl(urlBuilder()); json = convertDataToJSONObject(data); } catch (UnsupportedEncodingException e) { throw new AppException(e.getMessage(), e); } catch (IOException e) { throw new AppException(e.getMessage(), e); } catch (JSONException e) { throw new AppException(e.getMessage(), e); } return json; }
From source file:eionet.cr.harvest.PushHarvest.java
@Override protected void doHarvest() throws HarvestException { if (StringUtils.isEmpty(pushedContent)) { throw new HarvestException("Pushed content must not be empty!"); }//from www .j a v a2 s .com InputStream inputStream = null; try { inputStream = new ByteArrayInputStream(pushedContent.getBytes("UTF-8")); int noOfTriples = getHarvestSourceDAO().loadIntoRepository(inputStream, null, getContextUrl(), false); setStoredTriplesCount(noOfTriples); } catch (UnsupportedEncodingException e) { throw new HarvestException(e.getMessage(), e); } catch (IOException e) { throw new HarvestException(e.getMessage(), e); } catch (OpenRDFException e) { throw new HarvestException(e.getMessage(), e); } }