List of usage examples for org.apache.commons.httpclient URIException URIException
public URIException(int reasonCode, String reason)
From source file:de.juwimm.cms.common.http.HttpClientWrapper.java
protected HttpMethodBase invoke(URL targetURL, String userName, String password) throws URIException { HttpMethodBase method = null;/*from www . ja v a2 s . c om*/ if (log.isDebugEnabled()) log.debug(targetURL.toExternalForm()); method = new GetMethod(targetURL.toExternalForm()); HttpClient httpClient = getNewHttpClient(); if (userName != null) { // Credentials for destination URL Credentials cred = new UsernamePasswordCredentials(userName, password); httpClient.getParams().setAuthenticationPreemptive(true); httpClient.getState().setCredentials(AUTHSCOPE_ANY, cred); } setHostConfiguration(httpClient, targetURL); String returnMessage = null; int returnCode = 500; try { returnCode = httpClient.executeMethod(method); } catch (InvalidCredentialsException exe) { if (log.isInfoEnabled()) log.info("Invalid credentials trying to authenticate: " + exe.getMessage()); } catch (HttpException exe) { log.error("while connection to: " + targetURL.getHost() + " an unknown error occured (HttpException): " + exe.getMessage()); } catch (SSLPeerUnverifiedException exe) { returnCode = 516; returnMessage = exe.getMessage(); } catch (IOException exe) { log.error("while connection to: " + targetURL.getHost() + " using Proxy: " + this.isUsingProxy() + " host: " + this.getHttpProxyHost() + " on Port: " + this.httpProxyPort + " together: " + this.getProxyServer() + " an unknown error occured (IOException): " + targetURL.toExternalForm() + " " + exe.getMessage()); } catch (Exception exe) { log.error("while connection to: " + targetURL.getHost() + " an unknown error occured: " + exe.getMessage()); } if ((returnCode > 199) && (returnCode < 300)) { // return is OK - so fall through if (log.isDebugEnabled()) log.debug("good return code: " + returnCode); } else if (returnCode == 401) { returnMessage = HttpMessages.getString("HttpClientWrapper.401_authRequired"); } else if (returnCode == 404) { returnMessage = HttpMessages.getString("HttpClientWrapper.404_notFound"); } else if (returnCode == 407) { returnMessage = HttpMessages.getString("HttpClientWrapper.407_proxyAuthRequired"); } else if (returnCode == 403) { returnMessage = HttpMessages.getString("HttpClientWrapper.403_Forbidden"); } else if (returnCode == 503) { returnMessage = HttpMessages.getString("HttpClientWrapper.503_ServiceUnavailable"); } else if (returnCode == 504) { returnMessage = HttpMessages.getString("HttpClientWrapper.504_ProxyTimeout"); } else if (returnCode == 516) { returnMessage = HttpMessages.getString("HttpClientWrapper.516_SSLPeerUnverified", returnMessage); } else { returnMessage = "Unknown error with return code " + returnCode; } if (returnMessage != null) { throw new URIException(returnCode, returnMessage); } return method; }
From source file:be.jcdo.mp3searchengines.tools.URIUtils.java
/** * Convert a target string from the fromCharset charset to * the toCharset charset./* ww w. ja v a 2 s . c om*/ * * What if the document charset is ISO-8859-1 and the protocol charset is * UTF-8, when it's read from the document part and is used in the protocol * part, the use of the method will be toUsingCharset(the string, * "ISO-8859-1", "UTF-8"). * * @param target a target string * @param fromCharset the previous charset * @param toCharset the changing charset * @return the document character encoded string * * @throws URIException if either of the charsets are not supported * * @deprecated Do not use. To be removed */ public static String toUsingCharset(String target, String fromCharset, String toCharset) throws URIException { try { return new String(target.getBytes(fromCharset), toCharset); } catch (UnsupportedEncodingException error) { throw new URIException(URIException.UNSUPPORTED_ENCODING, error.getMessage()); } }