List of usage examples for org.apache.commons.httpclient HttpException getMessage
public String getMessage()
From source file:it.eng.spagobi.engines.talend.client.SpagoBITalendEngineClient_0_5_0.java
private String getEngineInfo(String infoType) throws EngineUnavailableException, ServiceInvocationFailedException { String version;/*from ww w . ja v a 2 s . com*/ HttpClient client; PostMethod method; NameValuePair[] nameValuePairs; version = null; client = new HttpClient(); method = new PostMethod(getServiceUrl(ENGINE_INFO_SERVICE)); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); nameValuePairs = new NameValuePair[] { new NameValuePair("infoType", infoType) }; //$NON-NLS-1$ method.setRequestBody(nameValuePairs); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new ServiceInvocationFailedException( Messages.getString("SpagoBITalendEngineClient_0_5_0.serviceExcFailed") //$NON-NLS-1$ + ENGINE_INFO_SERVICE, method.getStatusLine().toString(), method.getResponseBodyAsString()); } else { version = method.getResponseBodyAsString(); } } catch (HttpException e) { throw new EngineUnavailableException( Messages.getString("SpagoBITalendEngineClient_0_5_0.protocolViolation") + e.getMessage()); //$NON-NLS-1$ } catch (IOException e) { throw new EngineUnavailableException( Messages.getString("SpagoBITalendEngineClient_0_5_0.transportError") + e.getMessage()); //$NON-NLS-1$ } finally { // Release the connection. method.releaseConnection(); } return version; }
From source file:it.eng.spagobi.engines.talend.client.SpagoBITalendEngineClient_0_5_0.java
public boolean deployJob(JobDeploymentDescriptor jobDeploymentDescriptor, File executableJobFiles) throws EngineUnavailableException, AuthenticationFailedException, ServiceInvocationFailedException { HttpClient client;//www . j a va 2 s .com PostMethod method; File deploymentDescriptorFile; boolean result = false; client = new HttpClient(); method = new PostMethod(getServiceUrl(JOB_UPLOAD_SERVICE)); deploymentDescriptorFile = null; try { deploymentDescriptorFile = File.createTempFile("deploymentDescriptor", ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ FileWriter writer = new FileWriter(deploymentDescriptorFile); writer.write(jobDeploymentDescriptor.toXml()); writer.flush(); writer.close(); Part[] parts = { new FilePart(executableJobFiles.getName(), executableJobFiles), new FilePart("deploymentDescriptor", deploymentDescriptorFile) }; //$NON-NLS-1$ method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(method); if (status == HttpStatus.SC_OK) { if (method.getResponseBodyAsString().equalsIgnoreCase("OK")) //$NON-NLS-1$ result = true; } else { throw new ServiceInvocationFailedException( Messages.getString("SpagoBITalendEngineClient_0_5_0.serviceExcFailed") + JOB_UPLOAD_SERVICE, //$NON-NLS-1$ method.getStatusLine().toString(), method.getResponseBodyAsString()); } } catch (HttpException e) { throw new EngineUnavailableException( Messages.getString("SpagoBITalendEngineClient_0_5_0.protocolViolation") + e.getMessage()); //$NON-NLS-1$ } catch (IOException e) { throw new EngineUnavailableException( Messages.getString("SpagoBITalendEngineClient_0_5_0.transportError") + e.getMessage()); //$NON-NLS-1$ } finally { method.releaseConnection(); if (deploymentDescriptorFile != null) deploymentDescriptorFile.delete(); } return result; }
From source file:controllers.sparql.SparqlQueryExecuter.java
public String request(URL url) throws SparqlExecutionException { GetMethod method = new GetMethod(url.toString()); String response = null;/* ww w . j ava 2 s. c o m*/ // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("SparqlQuery failed: " + method.getStatusLine()); throw new SparqlExecutionException(String.format("%s (%s). %s", method.getStatusLine(), method.getURI(), method.getResponseBodyAsString())); } // Read the response body. byte[] responseBody = method.getResponseBody(); // Deal with the response. // Use caution: ensure correct character encoding and is not binary data response = new String(responseBody); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); throw new SparqlExecutionException(e); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); throw new SparqlExecutionException(e); } finally { // Release the connection. method.releaseConnection(); } return response; }
From source file:fr.jayasoft.ivy.url.HttpClientHandler.java
public URLInfo getURLInfo(URL url, int timeout) { HeadMethod head = null;/*from w ww .j av a 2s.c o m*/ try { head = doHead(url, timeout); int status = head.getStatusCode(); head.releaseConnection(); if (status == HttpStatus.SC_OK) { return new URLInfo(true, getResponseContentLength(head), getLastModified(head)); } if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { Message.error("Your proxy requires authentication."); } else if (String.valueOf(status).startsWith("4")) { Message.verbose("CLIENT ERROR: " + head.getStatusText() + " url=" + url); } else if (String.valueOf(status).startsWith("5")) { Message.warn("SERVER ERROR: " + head.getStatusText() + " url=" + url); } Message.debug("HTTP response status: " + status + "=" + head.getStatusText() + " url=" + url); } catch (HttpException e) { Message.error("HttpClientHandler: " + e.getMessage() + ":" + e.getReasonCode() + "=" + e.getReason() + " url=" + url); } catch (UnknownHostException e) { Message.warn("Host " + e.getMessage() + " not found. url=" + url); Message.info( "You probably access the destination server through a proxy server that is not well configured."); } catch (IOException e) { Message.error("HttpClientHandler: " + e.getMessage() + " url=" + url); } finally { if (head != null) { head.releaseConnection(); } } return UNAVAILABLE; }
From source file:com.testmax.uri.ExecuteHttpRequest.java
public String handleHTTPPostPerformance() throws Exception { String resp = null;/*from w ww .j ava 2 s . c o m*/ boolean isItemIdReplaced = false; String replacedParam = ""; // Create a method instance. List<NameValuePair> nvps = new ArrayList<NameValuePair>(); URLConfig urlConf = this.page.getPageURL().getUrlConfig(this.action); List<Element> globalItemList = urlConf.getItemListElement(); if (globalItemList.size() > 0) { urlConf.setItemList(); isItemIdReplaced = true; } String newurl = urlConf.replaceGlobalItemIdForUrl(this.url); PostMethod method = new PostMethod(newurl); System.out.println(newurl); Set<String> s = urlConf.getUrlParamset(); for (String param : s) { if (!isItemIdReplaced) { //nvps.add(new BasicNameValuePair(param,urlConf.getUrlParamValue(param))); method.addParameter(param, urlConf.getUrlParamValue(param)); } else { replacedParam = urlConf.getUrlReplacedItemIdParamValue(param); method.addParameter(param, replacedParam); //System.out.println(replacedParam); //nvps.add(new BasicNameValuePair(param,replacedParam)); } } org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient(); this.startRecording(); int startcount = 0; long starttime = this.getCurrentTime(); int statusCode = 0; try { // Execute the method. statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { WmLog.getCoreLogger() .info("Auth Server response received, but there was a ParserConfigurationException: "); } // Read the response body. byte[] responseBody = method.getResponseBody(); resp = new String(responseBody, "UTF-8"); // log the response WmLog.getCoreLogger().info("MDE Request : " + resp); } catch (HttpException e) { WmLog.getCoreLogger().info("Unable to retrieve response from MDE webservice : " + e.getMessage()); return null; } catch (IOException e) { WmLog.getCoreLogger().info("Unable to retrieve response from MDE webservice : " + e.getMessage()); return null; } finally { // Release the connection. method.releaseConnection(); } // Measure the time passed between response long elaspedTime = this.getElaspedTime(starttime); this.stopMethodRecording(statusCode, elaspedTime, startcount); //System.out.println(resp); System.out.println("ElaspedTime: " + elaspedTime); WmLog.getCoreLogger().info("Response XML: " + resp); WmLog.getCoreLogger().info("ElaspedTime: " + elaspedTime); this.printMethodRecording(statusCode, newurl); this.printMethodLog(statusCode, newurl); if (statusCode == 200 && validateAssert(urlConf, resp)) { this.addThreadActionMonitor(this.action, true, elaspedTime); } else { this.addThreadActionMonitor(this.action, false, elaspedTime); WmLog.getCoreLogger().info("Input XML: " + replacedParam); WmLog.getCoreLogger().info("Response XML: " + resp); } return (resp); }
From source file:eu.eco2clouds.scheduler.bonfire.BFClientSchedulerImpl.java
private String putMethod(String url, String payload, Boolean exception) { // Create an instance of HttpClient. HttpClient client = getHttpClient(); logger.debug("Connecting to: " + url); // Create a method instance. PutMethod method = new PutMethod(url); setHeaders(method);/*from w w w . ja v a2s .c o m*/ // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); String response = ""; try { RequestEntity entity = new StringRequestEntity(payload, SchedulerDictionary.CONTENT_TYPE_BONFIRE_XML, "UTF-8"); method.setRequestEntity(entity); // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_ACCEPTED) { //TODO test for this case... logger.warn( "get 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; }
From source file:com.testmax.uri.HttpSoapWebservice.java
public String handleHTTPPostPerformance() throws Exception { String resp = null;/*from w w w .j a va 2 s . c om*/ int startcount = 5; boolean isItemIdReplaced = false; String replacedParam = ""; // Create a method instance. PostMethod method = new PostMethod(this.url); System.out.println(this.url); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); URLConfig urlConf = this.page.getPageURL().getUrlConfig(this.action); List<Element> globalItemList = urlConf.getItemListElement(); if (globalItemList.size() > 0) { urlConf.setItemList(); isItemIdReplaced = true; } Set<String> s = urlConf.getUrlParamset(); for (String param : s) { if (!isItemIdReplaced) { method.addParameter(param, urlConf.getUrlParamValue(param)); } else { replacedParam = urlConf.getUrlReplacedItemIdParamValue(param); method.addParameter(param, replacedParam); } } org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient(); this.startRecording(); long starttime = this.getCurrentTime(); int statusCode = 0; try { // Execute the method. statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { WmLog.getCoreLogger() .info("Auth Server response received, but there was a ParserConfigurationException: "); } // Read the response body. byte[] responseBody = method.getResponseBody(); resp = new String(responseBody, "UTF-8"); // log the response WmLog.getCoreLogger().info("MDE Request : " + resp); } catch (HttpException e) { WmLog.getCoreLogger().info("Unable to retrieve response from MDE webservice : " + e.getMessage()); return null; } catch (IOException e) { WmLog.getCoreLogger().info("Unable to retrieve response from MDE webservice : " + e.getMessage()); return null; } finally { // Release the connection. method.releaseConnection(); } // Measure the time passed between response long elaspedTime = this.getElaspedTime(starttime); this.stopMethodRecording(statusCode, elaspedTime, startcount); //System.out.println(resp); System.out.println("ElaspedTime: " + elaspedTime); WmLog.getCoreLogger().info("Response XML: " + resp); WmLog.getCoreLogger().info("ElaspedTime: " + elaspedTime); this.printMethodRecording(statusCode, this.url); this.printMethodLog(statusCode, this.url); if (statusCode == 200 && validateAssert(urlConf, resp)) { this.addThreadActionMonitor(this.action, true, elaspedTime); } else { this.addThreadActionMonitor(this.action, false, elaspedTime); WmLog.getCoreLogger().info("Input XML: " + replacedParam); WmLog.getCoreLogger().info("Response XML: " + resp); } return (resp); }
From source file:grafix.basedados.Download.java
public int baixaArquivo() { // Create an instance of HttpClient. HttpClient client = new HttpClient(); int retorno = 0; // Create a method instance. if (this.usaProxy) { client.getHostConfiguration().setProxy(this.servidorProxy, this.portaProxy); client.getState().setProxyCredentials(new AuthScope(this.servidorProxy, this.portaProxy), new UsernamePasswordCredentials(this.usuarioProxy, this.senhaProxy)); client.getParams().setAuthenticationPreemptive(true); }//from w ww . ja va 2 s . c om URI url2; String ff = null; try { url2 = new URI(this.getUrl(), false); ff = url2.toString(); } catch (URIException ex) { ex.printStackTrace(); } catch (NullPointerException ex) { ex.printStackTrace(); } GetMethod method = new GetMethod(ff); byte[] arquivo = null; long totalBytesRead = 0; long loopBytesRead = 0; // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); byte[] buffer = new byte[4096]; int progresso = 0; try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusCode() + " " + method.getStatusLine()); retorno = method.getStatusCode(); } else { long contentLength = method.getResponseContentLength(); File file = new File(this.getArquivo()); FileOutputStream os = new FileOutputStream(file); InputStream stream = method.getResponseBodyAsStream(); while ((loopBytesRead = stream.read(buffer)) != -1) { for (int i = 0; i < loopBytesRead; i++) { os.write(buffer[i]); } totalBytesRead += loopBytesRead; progresso = (int) ((float) totalBytesRead / contentLength * 100); if (progresso >= 0 || progresso <= 100) { // System.out.println("download " + progresso + " %"); if (this.mostraProgresso) formAtualizacao.definirPercentualProgresso(progresso); } } os.flush(); os.close(); stream.close(); } } catch (HttpException e) { retorno = 2; System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { retorno = 3; System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } if (this.mostraProgresso) formAtualizacao.definirPercentualProgresso(0); return retorno; }
From source file:com.tribune.uiautomation.testscripts.Photo.java
private boolean delete(String namespaceParam, String slugParam) { checkValidStateForDelete();//from w w w . j a v a 2 s . c o m DeleteMethod delete = new DeleteMethod(constructResourceUrl(namespaceParam, slugParam)); try { setRequestHeaders(delete); HttpClient client = new HttpClient(); int status = client.executeMethod(delete); log.debug("Photo Service delete return status: " + delete.getStatusLine()); if (status == HttpStatus.SC_OK) { return true; } } catch (HttpException e) { log.fatal("Fatal protocol violation: " + e.getMessage(), e); } catch (IOException e) { log.fatal("Fatal transport error: " + e.getMessage(), e); } finally { // Release the connection. delete.releaseConnection(); } return false; }
From source file:com.tribune.uiautomation.testscripts.Photo.java
public boolean update() throws JSONException { checkValidStateForCreate();//w w w .j av a 2 s . c o m PutMethod put = new PutMethod(constructResourceUrl(namespace, slug)); try { setRequestHeaders(put); setParameters(put); HttpClient client = new HttpClient(); int status = client.executeMethod(put); log.debug("Photo Service update return status: " + put.getStatusLine()); if (status == HttpStatus.SC_OK) { processResponse(this, put.getResponseBodyAsStream()); return true; } } catch (HttpException e) { log.fatal("Fatal protocol violation: " + e.getMessage(), e); } catch (IOException e) { log.fatal("Fatal transport error: " + e.getMessage(), e); } finally { // Release the connection. put.releaseConnection(); } return false; }