List of usage examples for org.apache.http.protocol HTTP UTF_8
String UTF_8
To view the source code for org.apache.http.protocol HTTP UTF_8.
Click Source Link
From source file:de.escidoc.core.test.aa.UserAttributeTestBase.java
/** * Test retrieving user attributes with given name. * * @param userId The id of the UserAccount. * @param name The name of the UserAttribute. * @return The xml representation of the user attributes. * @throws Exception If anything fails.//w w w. jav a2 s . co m */ protected String retrieveNamedAttributes(final String userId, final String name) throws Exception { Object result = client.retrieveNamedAttributes(userId, name); String xmlResult = null; if (result instanceof HttpResponse) { HttpResponse method = (HttpResponse) result; xmlResult = EntityUtils.toString(method.getEntity(), HTTP.UTF_8); assertHttpStatusOfMethod("", method); } else if (result instanceof String) { xmlResult = (String) result; } return xmlResult; }
From source file:de.escidoc.core.test.sm.ReportDefinitionTestBase.java
/** * Test retrieving an reportDefinition from the mock framework. * * @param id The id of the reportDefinition. * @return The retrieved reportDefinition. * @throws Exception If anything fails./*from www .jav a 2s .co m*/ */ @Override public String retrieve(final String id) throws Exception { Object result = getReportDefinitionClient().retrieve(id); String xmlResult = null; if (result instanceof HttpResponse) { HttpResponse httpRes = (HttpResponse) result; assertHttpStatusOfMethod("", httpRes); xmlResult = EntityUtils.toString(httpRes.getEntity(), HTTP.UTF_8); } else if (result instanceof String) { xmlResult = (String) result; } return xmlResult; }
From source file:com.lostad.app.base.util.RequestUtil.java
public static String postForm(String url, List<NameValuePair> params, boolean isSingleton) throws Exception { String json = null;/* w w w. j ava 2 s . c om*/ HttpClient client = HttpClientManager.getHttpClient(isSingleton); HttpEntity resEntity = null; HttpPost post = new HttpPost(url); try { if (params != null) { UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8); post.setEntity(entity); } HttpResponse response = client.execute(post, new BasicHttpContext()); resEntity = response.getEntity(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {// 200 // ? json = EntityUtils.toString(resEntity); } } catch (Exception e) { if (post != null) { post.abort();// } throw e; } finally { if (resEntity != null) { try { resEntity.consumeContent();//? } catch (IOException e) { e.printStackTrace(); } } client.getConnectionManager().closeExpiredConnections(); ///client.getConnectionManager().shutdown(); } return json; }
From source file:jp.xii.relog.customlibrary.DoSuCommand.java
/** * su???/*from w w w.j ava2 s. c o m*/ * ??????????? * ???????????????? * ?????? * ??????? * split???????? * @param timeout * @return */ public String read() {//int timeout){ String ret = ""; if (_inputStream == null) { } else { int size = 0; byte[] buffer = new byte[1024]; // long start_time = System.currentTimeMillis(); try { do { size = _inputStream.read(buffer); if (size > 0) { ret += new String(buffer, 0, size, HTTP.UTF_8); } } while (_inputStream.available() > 0); // do{ // while(_inputStream.available() > 0){ // size = _inputStream.read(buffer); // if(size > 0){ // ret += new String(buffer, 0, size, HTTP.UTF_8); // } // } // // //????????? // if(ret.length() > 0){ // break; // }else{ // try { // Thread.sleep(10); // } catch (InterruptedException e) { // } // } // // //???????? // }while((System.currentTimeMillis() - start_time) < timeout); } catch (IOException e) { } } return ret; }
From source file:com.wso2telco.gsma.shorten.BitlyUrlShorten.java
/** * Gets the new http client.//from w ww .java 2 s .c o m * * @return the new http client */ @SuppressWarnings("deprecation") public CloseableHttpClient getNewHttpClient() { try { KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); org.apache.http.conn.ssl.SSLSocketFactory sf = new SSLSocket(trustStore); sf.setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:com.wbtech.ums.NetworkUtil.java
public static MyMessage Post(String url, String data) { CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "URL = " + url); CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "LENGTH:" + data.length() + " *Data = " + data + "*"); if (!hasInitSSL && UmsConstants.SDK_SECURITY_LEVEL.equals("2")) { initSSL();//from w ww .ja v a 2 s.c o m hasInitSSL = true; } BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT); DefaultHttpClient httpclient = null; /*SDK??: * 1,CPOS:???sslSDK_SSL=true;??dn(?dnSDK_HTTPS_DNnone) * 2,HTTPS???????https? * 3,http */ if (UmsConstants.SDK_SECURITY_LEVEL.equals("2")) { httpclient = new DefaultHttpClient(httpParams); // cpos with dn check if (!UmsConstants.SDK_HTTPS_DN.equals("none")) { SSLSocketFactory mysf = null; try { mysf = new CposSSLSocketFactory(); if (serverUrl == null) { serverUrl = new URL(url); serverPort = ((serverUrl.getPort() == -1) ? serverUrl.getDefaultPort() : serverUrl.getPort()); } httpclient.getConnectionManager().getSchemeRegistry() .register(new Scheme(serverUrl.getProtocol(), mysf, serverPort)); } catch (Exception e) { CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, e.toString()); } } } else if (UmsConstants.SDK_SECURITY_LEVEL.equals("1") && url.toLowerCase().startsWith("https")) { // for https with company cert if (serverPort < 0) { serverPort = getPort(); } CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "InitSSL port is:" + serverPort); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("https", SSLCustomSocketFactory.getSocketFactory(), serverPort)); ClientConnectionManager connMgr = new ThreadSafeClientConnManager(httpParams, schReg); httpclient = new DefaultHttpClient(connMgr, httpParams); } else { httpclient = new DefaultHttpClient(httpParams); } processCookieRejected(httpclient); MyMessage message = new MyMessage(); try { HttpPost httppost = new HttpPost(url); StringEntity se = new StringEntity("content=" + URLEncoder.encode(data), HTTP.UTF_8); se.setContentType("application/x-www-form-urlencoded"); httppost.setEntity(se); HttpResponse response = httpclient.execute(httppost); CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "Status code=" + response.getStatusLine().getStatusCode()); String returnXML = EntityUtils.toString(response.getEntity()); int status = response.getStatusLine().getStatusCode(); String returnContent = URLDecoder.decode(returnXML, "UTF-8"); CobubLog.d(UmsConstants.LOG_TAG, NetworkUtil.class, "returnString = " + returnContent); //TODO:???200okjson??????????flag<0 //?flag??? switch (status) { case 200: message.setSuccess(isJson(returnContent)); message.setMsg(returnContent); break; default: Log.e("error", status + returnContent); message.setSuccess(false); message.setMsg(returnContent); break; } } catch (Exception e) { message.setSuccess(false); message.setMsg(e.toString()); } return message; }
From source file:com.halseyburgund.rwframework.core.RWHttpManager.java
public static String doPost(String page, Properties props, int timeOutSec) throws Exception { HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, timeOutSec * 1000); HttpConnectionParams.setSoTimeout(httpParams, timeOutSec * 1000); HttpClient httpClient = new DefaultHttpClient(httpParams); HttpPost request = new HttpPost(page); HttpResponse response = null;/*w w w . j av a2s . c o m*/ HttpEntity entity = null; StringBuffer sbResponse = new StringBuffer(); Enumeration<Object> enumProps = props.keys(); String key, value = null; List<NameValuePair> nvps = new ArrayList<NameValuePair>(); while (enumProps.hasMoreElements()) { key = (String) enumProps.nextElement(); value = (String) props.get(key); nvps.add(new BasicNameValuePair(key, value)); } UrlEncodedFormEntity uf = new UrlEncodedFormEntity(nvps, HTTP.UTF_8); request.setEntity(uf); request.setHeader("Content-Type", POST_MIME_TYPE); // Post, check and show the result (not really spectacular, but works): response = httpClient.execute(request); entity = response.getEntity(); int status = response.getStatusLine().getStatusCode(); // we assume that the response body contains the error message if (status != HttpStatus.SC_OK) { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); entity.writeTo(ostream); Log.e(TAG, "Error status code = " + status, null); Log.e(TAG, ostream.toString(), null); throw new HttpException(String.valueOf(status)); } else { InputStream content = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { sbResponse.append(line); } content.close(); // this will also close the connection return sbResponse.toString(); } }
From source file:de.escidoc.core.test.aa.UserPreferenceTestBase.java
/** * Test updating single user preference. * * @param id The id of the UserAccount. * @return The xml representation of the updated preference. * @throws Exception If anything fails.//from w w w . j ava2 s . c om */ protected String updatePreference(final String id, final String name, final String xml) throws Exception { Object result = client.updatePreference(id, name, xml); String xmlResult = null; if (result instanceof HttpResponse) { HttpResponse method = (HttpResponse) result; xmlResult = EntityUtils.toString(method.getEntity(), HTTP.UTF_8); assertHttpStatusOfMethod("", method); } else if (result instanceof String) { xmlResult = (String) result; } return xmlResult; }
From source file:ar.dgarcia.http.simple.impl.ApacheResponseProvider.java
/** * Traduce el request en formato simple a un request de apache * //from ww w .j av a 2 s.co m * @param request * El request simple * @return La versin completa para poder procesarlo */ private HttpUriRequest translateRequestFor(final StringRequest request) { HttpUriRequest apacheRequest; if (request.isPostRequest()) { final HttpPost httpPost = new HttpPost(request.getCompleteGetUrl()); final List<? extends NameValuePair> postParameters = createPostParametersFrom( request.getPostParameters()); try { httpPost.setEntity(new UrlEncodedFormEntity(postParameters, HTTP.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new ConnectionProblemException("Fall seteo de encoding del request POST", e); } apacheRequest = httpPost; } else { apacheRequest = new HttpGet(request.getCompleteGetUrl()); } return apacheRequest; }