/** * 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]); } } }
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(); } } }
/** * 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; } }
s_logger.error(e.getMessage()); return null; } catch (IOException e) {
s_logger.error(e.getMessage()); return null; } catch (IOException e) {
} catch (HttpException hte) { status = TemplateDownloader.Status.UNRECOVERABLE_ERROR; errorString = hte.getMessage(); } catch (IOException ioe) {
s_logger.error(e.getMessage()); return null; } catch (IOException e) {
protected InputStream getInputStream() throws XmlRpcException { try { 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); } }
protected InputStream getInputStream() throws XmlRpcException { try { 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); } }
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 boolean sendSMS(String number, String token) { number = number.replace(" ", ""); final String message = "Bem-vindo ao sistema Fenix. Introduza o codigo " + token + " . Obrigado!"; if (canRun()) { PostMethod method = new PostMethod(CIIST_SMS_GATEWAY_URL); method.addParameter(new NameValuePair("number", number)); method.addParameter(new NameValuePair("msg", message)); try { CIIST_CLIENT.executeMethod(method); if (method.getStatusCode() != 200) { return false; } } catch (HttpException e) { // TODO Auto-generated catch block logger.error(e.getMessage(), e); return false; } catch (IOException e) { // TODO Auto-generated catch block logger.error(e.getMessage(), e); return false; } } else { logger.info("SMS to >" + number + "<: " + message); } return true; } }
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 void parse(URL url) { // Parse the data from inputStream, // resolving any relative URIs against the URL of the source // Set statement and error handler _parser.setParseErrorListener(new RetrieverErrorListener()); _parser.setRDFHandler(this); try { List<String> mimetypes = _parser.getRDFFormat().getMIMETypes(); InputStream input = Util.getDocumentAsInputStream(url.toString(), mimetypes); _parser.parse(input, url.toString()); } catch (RDFParseException e) { _logger.error(e.getMessage(), e); } catch (RDFHandlerException e) { _logger.error(e.getMessage(), e); } catch (HttpException e) { _logger.error(e.getMessage(), e); } catch (IOException e) { _logger.error(e.getMessage(), 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]); } } }
/** * 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]); } } }
/** * 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]); } } }
/** * 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]); } } }
private String httpPost(NameValuePair[] data) { String response = null; HttpClient client = new HttpClient(); PostMethod post = new PostMethod(url); if( data.length>1 && data[1]!=null ) { log( data[1].getName() + "::" + data[1].getValue() ); } post.setRequestBody(data); try { int statusCode = client.executeMethod(post); if (statusCode != HttpStatus.SC_OK) { log("POST failed: " + post.getStatusLine()); response = post.getStatusLine().toString(); }// else { // byte[] responseBody = post.getResponseBody(); // response = new String(responseBody); //} } catch (HttpException e) { log("Fatal protocol violation: " + e.getMessage()); response = "Fatal protocol violation: " + e.getMessage(); } catch (IOException e) { log("Fatal transport error: " + e.getMessage()); response = "Fatal transport error: " + e.getMessage(); } finally { post.releaseConnection(); } return response; }
@Override protected InputStream getInputStream() throws XmlRpcException { int responseCode = method.getStatusCode(); if (responseCode != HttpURLConnection.HTTP_OK) { XmlRpcHttpException e = new XmlRpcHttpException(responseCode); if (responseCode == HttpStatus.SC_UNAUTHORIZED) { e.setAuthScheme(method.getHostAuthState().getAuthScheme()); } throw e; } try { return method.getResponseBodyAsStream(); } catch (HttpException e) { throw new XmlRpcClientException("Error in HTTP transport: " + e.getMessage(), e); //$NON-NLS-1$ } catch (IOException e) { throw new XmlRpcClientException("I/O error in server communication: " + e.getMessage(), e); //$NON-NLS-1$ } }
protected void sendSubFolders(String command, String folderPath, boolean recursive, boolean wildcard) throws IOException { try { List<ExchangeSession.Folder> folders = session.getSubFolders(folderPath, recursive, wildcard); for (ExchangeSession.Folder folder : folders) { sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + encodeFolderPath(folder.folderPath) + '\"'); } } catch (HttpForbiddenException e) { // access forbidden, ignore DavGatewayTray.debug(new BundleMessage("LOG_SUBFOLDER_ACCESS_FORBIDDEN", folderPath)); } catch (HttpNotFoundException e) { // not found, ignore DavGatewayTray.debug(new BundleMessage("LOG_FOLDER_NOT_FOUND", folderPath)); } catch (HttpException e) { // other errors, ignore DavGatewayTray.debug(new BundleMessage("LOG_FOLDER_ACCESS_ERROR", folderPath, e.getMessage())); } }