List of usage examples for org.apache.commons.httpclient HttpException getMessage
public String getMessage()
From source file:com.funambol.json.manager.JsonAuthenticatorManagerImpl.java
public void enterSyncEndStatus(String username) throws DaoException { try {/*from w w w .ja va 2 s . c o m*/ JsonResponse jsonResponse = authenticatorDAO.enterSyncEndStatus(username); exceptionUtil.throwExceptionOnJsonResponseError(jsonResponse); } catch (org.apache.commons.httpclient.HttpException httpEx) { log.error("Failed the connection to the Json backend", httpEx); throw new DaoException(httpEx.getMessage(), httpEx); } catch (IOException ioEx) { log.error("Failed the connection to the Json backend", ioEx); throw new DaoException(ioEx.getMessage(), ioEx); } }
From source file:com.funambol.json.manager.JsonAuthenticatorManagerImpl.java
public void logout(JsonUser user) throws DaoException { try {//from w ww . j av a 2s . co m JsonResponse jsonResponse = authenticatorDAO.logout(user); exceptionUtil.throwExceptionOnJsonResponseError(jsonResponse); } catch (org.apache.commons.httpclient.HttpException httpEx) { log.error("Failed the connection to the Json backend", httpEx); throw new DaoException(httpEx.getMessage(), httpEx); } catch (IOException ioEx) { log.error("Failed the connection to the Json backend", ioEx); throw new DaoException(ioEx.getMessage(), ioEx); } }
From source file:com.funambol.json.manager.JsonAuthenticatorManagerImpl.java
public boolean isSyncing(String username, String deviceId) throws DaoException { try {// w ww . j av a 2 s . c om JsonResponse jsonResponse = authenticatorDAO.isSyncing(username, deviceId); exceptionUtil.throwExceptionOnJsonResponseError(jsonResponse); exceptionUtil.throwExceptionOnResponseBodyNull(jsonResponse); return parseSyncStatus(jsonResponse); } catch (org.apache.commons.httpclient.HttpException httpEx) { log.error("Failed the connection to the Json backend", httpEx); throw new DaoException(httpEx.getMessage(), httpEx); } catch (IOException ioEx) { log.error("Failed the connection to the Json backend", ioEx); throw new DaoException(ioEx.getMessage(), ioEx); } catch (JSONException e) { e.printStackTrace(); } return false; }
From source file:com.funambol.json.manager.JsonAuthenticatorManagerImpl.java
public JsonAuthResponse login(JsonAuthRequest request) throws DaoException { try {/*from ww w .j a va 2s . c om*/ String jsonObject = converter.toJSON(request); JsonResponse jsonResponse = authenticatorDAO.login(jsonObject); exceptionUtil.throwExceptionOnJsonResponseError(jsonResponse); exceptionUtil.throwExceptionOnResponseBodyNull(jsonResponse); AuthenticatorResponseConverter converter = new AuthenticatorResponseConverter(); converter.customerUserIdLabel = this.customerUserIdLabel; JsonAuthResponse jsonAuthResponse = converter.fromJSON(jsonResponse.getResponseBody()); return jsonAuthResponse; } catch (org.apache.commons.httpclient.HttpException httpEx) { log.error("Failed the connection to the json backend", httpEx); throw new DaoException(httpEx.getMessage(), httpEx); } catch (IOException ioEx) { log.error("Failed the connection to the json backend", ioEx); throw new DaoException(ioEx.getMessage(), ioEx); } }
From source file:edu.ucsd.xmlrpc.xmlrpc.client.XmlRpcCommonsTransport.java
protected InputStream getInputStream() throws XmlRpcException { try {//from w w w . j a v a2 s . c om checkStatus(method); return method.getResponseBodyAsStream(); } catch (HttpException e) { throw new XmlRpcClientException("Error in HTTP transport: " + e.getMessage(), e); } catch (IOException e) { throw new XmlRpcClientException("I/O error in server communication: " + e.getMessage(), e); } }
From source file:com.sun.portal.rssportlet.FeedHelper.java
/** * Get the ROME SyndFeed object for the specified feed. The object may come * from a cache; the data in the feed may not be read at the time * this method is called./* ww w.j a v a 2 s. com*/ * * The <code>RssPortletBean</code> object is used to identify the feed * of interest, and the timeout value to be used when managing this * feed's cached value. * * @param bean an <code>RssPortletBean</code> object that describes * the feed of interest, and the cache timeout value for the feed. * @return a ROME <code>SyndFeed</code> object encapsulating the * feed specified by the URL. */ public SyndFeed getFeed(SettingsBean bean, String selectedFeed) throws IOException, FeedException { SyndFeed feed = null; FeedElement feedElement = (FeedElement) feeds.get(selectedFeed); if (feedElement != null && !feedElement.isExpired()) { feed = feedElement.getFeed(); } else { GetMethod httpget = null; try { SyndFeedInput input = new SyndFeedInput(); HttpClient httpclient = new HttpClient(); httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_TIMEOUT); // SO_TIMEOUT -- timeout for blocking reads httpclient.getHttpConnectionManager().getParams().setSoTimeout(SOCKET_TIMEOUT); httpget = new GetMethod(selectedFeed); //httpget.getParams().setParameter("http.socket.timeout", new Integer(20000)); // Internally the parameter collections will be linked together // by performing the following operations: // hostconfig.getParams().setDefaults(httpclient.getParams()); // httpget.getParams().setDefaults(hostconfig.getParams()); //httpclient.executeMethod(hostconfig, httpget); // Execute the method. int statusCode = httpclient.executeMethod(httpget); if (statusCode != HttpStatus.SC_OK) { log.info("Method failed: " + httpget.getStatusLine()); } // Read the response body. InputSource src = new InputSource(httpget.getResponseBodyAsStream()); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data feed = input.build(src); // // only cache the feed if the cache timeout is not equal to 0 // a cache timeout of 0 means "don't cache" // int timeout = bean.getCacheTimeout(); if (timeout != 0) { putFeed(selectedFeed, feed, timeout); } } catch (MalformedURLException mfurlex) { log.info("MalformedURLException: " + mfurlex.getMessage()); mfurlex.printStackTrace(); throw new IOException("MalformedURLException: " + mfurlex.getMessage()); } catch (HttpException httpex) { log.info("Fatal protocol violation: " + httpex.getMessage()); httpex.printStackTrace(); throw new IOException("Fatal protocol violation: " + httpex.getMessage()); } catch (IllegalArgumentException iae) { log.info("IllegalArgumentException: " + iae.getMessage()); iae.printStackTrace(); throw new IOException("IllegalArgumentException: " + iae.getMessage()); } catch (IOException ioe) { log.info("Fatal transport error: " + ioe.getMessage()); ioe.printStackTrace(); throw new IOException("Fatal transport error: " + ioe.getMessage()); } catch (ParsingFeedException parsingfeedex) { log.info("ParsingFeedException: " + parsingfeedex.getMessage()); parsingfeedex.printStackTrace(); throw new FeedException("ParsingFeedException: " + parsingfeedex.getMessage()); } catch (FeedException feedex) { log.info("FeedException: " + feedex.getMessage()); feedex.printStackTrace(); throw new FeedException("FeedException: " + feedex.getMessage()); } catch (Exception ex) { log.info("Exception ERROR: " + ex.getMessage()); ex.printStackTrace(); } finally { // Release the connection. httpget.releaseConnection(); } } return feed; }
From source file:br.org.acessobrasil.silvinha.util.versoes.AtualizadorDeVersoes.java
public boolean baixarVersao() { HttpClient client = new HttpClient(); PostMethod method = new PostMethod(url); NameValuePair param = new NameValuePair("param", "update"); method.setRequestBody(new NameValuePair[] { param }); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); JFrame down = new JFrame("Download"); File downFile = null;/*from w w w . j a va 2s.c o m*/ InputStream is = null; FileOutputStream fos = null; try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { log.error("Method failed: " + method.getStatusLine()); } Header header = method.getResponseHeader("Content-Disposition"); String fileName = "silvinha.exe"; if (header != null) { fileName = header.getValue().split("=")[1]; } // Read the response body. is = method.getResponseBodyAsStream(); down.pack(); ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(down, TradAtualizadorDeVersoes.FAZ_DOWNLOAD_FILE + fileName, is); pmis.getProgressMonitor().setMinimum(0); pmis.getProgressMonitor().setMaximum((int) method.getResponseContentLength()); downFile = new File(fileName); fos = new FileOutputStream(downFile); int c; while (((c = pmis.read()) != -1) && (!pmis.getProgressMonitor().isCanceled())) { fos.write(c); } fos.flush(); fos.close(); String msgOK = TradAtualizadorDeVersoes.DOWNLOAD_EXITO + TradAtualizadorDeVersoes.DESEJA_ATUALIZAR_EXECUTAR + TradAtualizadorDeVersoes.ARQUIVO_DE_NOME + fileName + TradAtualizadorDeVersoes.LOCALIZADO_NA + TradAtualizadorDeVersoes.PASTA_INSTALACAO + TradAtualizadorDeVersoes.APLICACAO_DEVE_SER_ENCERRADA + TradAtualizadorDeVersoes.DESEJA_CONTINUAR_ATUALIZACAO; if (JOptionPane.showConfirmDialog(null, msgOK, TradAtualizadorDeVersoes.ATUALIZACAO_DO_PROGRAMA, JOptionPane.YES_NO_OPTION) == 0) { return true; } else { return false; } } catch (HttpException he) { log.error("Fatal protocol violation: " + he.getMessage(), he); return false; } catch (InterruptedIOException iioe) { method.abort(); String msg = GERAL.OP_CANCELADA_USUARIO + TradAtualizadorDeVersoes.DIRECIONADO_A_APLICACAO; JOptionPane.showMessageDialog(down, msg); try { if (fos != null) { fos.close(); } } catch (IOException ioe) { method.releaseConnection(); System.exit(0); } if (downFile != null && downFile.exists()) { downFile.delete(); } return false; // System.err.println("Fatal transport error: " + iioe.getMessage()); // iioe.printStackTrace(); } catch (IOException ioe) { log.error("Fatal transport error: " + ioe.getMessage(), ioe); return false; } finally { //Release the connection. method.releaseConnection(); } }
From source file:com.taobao.metamorphosis.client.http.SimpleHttpConsumer.java
@Override public long offset(final FetchRequest fetchRequest) throws MetaClientException { final long start = System.currentTimeMillis(); final boolean success = false; // URI/offset/{brokerID}?topic&partition&group, {brokerID}HTTP // LBHTTP clientBroker server final String uri = "/offset/" + fetchRequest.getPartitionObject().getBrokerId() + "?topic=" + fetchRequest.getTopic() + "&partition=" + fetchRequest.getPartition() + "&offset=" + fetchRequest.getOffset();// w w w . ja v a 2 s. c o m final GetMethod httpget = new GetMethod(uri); try { this.httpclient.executeMethod(httpget); if (httpget.getStatusCode() == HttpStatus.Success) { return Long.parseLong(httpget.getResponseBodyAsString()); } else { throw new MetaClientException(httpget.getResponseBodyAsString()); } } catch (final HttpException e) { logger.error(e.getMessage(), e); throw new MetaClientException(e); } catch (final IOException e) { logger.error(e.getMessage(), e); throw new MetaClientException(e); } finally { httpget.releaseConnection(); final long duration = System.currentTimeMillis() - start; if (duration > 200) { MetaStatLog.addStatValue2(null, StatConstants.GET_TIME_STAT, fetchRequest.getTopic(), duration); } if (!success) { MetaStatLog.addStat(null, StatConstants.GET_FAILED_STAT, fetchRequest.getTopic()); } } }
From source file:com.taobao.metamorphosis.client.http.SimpleHttpConsumer.java
@Override public MessageIterator fetch(final FetchRequest fetchRequest, final long timeout, final TimeUnit timeUnit) throws MetaClientException, InterruptedException { final long start = System.currentTimeMillis(); final boolean success = false; // URI/get/{brokerID}?topic&partition&group, {brokerID}HTTP // LBHTTP clientBroker server // HTTP LBHAProxybrokerIDBorker server final String uri = "/get/" + fetchRequest.getPartitionObject().getBrokerId() + "?topic=" + fetchRequest.getTopic() + "&partition=" + fetchRequest.getPartition() + "&offset=" + fetchRequest.getOffset() + "&group=" + this.config.getGroup() + "&maxsize=" + fetchRequest.getMaxSize(); final GetMethod httpget = new GetMethod(uri); try {//w ww. j a v a 2 s . co m this.httpclient.executeMethod(httpget); if (httpget.getStatusCode() == HttpStatus.Success) { return new MessageIterator(fetchRequest.getTopic(), httpget.getResponseBody()); } else if (httpget.getStatusCode() == HttpStatus.NotFound) { return null; } else { throw new MetaClientException(httpget.getResponseBodyAsString()); } } catch (final HttpException e) { logger.error(e.getMessage(), e); throw new MetaClientException(e); } catch (final IOException e) { logger.error(e.getMessage(), e); throw new MetaClientException(e); } finally { httpget.releaseConnection(); final long duration = System.currentTimeMillis() - start; if (duration > 200) { MetaStatLog.addStatValue2(null, StatConstants.GET_TIME_STAT, fetchRequest.getTopic(), duration); } if (!success) { MetaStatLog.addStat(null, StatConstants.GET_FAILED_STAT, fetchRequest.getTopic()); } } }
From source file:eu.eco2clouds.scheduler.em.EMClientHC.java
private String postMethod(String url, String payload, String contentType, Boolean exception) { // Create an instance of HttpClient. HttpClient client = getHttpClient(); logger.debug("Connecting to: " + url); // Create a method instance. PostMethod method = new PostMethod(url); //setHeaders(method, contentType); setHeaders(method, Configuration.bonfireApiGroup); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); String response = ""; try {/*from w w w . j av a 2 s . c o m*/ RequestEntity requestEntity = new StringRequestEntity(payload, contentType, null); method.setRequestEntity(requestEntity); // Execute the method. int statusCode = client.executeMethod(method); if (statusCode >= 200 && statusCode > 300) { //TODO test for this case... logger.warn( "post managed experiments information... : " + url + " failed: " + method.getStatusLine()); } else { // Read the response body. byte[] responseBody = method.getResponseBody(); response = new String(responseBody); } } catch (HttpException e) { logger.warn("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); exception = true; } catch (IOException e) { logger.warn("Fatal transport error: " + e.getMessage()); e.printStackTrace(); exception = true; } finally { // Release the connection. method.releaseConnection(); } return response; }