List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
From source file:org.ubicompforall.cityexplorer.gui.ImportWebTab_oldWebView.java
/*** * @param webview/*from www . java 2s. c om*/ * @return status: loaded or not */ public boolean setupWebDBs() { if (!loaded) { //String responseString; HttpClient httpclient = new DefaultHttpClient(); HttpResponse response; for (String webURL : webFolders) { debug(0, "Getting webFolder " + webURL); try { response = httpclient.execute(new HttpGet(webURL)); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); //responseString = out.toString(); String SERVER_URL = "http://" + (new URL(webURL).getHost()); File[] linkDbTerms = new File[0]; // extractDBs( responseString, SERVER_URL ); if (linkDbTerms.equals("")) { //webview.loadData( responseString, "text/html", "utf-8" ); webview.loadData("Loading page...", "text/html", "utf-8"); webview.loadUrl(webURL); } else { debug(2, "searching host " + SERVER_URL + ", extracted is " + linkDbTerms); //webview.loadData(linkDbTerms, "text/html", "utf-8" ); //webview.loadData(linkDbTerms, "text/html", "utf-8" ); loaded = true; } //webview.loadData( responseString, "text/html", "utf-8" ); } else { //Closes the connection on failure response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); debug(-1, "Network unavailable? " + e.getMessage() + "\n...weburl was " + webURL); } // try downloading db's from the Web, catch and print exceptions } // for all web-locations with DBs on them } // if not already loaded once before return loaded; }
From source file:net.evecom.androidecssp.activity.event.EventAddActivity.java
/** * //from www.ja va2s . c o m * postdata * * @author Mars zhang * @created 2015-11-10 4:13:51 * @param entity */ private void postdata(final HashMap<String, String> entity) { new Thread(new Runnable() { @Override public void run() { Message message = new Message(); try { saveResult = connServerForResultPost("jfs/ecssp/mobile/eventCtr/eventAdd", entity); } catch (ClientProtocolException e) { message.what = MESSAGETYPE_02; Log.e("mars", e.getMessage()); } catch (IOException e) { message.what = MESSAGETYPE_02; Log.e("mars", e.getMessage()); } if (saveResult.length() > 0) { message.what = MESSAGETYPE_01; String eventId = ""; try { BaseModel eventInfo = getObjInfo(saveResult); if (null != eventInfo) { eventId = eventInfo.get("id"); } } catch (JSONException e) { Log.e("mars", e.getMessage()); } HashMap<String, String> map = new HashMap<String, String>(); map.put("eventId", eventId); postImage(map, filebeans, "jfs/ecssp/mobile/eventCtr/eventFileSave"); } else { message.what = MESSAGETYPE_02; } Log.v("mars", saveResult); saveHandler.sendMessage(message); } }).start(); }
From source file:com.chaturs.notepad.NoteEditor.java
public String postData() { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(IpValue.trim() + "/docprocessor/addnote.php"); String title = note.getTitle(); String content = note.getContent(); String selectedGroupIds = note.getSelectedStudyGroupIds(); String user = note.getUserName(); // Toast.makeText(this, "Selected GroupIds " + selectedGroupIds, Toast.LENGTH_SHORT).show(); long study_group_id = note.getStudygroupId(); if (title == null) { title = "sample"; }// w ww. ja v a2 s .c o m if (content == null) { content = "No Content"; } try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("title", title)); nameValuePairs.add(new BasicNameValuePair("content", content)); nameValuePairs.add(new BasicNameValuePair("groups", selectedGroupIds)); nameValuePairs.add(new BasicNameValuePair("user", user)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String response = httpclient.execute(httppost, responseHandler); Log.i("test", "" + response); return response; // Toast.makeText(this, ""+response, Toast.LENGTH_SHORT) ; } catch (ClientProtocolException e) { Log.e("test", "" + e.getMessage()); return e.getMessage(); } catch (IOException e) { Log.e("test", "" + e.getMessage()); return e.getMessage(); } }
From source file:net.evecom.androidecssp.activity.taskresponse.TaskResponseAddActivity.java
/** * //from ww w. j a v a 2s . co m * * * @author Mars zhang * @created 2016-1-27 9:21:54 */ private void postStrForm(final HashMap<String, String> entity) { new Thread(new Runnable() { @Override public void run() { Message message = new Message(); try { saveResult = connServerForResultPost("jfs/ecssp/mobile/taskresponseCtr/taskResponseAdd", entity); } catch (ClientProtocolException e) { message.what = MESSAGETYPE_02; Log.e("mars", e.getMessage()); } catch (IOException e) { message.what = MESSAGETYPE_02; Log.e("mars", e.getMessage()); } if (saveResult.length() > 0) { message.what = MESSAGETYPE_01; /*String responseid = ""; try { TaskResponseInfo taskResponseInfo = getTaskResponseInfo(saveResult); if (null != taskResponseInfo) { responseid = taskResponseInfo.getId(); } } catch (JSONException e) { }*/ } else { message.what = MESSAGETYPE_02; } saveHandler.sendMessage(message); } }).start(); }
From source file:org.talend.mdm.workbench.serverexplorer.console.MDMServerMessageConsole.java
private HttpResponse executeByHttpget(String url, String userName, String password) { HttpGet httpGet = new HttpGet(url); HttpClientUtil.addStudioToken(httpGet, serverDef.getUser()); DefaultHttpClient httpClient = createHttpClient(); HttpResponse response = null;//from w w w.ja v a 2 s.c o m try { response = httpClient.execute(httpGet); } catch (ClientProtocolException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } return response; }
From source file:org.wso2.carbon.apimgt.sciquest.keymanager.APIManagerOAuthClient.java
/** * This method retrieve access token from external OAuth Server * * @param tokenRequest having necessary parameters for token generation in the external OAuth Server * @return an {@code AccessTokenInfo} having newly created access token and it's meta informations * @throws APIManagementException//from www .j av a2 s.c o m */ public AccessTokenInfo getNewApplicationAccessToken(AccessTokenRequest tokenRequest) throws APIManagementException { if (tokenRequest == null) { return null; } if (log.isDebugEnabled()) { log.debug("Calling OAuth Server for generating Access Token"); } KeyManagerConfiguration config = KeyManagerHolder.getKeyManagerInstance().getKeyManagerConfiguration(); String tokenEndpoint = config.getParameter(ClientConstants.TOKEN_URL); HttpPost httpPost = new HttpPost(tokenEndpoint.trim()); HttpClient httpClient = new DefaultHttpClient(); BufferedReader reader = null; try { String jsonPayload = "grant_type=client_credentials"; httpPost.setEntity(new StringEntity(jsonPayload, ClientConstants.UTF_8)); httpPost.setHeader(ClientConstants.CONTENT_TYPE, ClientConstants.URL_ENCODED_CONTENT_TYPE); httpPost.setHeader(ClientConstants.ACCEPT, ClientConstants.APPLICATION_JSON_CONTENT_TYPE); String encodedSecret = Base64.encode( new String(tokenRequest.getClientId() + ":" + tokenRequest.getClientSecret()).getBytes()); httpPost.setHeader(ClientConstants.AUTHORIZATION, ClientConstants.BASIC + encodedSecret); HttpResponse response = httpClient.execute(httpPost); int responseCode = response.getStatusLine().getStatusCode(); if (HttpStatus.SC_OK == responseCode) { HttpEntity entity = response.getEntity(); reader = new BufferedReader(new InputStreamReader(entity.getContent(), ClientConstants.UTF_8)); JSONObject parsedObject = getParsedObjectByReader(reader); return getAccessTokenFromResponse(parsedObject); } else { handleException("Some thing wrong here while retrieving new token HTTP Error response code is " + responseCode); } } catch (ClientProtocolException e) { handleException( "HTTP request error has occurred while sending request to OAuth Provider. " + e.getMessage(), e); } catch (IOException e) { handleException("Error has occurred while reading or closing buffer reader. " + e.getMessage(), e); } catch (ParseException e) { handleException("Error while parsing response json " + e.getMessage(), e); } finally { IOUtils.closeQuietly(reader); } return null; }
From source file:com.stepsdk.android.api.APIClient.java
public HttpEntity httpPost(String url, UrlEncodedFormEntity ent) throws NetworkDownException, HttpPostException { mHttpclient = new DefaultHttpClient(); ClientConnectionManager mgr = mHttpclient.getConnectionManager(); HttpParams params = mHttpclient.getParams(); if (WEB_USER_AGENT != null) params.setParameter(CoreProtocolPNames.USER_AGENT, WEB_USER_AGENT); mHttpclient = new DefaultHttpClient(new ThreadSafeClientConnManager(params, mgr.getSchemeRegistry()), params);//from ww w .j ava2 s .com HttpPost post = new HttpPost(url); if (ent != null) post.setEntity(ent); try { if (!NetworkUtil.isOnline(mContext)) throw new NetworkDownException(); HttpResponse response = mHttpclient.execute(post); return response.getEntity(); } catch (ClientProtocolException e) { throw new HttpPostException(e.getMessage()); } catch (IOException e) { throw new HttpPostException(e.getMessage()); } }
From source file:com.heliumv.api.BaseApi.java
public void respondUnavailable(ClientProtocolException e) { log.info("default-log", e); getServletResponse().setHeader(X_HV_ERROR_CODE, HvErrorCode.CLIENTPROTOCOL_EXCEPTION.toString()); getServletResponse().setHeader(X_HV_ERROR_CODE_DESCRIPTION, e.getMessage()); // TODO: Enunciate kennt "BAD_GATEWAY" nicht?? // getServletResponse().setStatus(Response.Status.BAD_GATEWAY.getStatusCode()) ; getServletResponse().setStatus(502); }
From source file:org.ubicompforall.cityexplorer.gui.ImportWebTab.java
/*** * @param webview//from w w w. jav a2 s . c o m * @return status: loaded or not */ public boolean setupWebDBs() { if (!loaded) { String responseString; HttpClient httpclient = new DefaultHttpClient(); HttpResponse response; for (String webURL : webFolders) { debug(1, "Getting webFolder " + webURL); if (CityExplorer.pingConnection(this, webURL)) { try { response = httpclient.execute(new HttpGet(webURL)); StatusLine statusLine = response.getStatusLine(); if (statusLine.getStatusCode() == HttpStatus.SC_OK) { ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); String SERVER_URL = "http://" + (new URL(webURL).getHost()); webDBs = extractDBs(responseString, SERVER_URL); if (webDBs.equals("")) { //webview.loadData( responseString, "text/html", "utf-8" ); webview.loadData("Loading page...", "text/html", "utf-8"); webview.loadUrl(webURL); } else { debug(1, "searching host " + SERVER_URL + ", extracted is " + webDBs); loaded = true; } } else { //Closes the connection on failure response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); debug(-1, "Network unavailable? " + e.getMessage() + "\n...weburl was " + webURL); } // try downloading db's from the Web, catch and print exceptions } else { debug(0, "Why!?"); CityExplorer.showNoConnectionDialog(this, "", "No Cache!", null); printNotAvailable(); } } // for all web-locations with DBs on them } // if not already loaded once before return loaded; }
From source file:com.neusou.bioroid.restful.RestfulClient.java
/** * Executes HTTP method// ww w . ja v a2 s . c o m * @param <T> Http Request Method class * @param <V> Restful response class * @param <M> restful method class * @param <R> response handler class * @param httpMethod http request method * @param rh response handler * @param data extra invocation data */ public <T extends HttpRequestBase, V extends IRestfulResponse<?>, M extends RestfulMethod, R extends RestfulResponseHandler<V, M>> void execute( final T httpMethod, R rh, final Bundle data) { Logger.l(Logger.DEBUG, LOG_TAG, "execute() " + httpMethod.getRequestLine().toString()); DefaultHttpClient httpClient = new DefaultHttpClient(); V response = null; String exceptionMessage = null; String cachedResponse = null; boolean isResponseCached = data.getBoolean(KEY_USE_CACHE, mUseCacheByDefault); String requestUrl = httpMethod.getRequestLine().getUri().toString(); Logger.l(Logger.DEBUG, LOG_TAG, "# # # # # useCache? " + isResponseCached); if (mResponseCacheInitialized && isResponseCached) { httpMethod.getParams().setBooleanParameter("param1", true); //Log.d(LOG_TAG, "paramstring: "+paramString); cachedResponse = mCacheResponseDbHelper.getResponse(requestUrl, httpMethod.getMethod()); Logger.l(Logger.DEBUG, LOG_TAG, "# # # # # cached response: " + cachedResponse); response = rh.createResponse(cachedResponse); response.set(new StringReader(cachedResponse)); } if (cachedResponse == null) { try { response = httpClient.execute(httpMethod, rh); } catch (ClientProtocolException e) { e.printStackTrace(); exceptionMessage = e.getMessage(); httpMethod.abort(); } catch (UnknownHostException e) { e.printStackTrace(); exceptionMessage = "not connected to the internet"; httpMethod.abort(); } catch (IOException e) { e.printStackTrace(); exceptionMessage = "connection error. please try again."; httpMethod.abort(); } // cache the response if (exceptionMessage == null && mResponseCacheInitialized && isResponseCached) { Logger.l(Logger.DEBUG, LOG_TAG, "# # # # # inserting response to cache: " + response); M method = data.getParcelable(XTRA_METHOD); BufferedReader br = new BufferedReader(response.get()); StringBuilder sb = new StringBuilder(); char[] buffer = new char[51200]; try { while (true) { int bytesRead; bytesRead = br.read(buffer); if (bytesRead == -1) { break; } sb.append(buffer, 0, bytesRead); } mCacheResponseDbHelper.insertResponse(requestUrl, sb.toString(), Calendar.getInstance().getTime().getTime(), httpMethod.getMethod(), method.getCallId()); } catch (IOException e) { e.printStackTrace(); } } } // process response //Logger.l(Logger.DEBUG, LOG_TAG, "starting service with action: "+INTENT_PROCESS_RESPONSE); Intent processIntent = new Intent(); processIntent.setAction(INTENT_PROCESS_RESPONSE); processIntent.putExtra(XTRA_RESPONSE, response); processIntent.putExtra(XTRA_ERROR, exceptionMessage); processIntent.putExtra(XTRA_REQUEST, data); mContext.startService(processIntent); boolean imcallback = data.getBoolean(KEY_IMMEDIATECALLBACK, false); if (imcallback) { Bundle callbackData = new Bundle(); callbackData.putBundle(XTRA_REQUEST, data); callbackData.putParcelable(XTRA_RESPONSE, response); callbackData.putString(XTRA_ERROR, exceptionMessage); broadcastCallback(mContext, callbackData, generateKey(mContext.getPackageName(), mName, RestfulClient.KEY_CALLBACK_INTENT)); } }