Java Code Examples for org.apache.http.client.ClientProtocolException
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project android-api_1, under directory /android-lib/src/com/catchnotes/api/.
Source file: CatchAPI.java

private HttpResponse performGET(String method,List<NameValuePair> httpParams,boolean useToken){ HttpGet httpget; String uri=method; if (!uri.startsWith("http")) { uri=catchBaseUrl + uri; } if (httpParams == null || httpParams.isEmpty()) { httpget=new HttpGet(uri); } else { httpget=new HttpGet(uri + '?' + URLEncodedUtils.format(httpParams,"UTF-8")); } HttpResponse response=null; try { response=useToken ? getHttpClient().execute(httpget) : getHttpClientNoToken().execute(httpget); } catch ( ClientProtocolException e) { log("caught ClientProtocolException performing GET " + httpget.getURI(),e); return null; } catch ( UnknownHostException e) { log("caught UnknownHostException performing GET " + httpget.getURI(),null); return null; } catch ( IOException e) { log("caught IOException performing GET " + httpget.getURI(),e); return null; } sync_trace("GET " + httpget.getURI() + " returned "+ response.getStatusLine().getStatusCode()+ ' '+ response.getStatusLine().getReasonPhrase()); return response; }
Example 2
From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.
Source file: HttpGetter.java

public String execute() throws ClientProtocolException, IOException { if (response == null) { HttpClient httpClient=HttpClientSingleton.getInstance(); HttpResponse serverresponse=null; serverresponse=httpClient.execute(httpget); HttpEntity entity=serverresponse.getEntity(); StringWriter writer=new StringWriter(); IOUtils.copy(entity.getContent(),writer); response=writer.toString(); } return response; }
Example 3
From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.
Source file: HttpPoster.java

public String execute() throws ClientProtocolException, IOException { if (response == null) { HttpClient httpClient=HttpClientSingleton.getInstance(); HttpResponse serverresponse=null; serverresponse=httpClient.execute(httppost); HttpEntity entity=serverresponse.getEntity(); StringWriter writer=new StringWriter(); IOUtils.copy(entity.getContent(),writer); response=writer.toString(); } return response; }
Example 4
From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/model/manageData/.
Source file: ViewTools.java

public String getOfqualQualPage(String qualificationNumber) throws ClientProtocolException, IOException { qualificationNumber=qualificationNumber.replace("/","_").replaceAll("[^\\w_]",""); ; String url="http://register.ofqual.gov.uk/Qualification/Details/" + qualificationNumber; return Request.Get(url).execute().returnContent().asString(); }
Example 5
From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/model/manageData/.
Source file: ViewTools.java

public String getOfqualOutcomesPage(String unitCode) throws ClientProtocolException, IOException { unitCode=unitCode.replace("/","_").replaceAll("[^\\w_]",""); ; String url="http://register.ofqual.gov.uk/Unit/Details/" + unitCode; return Request.Get(url).execute().returnContent().asString(); }
Example 6
From project ajah, under directory /ajah-http/src/main/java/com/ajah/http/.
Source file: Http.java

private static HttpEntity internalGet(final URI uri) throws IOException, ClientProtocolException, NotFoundException, UnexpectedResponseCode { final HttpClient httpclient=new DefaultHttpClient(); final HttpGet httpget=new HttpGet(uri); final HttpResponse response=httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() == 200) { final HttpEntity entity=response.getEntity(); return entity; } else if (response.getStatusLine().getStatusCode() == 404) { throw new NotFoundException(response.getStatusLine().getStatusCode() + " - " + response.getStatusLine().getReasonPhrase()); } else { throw new UnexpectedResponseCode(response.getStatusLine().getStatusCode() + " - " + response.getStatusLine().getReasonPhrase()); } }
Example 7
From project ALP, under directory /workspace/alp-reporter/src/main/java/com/lohika/alp/reporter/client/.
Source file: LogUploader.java

/** * Upload certain log to server. * @param testMethodId the ID of test method which log will be uploaded * @param logFile - instance of file to upload * @throws ClientProtocolException the client protocol exception * @throws IOException Signals that an I/O exception has occurred. */ public void upload(long testMethodId,File logFile) throws ClientProtocolException, IOException { String url=server + "/results/test-method/" + testMethodId+ "/log"; HttpClient httpclient=new DefaultHttpClient(); HttpPost httppost=new HttpPost(url); MultipartEntity mpEntity=new MultipartEntity(); ContentBody cbFile=new FileBody(logFile); mpEntity.addPart("fileData",cbFile); httppost.setEntity(mpEntity); httpclient.execute(httppost); }
Example 8
From project Amantech, under directory /Android/cloudLogin/src/com/cloude/entropin/.
Source file: GAEConnector.java

/** * Get AuthCookie from App Engine */ private Cookie retrieveAuthCookie(String authToken) throws ClientProtocolException, IOException { String url=_gaeAppLoginUrl + "?continue=" + URLEncoder.encode(_gaeAppBaseUrl,"UTF-8")+ "&auth="+ URLEncoder.encode(authToken,"UTF-8"); Log.d("retrieveAuthCookie","cookieUrl = " + url); DefaultHttpClient httpClient=new DefaultHttpClient(); BasicHttpParams params=new BasicHttpParams(); HttpClientParams.setRedirecting(params,false); httpClient.setParams(params); HttpGet httpget=new HttpGet(url); HttpResponse response=httpClient.execute(httpget); if (response.getStatusLine().getStatusCode() != 302) return null; Cookie theCookie=null; String cookieName=_usehttps ? "SACSID" : "ACSID"; for ( Cookie c : httpClient.getCookieStore().getCookies()) { if (c.getName().equals(cookieName)) { theCookie=c; Log.v("retrieveAuthCookie","TheCookie: " + theCookie.getName() + " = "+ theCookie.getValue()); } } return theCookie; }
Example 9
From project android-api_1, under directory /android-lib/src/com/catchnotes/api/.
Source file: CatchAPI.java

private HttpResponse performDELETE(String method,List<NameValuePair> httpParams){ HttpDelete httpdelete; if (httpParams == null || httpParams.isEmpty()) { httpdelete=new HttpDelete(catchBaseUrl + method); } else { httpdelete=new HttpDelete(catchBaseUrl + method + '?'+ URLEncodedUtils.format(httpParams,"UTF-8")); } HttpResponse response=null; try { response=getHttpClient().execute(httpdelete); } catch ( ClientProtocolException e) { log("caught ClientProtocolException performing DELETE " + httpdelete.getURI(),e); return null; } catch ( IOException e) { log("caught IOException performing DELETE " + httpdelete.getURI(),e); return null; } sync_trace("DELETE " + httpdelete.getURI() + " returned "+ response.getStatusLine().getStatusCode()+ ' '+ response.getStatusLine().getReasonPhrase()); return response; }
Example 10
From project android-bankdroid, under directory /src/com/liato/bankdroid/banking/.
Source file: Bank.java

public SessionPackage getSessionPackage(Context context){ String preloader="Error..."; try { preloader=IOUtils.toString(context.getResources().openRawResource(R.raw.loading)); } catch ( NotFoundException e1) { e1.printStackTrace(); } catch ( IOException e1) { e1.printStackTrace(); } try { LoginPackage lp=preLogin(); if (lp == null) { throw new BankException("No automatic login for this bank. preLogin() is not implemented or has failed."); } String html=String.format(preloader,"function go(){document.getElementById('submitform').submit(); }",Helpers.renderForm(lp.getLoginTarget(),lp.getPostData()) + "<script type=\"text/javascript\">setTimeout('go()', 1000);</script>"); CookieStore cookies=urlopen.getHttpclient().getCookieStore(); return new SessionPackage(html,cookies); } catch ( ClientProtocolException e) { Log.e(TAG,e.getMessage()); } catch ( IOException e) { Log.e(TAG,e.getMessage()); } catch ( BankException e) { Log.e(TAG,e.getMessage()); } String html=String.format(preloader,String.format("function go(){window.location=\"%s\" }",this.URL),"<script type=\"text/javascript\">setTimeout('go()', 1000);</script>"); return new SessionPackage(html,null); }
Example 11
From project android-bankdroid, under directory /src/com/liato/bankdroid/banking/banks/.
Source file: AkeliusInvest.java

@Override protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException { urlopen=new Urllib(); String response=urlopen.open("https://online.akeliusinvest.com/login.mws"); Matcher matcher=reLogintoken.matcher(response); if (!matcher.find()) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " logintoken."); } String strLogintoken=matcher.group(1); List<NameValuePair> postData=new ArrayList<NameValuePair>(); postData.add(new BasicNameValuePair("action","login")); postData.add(new BasicNameValuePair("logintoken",strLogintoken)); postData.add(new BasicNameValuePair("df_username",username)); postData.add(new BasicNameValuePair("df_password",password)); postData.add(new BasicNameValuePair("Language","SV")); postData.add(new BasicNameValuePair("IdleTime","900")); return new LoginPackage(urlopen,postData,response,"https://online.akeliusinvest.com/login.mws"); }
Example 12
From project android-client, under directory /xwiki-android-rest/src/org/xwiki/android/rest/.
Source file: HttpConnector.java

public int headRequest(String Uri) throws RestConnectionException { initialize(); HttpHead request=new HttpHead(); try { requestUri=new URI(Uri); } catch ( URISyntaxException e) { e.printStackTrace(); } setCredentials(); request.setURI(requestUri); Log.d("HEAD Request URL",Uri); try { response=client.execute(request); Log.d("Response status",response.getStatusLine().toString()); return response.getStatusLine().getStatusCode(); } catch ( ClientProtocolException e) { e.printStackTrace(); } catch ( IOException e) { e.printStackTrace(); throw new RestConnectionException(e); } return -1; }
Example 13
From project android-client, under directory /xwiki-android-rest/src/org/xwiki/android/rest/.
Source file: HttpConnector.java

/** * Perform HTTP Get method execution and return the response as a String * @param Uri URL of XWiki RESTful API * @return Response data of the HTTP connection as a String */ public String getResponse(String Uri) throws RestConnectionException, RestException { initialize(); BufferedReader in=null; HttpGet request=new HttpGet(); String responseText=new String(); try { requestUri=new URI(Uri); } catch ( URISyntaxException e) { e.printStackTrace(); } setCredentials(); request.setURI(requestUri); Log.d("GET Request URL",Uri); try { response=client.execute(request); Log.d("Response status",response.getStatusLine().toString()); in=new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer sb=new StringBuffer(""); String line=""; String NL=System.getProperty("line.separator"); while ((line=in.readLine()) != null) { sb.append(line + NL); } in.close(); responseText=sb.toString(); Log.d("Response","response: " + responseText); validate(response.getStatusLine().getStatusCode()); } catch ( ClientProtocolException e) { e.printStackTrace(); } catch ( IOException e) { e.printStackTrace(); throw new RestConnectionException(e); } return responseText; }
Example 14
From project android-rackspacecloud, under directory /extensions/apachehc/src/main/java/org/jclouds/http/apachehc/.
Source file: ApacheHCHttpCommandExecutorService.java

private org.apache.http.HttpResponse executeRequest(HttpUriRequest nativeRequest) throws IOException, ClientProtocolException { URI endpoint=URI.create(nativeRequest.getRequestLine().getUri()); HttpHost host=new HttpHost(endpoint.getHost(),endpoint.getPort(),endpoint.getScheme()); org.apache.http.HttpResponse nativeResponse=client.execute(host,nativeRequest); return nativeResponse; }
Example 15
From project android-rackspacecloud, under directory /src/com/rackspace/cloud/files/api/client/.
Source file: ContainerManager.java

public HttpBundle create(Editable editable) throws CloudServersException { HttpResponse resp=null; CustomHttpClient httpclient=new CustomHttpClient(context); String url=getSafeURL(Account.getAccount().getStorageUrl(),editable.toString()); HttpPut put=new HttpPut(url); put.addHeader("X-Auth-Token",Account.getAccount().getAuthToken()); httpclient.removeRequestInterceptorByClass(RequestExpectContinue.class); HttpBundle bundle=new HttpBundle(); bundle.setCurlRequest(put); try { resp=httpclient.execute(put); bundle.setHttpResponse(resp); } catch ( ClientProtocolException e) { CloudServersException cse=new CloudServersException(); cse.setMessage(e.getLocalizedMessage()); throw cse; } catch ( IOException e) { CloudServersException cse=new CloudServersException(); cse.setMessage(e.getLocalizedMessage()); throw cse; } catch ( FactoryConfigurationError e) { CloudServersException cse=new CloudServersException(); cse.setMessage(e.getLocalizedMessage()); throw cse; } return bundle; }
Example 16
From project android-rss, under directory /src/main/java/org/mcsoxford/rss/.
Source file: RSSReader.java

/** * Send HTTP GET request and parse the XML response to construct an in-memory representation of an RSS 2.0 feed. * @param uri RSS 2.0 feed URI * @return in-memory representation of downloaded RSS feed * @throws RSSReaderException if RSS feed could not be retrieved because ofHTTP error * @throws RSSFault if an unrecoverable IO error has occurred */ public RSSFeed load(String uri) throws RSSReaderException { final HttpGet httpget=new HttpGet(uri); InputStream feedStream=null; try { final HttpResponse response=httpclient.execute(httpget); final StatusLine status=response.getStatusLine(); if (status.getStatusCode() != HttpStatus.SC_OK) { throw new RSSReaderException(status.getStatusCode(),status.getReasonPhrase()); } HttpEntity entity=response.getEntity(); feedStream=entity.getContent(); RSSFeed feed=parser.parse(feedStream); if (feed.getLink() == null) { feed.setLink(android.net.Uri.parse(uri)); } return feed; } catch ( ClientProtocolException e) { throw new RSSFault(e); } catch ( IOException e) { throw new RSSFault(e); } finally { Resources.closeQuietly(feedStream); } }
Example 17
From project android-tether, under directory /src/og/android/tether/.
Source file: C2DMReceiver.java

@Override public void onMessage(Context context,Intent intent){ Bundle extras=intent.getExtras(); if (extras != null) { Log.d(TAG,"Received message: " + extras.toString()); String msg=(String)extras.get("msg"); String title=(String)extras.get("title"); String uid=(String)extras.get("uid"); DefaultHttpClient client=new DefaultHttpClient(); HttpGet get=new HttpGet(DeviceRegistrar.RECEIVED_PATH + "?uid=" + uid); try { client.execute(get); } catch ( ClientProtocolException e) { } catch ( IOException e) { } String url=DeviceRegistrar.REACT_PATH + "?uid=" + uid; Intent launchIntent=new Intent(Intent.ACTION_VIEW,Uri.parse(url)); launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); generateNotification(context,msg,title,launchIntent); } }
Example 18
From project android-tether, under directory /src/og/android/tether/.
Source file: RSSReader.java

InputStream httpGetRSS(String url){ HttpResponse response=null; InputStream content=null; try { response=new DefaultHttpClient().execute(new HttpGet(RSS_URL)); content=response.getEntity().getContent(); } catch ( ClientProtocolException e) { e.printStackTrace(); } catch ( IOException e) { e.printStackTrace(); } if (response == null) { Log.e(TAG,"httpGet failed: no response."); } else if (response.getStatusLine().getStatusCode() != 200) { Log.e(TAG,"httpGet failed: " + response.getStatusLine().getStatusCode()); } else { Log.d(TAG,"Response code: " + response.getStatusLine().getStatusCode()); } return content; }
Example 19
From project androidquery, under directory /src/com/androidquery/callback/.
Source file: AbstractAjaxCallback.java

private void httpEntity(String url,HttpEntityEnclosingRequestBase req,Map<String,String> headers,Map<String,Object> params,AjaxStatus status) throws ClientProtocolException, IOException { req.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,false); HttpEntity entity=null; Object value=params.get(AQuery.POST_ENTITY); if (value instanceof HttpEntity) { entity=(HttpEntity)value; } else { List<NameValuePair> pairs=new ArrayList<NameValuePair>(); for ( Map.Entry<String,Object> e : params.entrySet()) { value=e.getValue(); if (value != null) { pairs.add(new BasicNameValuePair(e.getKey(),value.toString())); } } entity=new UrlEncodedFormEntity(pairs,"UTF-8"); } if (headers != null && !headers.containsKey("Content-Type")) { headers.put("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"); } req.setEntity(entity); httpDo(req,url,headers,status); }
Example 20
From project androidquery, under directory /tests/src/com/androidquery/test/.
Source file: AQueryAsyncTest.java

public void testAjaxProxy() throws ClientProtocolException, IOException { String url="http://www.google.com"; aq.ajax(url,String.class,new AjaxCallback<String>(){ @Override public void callback( String url, String json, AjaxStatus status){ done(url,json,status); } } .proxy("112.25.12.38",80)); waitAsync(); assertNotNull(result); List<Header> headers=status.getHeaders(); assertTrue(headers.size() > 0); Header c=headers.get(0); AQUtility.debug(c.getName(),c.getValue()); }
Example 21
From project android_7, under directory /src/org/immopoly/android/helper/.
Source file: WebHelper.java

private static HttpResponse postHttp(String url,JSONObject jsonObject) throws ClientProtocolException, IOException { HttpClient httpclient=new DefaultHttpClient(); HttpPost httppost=new HttpPost(url); httppost.setHeader("User-Agent","immopoly android client " + ImmopolyActivity.getStaticVersionInfo()); httppost.setHeader("Accept-Encoding","gzip"); HttpEntity entity; entity=new StringEntity(jsonObject.toString()); httppost.setEntity(entity); return httpclient.execute(httppost); }
Example 22
From project androlog, under directory /androlog/src/main/java/de/akquinet/android/androlog/reporter/.
Source file: PostReporter.java

public static void postReport(URL url,String param) throws IOException { HttpClient httpclient=new DefaultHttpClient(); HttpPost httppost=new HttpPost(url.toExternalForm()); try { List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("report",param)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httpclient.execute(httppost); } catch ( ClientProtocolException e) { throw new IOException(e.getMessage()); } }
Example 23
From project Anki-Android, under directory /src/com/ichi2/anki/.
Source file: AnkiDroidProxy.java

public String getDecks(){ String decksServer="{}"; try { String data="p=" + URLEncoder.encode(mPassword,"UTF-8") + "&client=ankidroid-0.4&u="+ URLEncoder.encode(mUsername,"UTF-8")+ "&d=None&sources="+ URLEncoder.encode("[]","UTF-8")+ "&libanki=0.9.9.8.6&pversion=5"; HttpPost httpPost=new HttpPost(SYNC_URL + "getDecks"); StringEntity entity=new StringEntity(data); httpPost.setEntity(entity); httpPost.setHeader("Accept-Encoding","identity"); httpPost.setHeader("Content-type","application/x-www-form-urlencoded"); DefaultHttpClient httpClient=new DefaultHttpClient(); HttpResponse response=httpClient.execute(httpPost); Log.i(AnkiDroidApp.TAG,"Response = " + response.toString()); HttpEntity entityResponse=response.getEntity(); Log.i(AnkiDroidApp.TAG,"Entity's response = " + entityResponse.toString()); InputStream content=entityResponse.getContent(); Log.i(AnkiDroidApp.TAG,"Content = " + content.toString()); decksServer=Utils.convertStreamToString(new InflaterInputStream(content)); Log.i(AnkiDroidApp.TAG,"String content = " + decksServer); } catch ( UnsupportedEncodingException e) { e.printStackTrace(); } catch ( ClientProtocolException e) { Log.i(AnkiDroidApp.TAG,"ClientProtocolException = " + e.getMessage()); } catch ( IOException e) { Log.i(AnkiDroidApp.TAG,"IOException = " + e.getMessage()); } return decksServer; }
Example 24
From project Anki-Android, under directory /src/com/ichi2/anki/.
Source file: AnkiDroidProxy.java

public void createDeck(String name){ Log.i(AnkiDroidApp.TAG,"createDeck"); try { String data="p=" + URLEncoder.encode(mPassword,"UTF-8") + "&u="+ URLEncoder.encode(mUsername,"UTF-8")+ "&d=None&name="+ URLEncoder.encode(name,"UTF-8"); HttpPost httpPost=new HttpPost(SYNC_URL + "createDeck"); StringEntity entity=new StringEntity(data); httpPost.setEntity(entity); httpPost.setHeader("Accept-Encoding","identity"); httpPost.setHeader("Content-type","application/x-www-form-urlencoded"); DefaultHttpClient httpClient=new DefaultHttpClient(); HttpResponse response=httpClient.execute(httpPost); Log.i(AnkiDroidApp.TAG,"Response = " + response.toString()); HttpEntity entityResponse=response.getEntity(); Log.i(AnkiDroidApp.TAG,"Entity's response = " + entityResponse.toString()); InputStream content=entityResponse.getContent(); Log.i(AnkiDroidApp.TAG,"Content = " + content.toString()); Log.i(AnkiDroidApp.TAG,"String content = " + Utils.convertStreamToString(new InflaterInputStream(content))); mDecks.put(name,new JSONArray("[0,0]")); } catch ( UnsupportedEncodingException e) { e.printStackTrace(); } catch ( ClientProtocolException e) { Log.i(AnkiDroidApp.TAG,"ClientProtocolException = " + e.getMessage()); e.printStackTrace(); } catch ( IOException e) { Log.i(AnkiDroidApp.TAG,"IOException = " + e.getMessage()); e.printStackTrace(); } catch ( JSONException e) { Log.i(AnkiDroidApp.TAG,"JSONException = " + e.getMessage()); e.printStackTrace(); } }