Refine search
/** * Makes an api call using region service end_point, api command and params * @param region * @param command * @param params * @return True, if api is successful */ protected static boolean makeAPICall(Region region, String command, List<NameValuePair> params) { try { String apiParams = buildParams(command, params); String url = buildUrl(apiParams, region); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); if (client.executeMethod(method) == 200) { return true; } else { return false; } } catch (HttpException e) { s_logger.error(e.getMessage()); return false; } catch (IOException e) { s_logger.error(e.getMessage()); return false; } }
/** * Print this HttpException and its stack trace to the standard error stream. * * @since 3.0 */ public void printStackTrace() { printStackTrace(System.err); }
/** * @see HttpConnectionManager#getConnection(HostConfiguration, long) * * @deprecated Use #getConnectionWithTimeout(HostConfiguration, long) */ public HttpConnection getConnection(HostConfiguration hostConfiguration, long timeout) throws HttpException { LOG.trace("enter HttpConnectionManager.getConnection(HostConfiguration, long)"); try { return getConnectionWithTimeout(hostConfiguration, timeout); } catch(ConnectionPoolTimeoutException e) { throw new HttpException(e.getMessage()); } }
private String doCall(String uri) throws IOException { System.out.println("We're calling the uri"); HttpClient httpClient = new HttpClient(); httpClient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); HttpMethod getMethod = new GetMethod(uri); try { int response = httpClient.executeMethod(getMethod); if (response != 200) { throw new IOException("HTTP problem, httpcode: " + response); } InputStream stream = getMethod.getResponseBodyAsStream(); String responseText = responseToString(stream); return responseText; } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage());
HttpClient httpclient = new HttpClient(); httpclient.executeMethod(post); e.printStackTrace(); throw new ServletException(e);
Date start = new Date(); HttpClient client = new HttpClient(); client.getParams().setSoTimeout(timeout); GetMethod method = new GetMethod(url); int statusCode = client.executeMethod(method); throw new HttpTransportException("Fatal protocol violation: " + e.getMessage(), e); } catch (SocketTimeoutException e) { throw new HttpTransportException("SocketTimeoutExceptionn: " + e.getMessage()+", response doesn't completed in expected "+ timeout + " millis", e);
HttpClient client = new HttpClient(); client.setHostConfiguration(config); setProxy(client); client.executeMethod(method); httpe.printStackTrace(); throw createTxException(httpe); } catch (IOException ioe) {
public void logout(String token) { HttpClient httpClient = new HttpClient(); PostMethod post = new PostMethod(LOG_ENDPOINT); LOG.log(Level.INFO, "Logging out: token: [" + token + "]: REST url: [" + LOG_ENDPOINT + "]"); NameValuePair[] data = { new NameValuePair("subjectid", token) }; post.setRequestBody(data); try { httpClient.executeMethod(post); if (post.getStatusCode() != HttpStatus.SC_OK) { throw new HttpException(post.getStatusLine().toString()); } } catch (HttpException e) { // TODO Auto-generated catch block LOG.log(Level.SEVERE, e.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block LOG.log(Level.SEVERE, e.getMessage()); } finally { post.releaseConnection(); } }
public static void checkUrlExistence(String url) { if (url.toLowerCase().startsWith("http") || url.toLowerCase().startsWith("https")) { HttpClient httpClient = getHttpClient(); HeadMethod httphead = new HeadMethod(url); try { if (httpClient.executeMethod(httphead) != HttpStatus.SC_OK) { throw new IllegalArgumentException("Invalid URL: " + url); } if (url.endsWith("metalink") && !checkUrlExistenceMetalink(url)) { throw new IllegalArgumentException("Invalid URLs defined on metalink: " + url); } } catch (HttpException hte) { throw new IllegalArgumentException("Cannot reach URL: " + url + " due to: " + hte.getMessage()); } catch (IOException ioe) { throw new IllegalArgumentException("Cannot reach URL: " + url + " due to: " + ioe.getMessage()); } finally { httphead.releaseConnection(); } } }
public String authenticate(String username, String password) { HttpClient httpClient = new HttpClient(); PostMethod post = new PostMethod(AUTH_ENDPOINT); String response; String ssoToken = null; NameValuePair[] data = { new NameValuePair("username", username), new NameValuePair("password", password), new NameValuePair("uri", "realm/lmmp") }; post.setRequestBody(data); try { httpClient.executeMethod(post); if (post.getStatusCode() != HttpStatus.SC_OK) { throw new HttpException(post.getStatusLine().toString()); } response = post.getResponseBodyAsString().trim(); ssoToken = response.substring(9); } catch (Exception e) { LOG.log(Level.SEVERE, e.getMessage()); } finally { post.releaseConnection(); } return ssoToken; }
protected String[] multipartPost(LinkedList<Part> parts, String URL, int expectedSC) throws IOException { log.debug("Request POST: " + URL); parts.add(new StringPart("token", token)); PostMethod postRequest = new PostMethod(URL); MultipartRequestEntity multipartRequest = new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), postRequest.getParams()); postRequest.setRequestEntity(multipartRequest); int result = httpClient.executeMethod(postRequest); if (result != expectedSC) { String fname = File.createTempFile("error_", ".html").getAbsolutePath(); notifier.notifyAbout("Saving server error response to: " + fname); FileOutputStream fos = new FileOutputStream(fname); FileChannel resultFile = fos.getChannel(); resultFile.write(ByteBuffer.wrap(IOUtils.toByteArray(postRequest.getResponseBodyAsStream()))); resultFile.close(); throw new HttpException("Request returned not " + expectedSC + " status code: " + result); } byte[] bytes = IOUtils.toByteArray(postRequest.getResponseBodyAsStream()); if (bytes == null) { bytes = new byte[0]; } String response = new String(bytes); return response.trim().split(";"); } }
private void doAuthentication(URL jenkinsUrl) throws AuthenticationException { httpClient.getState().setCredentials( new AuthScope(jenkinsUrl.getHost(), jenkinsUrl.getPort()), new UsernamePasswordCredentials(username, password)); httpClient.getParams().setAuthenticationPreemptive(true); int responseCode = httpClient.executeMethod(post); final String responseBody; try(InputStream inputStream = post.getResponseBodyAsStream();) { throw new ConfigurationException(String.format("HTTP Error during method execution '%s': %s", jenkinsUrl.toString(), httpEx.getMessage()), httpEx); } catch (IOException ioEx) { throw new ConfigurationException(String.format("IO Error during method execution '%s': %s", jenkinsUrl.toString(), ioEx.getMessage()), ioEx);
webClient_.getCookieManager().updateState(httpClient.getState()); final HostConfiguration hostConfiguration = getHostConfiguration(settings); final long startTime = System.currentTimeMillis(); final int responseCode = httpClient.executeMethod(hostConfiguration, httpMethod); final long endTime = System.currentTimeMillis(); webClient_.getCookieManager().updateFromState(httpClient.getState()); return makeWebResponse(responseCode, httpMethod, settings, endTime - startTime); return getResponse(newRequest); throw new RuntimeException("HTTP Error: " + e.getMessage(), e); } catch (IOException e) { throw (IOException)new IOException(httpMethod.getName()+' '+url.toExternalForm()+" failed").initCause(e);
m_method.setRequestBody(m_payload); m_client.executeMethod(m_method); e.printStackTrace(); } catch (IOException e) {
method.setFollowRedirects(this.followRedirects); generateTransactionHeader(method); int status = client.executeMethod(method); HttpException ex = new HttpException(); ex.setReasonCode(status); throw ex;
httpClient.getParams().setParameter("http.socket.timeout", DEFAULT_SOCKET_TIMEOUT); httpClient.getParams().setParameter("http.connection.timeout", DEFAULT_CONNECTION_TIMEOUT); } else { httpClient.getParams().setParameter("http.socket.timeout", 0); httpClient.getParams().setParameter("http.connection.timeout", 0); throw new ConfigurationException(String.format("HTTP Error during method execution '%s': %s", url, httpEx.getMessage()), httpEx); } catch (UnknownHostException uhEx) { throw new ConfigurationException(String.format("Unknown server: %s", uhEx.getMessage()), uhEx);
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(expireSeconds > 0 ? expireSeconds * 1000 : 5000); if (logger.isDebugEnabled()) logger.debug("http Request QueryString: " + postMethod.getQueryString()); BufferedReader bufferedreader = null; try { int status = httpClient.executeMethod(postMethod); in = postMethod.getResponseBodyAsStream(); if (charSet == null) logger.error(requestUri + " 远程服务调用时发生HttpException,异常信息: " + e.getMessage()); logger.error("",e); } catch (IOException e) {
/** * Reads and stores the Trailer headers. * @throws IOException If an IO problem occurs */ private void parseTrailerHeaders() throws IOException { Header[] footers = null; try { String charset = "US-ASCII"; if (this.method != null) { charset = this.method.getParams().getHttpElementCharset(); } footers = HttpParser.parseHeaders(in, charset); } catch(HttpException e) { LOG.error("Error parsing trailer headers", e); IOException ioe = new IOException(e.getMessage()); ExceptionUtil.initCause(ioe, e); throw ioe; } if (this.method != null) { for (int i = 0; i < footers.length; i++) { this.method.addResponseFooter(footers[i]); } } }
Message.error("HttpClientHandler: " + e.getMessage() + ":" + e.getReasonCode() + "=" + e.getReason() + " url=" + url); } catch (UnknownHostException e) { Message.warn("Host " + e.getMessage() + " not found. url=" + url);