List of usage examples for org.apache.commons.httpclient HttpException getMessage
public String getMessage()
From source file:org.apache.jackrabbit.spi2davex.RepositoryServiceImpl.java
/** * @see RepositoryService#getItemInfos(SessionInfo, NodeId) *//*from w w w. j a va2s. c om*/ public Iterator getItemInfos(SessionInfo sessionInfo, NodeId nodeId) throws ItemNotFoundException, RepositoryException { Path path = getPath(nodeId, sessionInfo); String uri = getURI(path, sessionInfo); int depth = batchReadConfig.getDepth(path, this.getNamePathResolver(sessionInfo)); GetMethod method = new GetMethod(uri + "." + depth + ".json"); try { int statusCode = getClient(sessionInfo).executeMethod(method); if (statusCode == DavServletResponse.SC_OK) { if (method.getResponseContentLength() == 0) { // no json response -> no such node on the server throw new ItemNotFoundException("No such node " + nodeId); } NamePathResolver resolver = getNamePathResolver(sessionInfo); NodeInfoImpl nInfo = new NodeInfoImpl(nodeId, path); ItemInfoJsonHandler handler = new ItemInfoJsonHandler(resolver, nInfo, getRootURI(sessionInfo), getQValueFactory(sessionInfo), getPathFactory(), getIdFactory()); JsonParser ps = new JsonParser(handler); ps.parse(method.getResponseBodyAsStream(), method.getResponseCharSet()); Iterator it = handler.getItemInfos(); if (!it.hasNext()) { throw new ItemNotFoundException("No such node " + uri); } return handler.getItemInfos(); } else { throw ExceptionConverter .generate(new DavException(statusCode, "Unable to retrieve NodeInfo for " + uri), method); } } catch (HttpException e) { throw ExceptionConverter .generate(new DavException(method.getStatusCode(), "Unable to retrieve NodeInfo for " + uri)); } catch (IOException e) { log.error("Internal error while retrieving NodeInfo.", e); throw new RepositoryException(e.getMessage()); } finally { method.releaseConnection(); } }
From source file:org.apache.jackrabbit.spi2davex.RepositoryServiceImpl.java
/** * @see RepositoryService#getItemInfos(SessionInfo, ItemId) *///from w w w. j a v a 2 s. c o m @Override public Iterator<? extends ItemInfo> getItemInfos(SessionInfo sessionInfo, ItemId itemId) throws ItemNotFoundException, RepositoryException { if (!itemId.denotesNode()) { PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, (PropertyId) itemId); return Iterators.singleton(propertyInfo); } else { NodeId nodeId = (NodeId) itemId; Path path = getPath(itemId, sessionInfo); String uri = getURI(path, sessionInfo); int depth = batchReadConfig.getDepth(path, this.getNamePathResolver(sessionInfo)); GetMethod method = new GetMethod(uri + "." + depth + ".json"); try { int statusCode = getClient(sessionInfo).executeMethod(method); if (statusCode == DavServletResponse.SC_OK) { if (method.getResponseContentLength() == 0) { // no JSON response -> no such node on the server throw new ItemNotFoundException("No such item " + nodeId); } NamePathResolver resolver = getNamePathResolver(sessionInfo); NodeInfoImpl nInfo = new NodeInfoImpl(nodeId, path); ItemInfoJsonHandler handler = new ItemInfoJsonHandler(resolver, nInfo, getRootURI(sessionInfo), getQValueFactory(sessionInfo), getPathFactory(), getIdFactory()); JsonParser ps = new JsonParser(handler); ps.parse(method.getResponseBodyAsStream(), method.getResponseCharSet()); Iterator<? extends ItemInfo> it = handler.getItemInfos(); if (!it.hasNext()) { throw new ItemNotFoundException("No such node " + uri); } return handler.getItemInfos(); } else { throw ExceptionConverter.generate( new DavException(statusCode, "Unable to retrieve NodeInfo for " + uri), method); } } catch (HttpException e) { throw ExceptionConverter.generate( new DavException(method.getStatusCode(), "Unable to retrieve NodeInfo for " + uri)); } catch (IOException e) { log.error("Internal error while retrieving NodeInfo.", e); throw new RepositoryException(e.getMessage()); } finally { method.releaseConnection(); } } }
From source file:org.apache.maven.plugin.docck.AbstractCheckDocumentationMojo.java
private void checkURL(String url, String description, DocumentationReporter reporter) { try {//w w w . j a va 2 s .c om String protocol = getURLProtocol(url); if (protocol.startsWith("http")) { if (offline) { reporter.warn("Cannot verify " + description + " in offline mode with URL: \'" + url + "\'."); } else if (!validUrls.contains(url)) { HeadMethod headMethod = new HeadMethod(url); headMethod.setFollowRedirects(true); headMethod.setDoAuthentication(false); try { getLog().debug("Verifying http url: " + url); if (httpClient.executeMethod(headMethod) != HTTP_STATUS_200) { reporter.error("Cannot reach " + description + " with URL: \'" + url + "\'."); } else { validUrls.add(url); } } catch (HttpException e) { reporter.error("Cannot reach " + description + " with URL: \'" + url + "\'.\nError: " + e.getMessage()); } catch (IOException e) { reporter.error("Cannot reach " + description + " with URL: \'" + url + "\'.\nError: " + e.getMessage()); } finally { headMethod.releaseConnection(); } } } else { reporter.warn("Non-HTTP " + description + " URL not verified."); } } catch (MalformedURLException e) { reporter.warn("The " + description + " appears to have an invalid URL \'" + url + "\'." + " Message: \'" + e.getMessage() + "\'. Trying to access it as a file instead."); checkFile(url, description, reporter); } }
From source file:org.apache.oodt.security.sso.opensso.SSOProxy.java
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);/*from w w w.j a v a 2s. c o m*/ 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(); } }
From source file:org.apache.sling.maven.bundlesupport.AbstractBundleInstallMojo.java
protected void removeConfiguration(final HttpClient client, final String targetURL, String pid) throws MojoExecutionException { final String postUrl = targetURL + "/configMgr/" + pid; final PostMethod post = new PostMethod(postUrl); post.addParameter("apply", "true"); post.addParameter("delete", "true"); try {/* w w w .jav a2 s. c o m*/ final int status = client.executeMethod(post); // we get a moved temporarily back from the configMgr plugin if (status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_OK) { getLog().debug("Configuration removed."); } else { getLog().error("Removing configuration failed, cause: " + HttpStatus.getStatusText(status)); } } catch (HttpException ex) { throw new MojoExecutionException( "Removing configuration at " + postUrl + " failed, cause: " + ex.getMessage(), ex); } catch (IOException ex) { throw new MojoExecutionException( "Removing configuration at " + postUrl + " failed, cause: " + ex.getMessage(), ex); } finally { post.releaseConnection(); } }
From source file:org.apache.sling.maven.bundlesupport.AbstractBundleInstallMojo.java
/** * Add a new configuration for the file system provider * @throws MojoExecutionException//from w w w .j a v a 2s .c om */ protected void addConfiguration(final HttpClient client, final String targetURL, String dir, String path) throws MojoExecutionException { final String postUrl = targetURL + "/configMgr/" + FS_FACTORY; final PostMethod post = new PostMethod(postUrl); post.addParameter("apply", "true"); post.addParameter("factoryPid", FS_FACTORY); post.addParameter("pid", "[Temporary PID replaced by real PID upon save]"); post.addParameter("provider.file", dir); post.addParameter("provider.roots", path); post.addParameter("propertylist", "provider.roots,provider.file"); try { final int status = client.executeMethod(post); // we get a moved temporarily back from the configMgr plugin if (status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_OK) { getLog().info("Configuration created."); } else { getLog().error("Configuration failed, cause: " + HttpStatus.getStatusText(status)); } } catch (HttpException ex) { throw new MojoExecutionException("Configuration on " + postUrl + " failed, cause: " + ex.getMessage(), ex); } catch (IOException ex) { throw new MojoExecutionException("Configuration on " + postUrl + " failed, cause: " + ex.getMessage(), ex); } finally { post.releaseConnection(); } }
From source file:org.apache.sling.maven.bundlesupport.AbstractBundleInstallMojo.java
/** * Try to get the version of the web console * @return The version or <code>null</code> if version is not detectable. *///from w w w . j a v a 2s . c o m protected String checkWebConsoleVersion(final String targetUrl) { getLog().debug("Checking web console version...."); final String bundleUrl = targetUrl + "/bundles/org.apache.felix.webconsole.json"; final HttpClient client = getHttpClient(); final GetMethod gm = new GetMethod(bundleUrl); // if something goes wrong, we assume an older version!! try { final int status = client.executeMethod(gm); if (status == 200) { if (gm.getResponseContentLength() == 0) { getLog().debug("Response has zero length. Assuming older version of web console."); return null; } final String jsonText = gm.getResponseBodyAsString(); try { final JSONObject obj = new JSONObject(jsonText); final JSONArray props = obj.getJSONArray("props"); for (int i = 0; i < props.length(); i++) { final JSONObject property = props.getJSONObject(i); if ("Version".equals(property.get("key"))) { final String version = property.getString("value"); getLog().debug("Found web console version " + version); return version; } } getLog().debug("Version property not found in response. Assuming older version."); return null; } catch (JSONException ex) { getLog().debug( "Converting response to JSON failed. Assuming older version: " + ex.getMessage()); return null; } } getLog().debug("Status code from web console: " + status); } catch (HttpException e) { getLog().debug("HttpException: " + e.getMessage()); } catch (IOException e) { getLog().debug("IOException: " + e.getMessage()); } getLog().debug("Unknown version."); return null; }
From source file:org.apache.webdav.cmd.Client.java
void options(String path) { out.println("options " + path); String param = path;/*from w w w .j a v a2 s.c o m*/ try { boolean succeeded = false; if (param != null) { if (!param.startsWith("/")) { httpURL = uriToHttpURL(param); Enumeration opts = null; try { // OPTIONS business logic opts = webdavResource.optionsMethod(httpURL); while (opts.hasMoreElements()) { out.print(opts.nextElement()); if (opts.hasMoreElements()) { out.print(", "); } else { out.println(); } } } catch (HttpException we) { if (we.getReasonCode() == HttpStatus.SC_UNAUTHORIZED) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); out.print("UserName: "); String userName = in.readLine(); if (userName != null && userName.length() > 0) { userName = userName.trim(); out.print("Password: "); String password = in.readLine(); if (password != null) password = password.trim(); try { // OPTIONS business logic httpURL.setUserinfo(userName, password); opts = webdavResource.optionsMethod(httpURL); while (opts.hasMoreElements()) { out.print(opts.nextElement()); if (opts.hasMoreElements()) { out.print(", "); } else { out.println(); } } } catch (Exception e) { out.println("Error: " + e.getMessage()); } } } else { out.println("Error: " + we.getMessage()); } } catch (IOException e) { out.println("Error: Check! " + e.getMessage()); } httpURL = null; return; } else if (webdavResource != null) { succeeded = webdavResource.optionsMethod(param); } else { out.println("Not connected yet."); } } else if (webdavResource != null) { succeeded = webdavResource.optionsMethod("*"); } else { out.println("Not connected yet."); } if (succeeded) { out.print("Allowed methods by http OPTIONS: "); Enumeration allowed = webdavResource.getAllowedMethods(); while (allowed.hasMoreElements()) { out.print(allowed.nextElement()); if (allowed.hasMoreElements()) out.print(", "); } Enumeration davCapabilities = webdavResource.getDavCapabilities(); if (davCapabilities.hasMoreElements()) out.print("\nDAV: "); while (davCapabilities.hasMoreElements()) { out.print(davCapabilities.nextElement()); if (davCapabilities.hasMoreElements()) out.print(", "); } out.println(); } } catch (Exception ex) { handleException(ex); } }
From source file:org.bibsonomy.recommender.tags.WebserviceTagRecommender.java
private InputStreamReader sendRequest(final PostMethod cnct) { InputStreamReader input = null; // byte[] responseBody = null; try {//from w ww.j a va 2s.c om // Execute the method. final int statusCode = client.executeMethod(cnct); if (statusCode != HttpStatus.SC_OK) { log.error("Method at " + getAddress().toString() + " failed: " + cnct.getStatusLine()); } else { // Read the response body. // responseBody = cnct.getResponseBody(); input = new InputStreamReader(cnct.getResponseBodyAsStream(), "UTF-8"); } } catch (final HttpException e) { log.fatal("Fatal protocol violation(" + getAddress() + "): " + e.getMessage(), e); } catch (final UnsupportedEncodingException ex) { // returns InputStream with default encoding if a exception // is thrown with utf-8 support log.fatal("Encoding error(" + getAddress() + "): " + ex.getMessage(), ex); } catch (final IOException e) { log.fatal("Fatal transport error(" + getAddress() + "): " + e.getMessage(), e); } catch (final Exception e) { log.fatal("Unknown error (" + getAddress() + ")", e); } finally { // Release the connection. // cnct.releaseConnection(); } // all done. // log.debug("Got response: " + new String(responseBody)); return input; }
From source file:org.bonitasoft.console.common.application.ApplicationURLUtils.java
/** * Check if the dedicated application URL is reachable * //from w w w. j a v a2 s . c om * @param anUrlToTest the URL to check * @return true if the URL is reacheable, false otherwise */ private boolean checkURLConnection(final URL anUrlToTest) { final HttpClient client = new HttpClient(); // Create a method instance. final GetMethod method = new GetMethod(anUrlToTest.toString()); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); boolean urlReachable = false; try { // Execute the method. final int statusCode = client.executeMethod(method); urlReachable = (statusCode == HttpStatus.SC_OK); } catch (final HttpException e) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("Fatal protocol violation: " + e.getMessage()); } } catch (final IOException e) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("Fatal transport error: " + e.getMessage()); } } finally { // Release the connection. method.releaseConnection(); } return urlReachable; }