List of usage examples for org.apache.commons.httpclient URI getPath
public String getPath() throws URIException
From source file:com.serena.rlc.provider.artifactory.domain.Artifact.java
public static Artifact parseSingle(JSONObject jsonObject) { Artifact aObj = null;/*from w w w. jav a2s. c om*/ if (jsonObject != null) { aObj = new Artifact((String) getJSONValue(jsonObject, "uri"), (String) jsonObject.get("path"), (String) jsonObject.get("downloadUri")); aObj.setRepo((String) jsonObject.get("repo")); aObj.setCreated((String) jsonObject.get("created")); aObj.setCreatedBy((String) jsonObject.get("createdBy")); aObj.setLastModified((String) jsonObject.get("lastModified")); aObj.setModifiedBy((String) jsonObject.get("modifiedBy")); aObj.setLastUpdated((String) jsonObject.get("lastUpdated")); aObj.setMimeType((String) jsonObject.get("mimeType")); aObj.setSize((String) jsonObject.get("size")); try { URI uri = new URI((String) getJSONValue(jsonObject, "uri")); aObj.setName(uri.getName()); String[] segments = uri.getPath().split("/"); aObj.setVersion(segments[segments.length - 2]); } catch (URIException ex) { logger.error("Error while parsing input JSON - " + (String) getJSONValue(jsonObject, "uri"), ex); } } return aObj; }
From source file:fr.cls.atoll.motu.library.cas.HttpClientCAS.java
/** * Adds the cas ticket.//from ww w . j a v a2 s. c om * * @param method * the method * @throws IOException * Signals that an I/O exception has occurred. * @throws MotuCasException */ public static void addCASTicket(HttpMethod method) throws IOException, MotuCasException { if (LOG.isDebugEnabled()) { LOG.debug("addCASTicket(HttpMethod) - entering : debugHttpMethod BEFORE " + HttpClientCAS.debugHttpMethod(method)); } if (HttpClientCAS.addCASTicketFromTGT(method)) { return; } if (!AuthenticationHolder.isCASAuthentication()) { if (LOG.isDebugEnabled()) { LOG.debug("addCASTicket(HttpMethod) - exiting - NO CAS AUTHENTICATION : debugHttpMethod AFTER " + HttpClientCAS.debugHttpMethod(method)); } return; } String newURIAsString = AssertionUtils.addCASTicket(method.getURI().getEscapedURI()); if (!AssertionUtils.hasCASTicket(newURIAsString)) { newURIAsString = AssertionUtils.addCASTicket(method.getURI().getEscapedURI(), AuthenticationHolder.getUser()); if (!AssertionUtils.hasCASTicket(newURIAsString)) { String login = AuthenticationHolder.getUserLogin(); throw new MotuCasException(String.format( "Unable to access resource '%s'. This resource has been declared as CASified, but the Motu application/API can't retrieve any ticket from CAS via REST. \nFor information, current user login is:'%s'", method.getURI().getEscapedURI(), login)); } } URI newURI = new URI(newURIAsString, true); // method.setURI(newURI); method.setPath(newURI.getPath()); method.setQueryString(newURI.getQuery()); // System.out.println(newURI.getPathQuery()); if (LOG.isDebugEnabled()) { LOG.debug("addCASTicket(HttpMethod) - exiting : debugHttpMethod AFTER " + HttpClientCAS.debugHttpMethod(method)); } }
From source file:fr.cls.atoll.motu.library.cas.HttpClientCAS.java
/** * Adds the cas ticket from tgt.//from w w w.jav a2 s.c o m * * @param method the method * @return true, if successful * @throws MotuCasException the motu cas exception * @throws URIException the uRI exception * @throws IOException Signals that an I/O exception has occurred. */ public static boolean addCASTicketFromTGT(HttpMethod method) throws MotuCasException, URIException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("addCASTicketFromTGT(HttpMethod) - entering : debugHttpMethod BEFORE " + HttpClientCAS.debugHttpMethod(method)); } Header headerTgt = method.getRequestHeader(HttpClientCAS.TGT_PARAM); Header headerCasRestUrl = method.getRequestHeader(HttpClientCAS.CAS_REST_URL_PARAM); if ((headerTgt == null) || (headerCasRestUrl == null)) { return false; } String ticketGrantingTicket = headerTgt.getValue(); String casRestUrl = headerCasRestUrl.getValue(); if ((RestUtil.isNullOrEmpty(ticketGrantingTicket)) || (RestUtil.isNullOrEmpty(casRestUrl))) { return false; } String ticket = RestUtil.loginToCASWithTGT(casRestUrl, ticketGrantingTicket, method.getURI().getEscapedURI()); String newURIAsString = AssertionUtils.addCASTicket(ticket, method.getURI().getEscapedURI()); if (!AssertionUtils.hasCASTicket(newURIAsString)) { throw new MotuCasException(String.format( "Unable to access resource '%s'. This resource has been declared as CASified, but the Motu application/API can't retrieve any ticket from CAS via REST. \nFor information, current TGT is:'%s', CAS REST url is:'%s'", method.getURI().getEscapedURI(), ticketGrantingTicket, casRestUrl)); } URI newURI = new URI(newURIAsString, true); // method.setURI(newURI); method.setPath(newURI.getPath()); method.setQueryString(newURI.getQuery()); // System.out.println(newURI.getPathQuery()); if (LOG.isDebugEnabled()) { LOG.debug("addCASTicketFromTGT(HttpMethod) - exiting : debugHttpMethod AFTER " + HttpClientCAS.debugHttpMethod(method)); } return true; }
From source file:com.eviware.soapui.impl.wsdl.submit.filters.EndpointRequestFilter.java
@Override public void filterAbstractHttpRequest(SubmitContext context, AbstractHttpRequest<?> request) { HttpRequestBase httpMethod = (HttpRequestBase) context.getProperty(BaseHttpRequestTransport.HTTP_METHOD); String strURL = request.getEndpoint(); strURL = PropertyExpander.expandProperties(context, strURL); try {/*from ww w . java 2 s . c o m*/ if (StringUtils.hasContent(strURL)) { URI uri = new URI(strURL, request.getSettings().getBoolean(HttpSettings.ENCODED_URLS)); context.setProperty(BaseHttpRequestTransport.REQUEST_URI, uri); httpMethod.setURI(new java.net.URI(uri.getScheme(), uri.getUserinfo(), uri.getHost(), uri.getPort(), (uri.getPath()) == null ? "/" : uri.getPath(), uri.getQuery(), uri.getFragment())); } } catch (Exception e) { SoapUI.logError(e); } }
From source file:com.silverpeas.openoffice.windows.webdav.WebdavManager.java
/** * Get the ressource from the webdav server. * * @param uri the uri to the ressource./* w w w .j ava2 s . co m*/ * @param lockToken the current lock token. * @return the path to the saved file on the filesystem. * @throws IOException */ public String getFile(URI uri, String lockToken) throws IOException { GetMethod method = executeGetFile(uri); String fileName = uri.getPath(); fileName = fileName.substring(fileName.lastIndexOf('/') + 1); fileName = URLDecoder.decode(fileName, "UTF-8"); UIManager.put("ProgressMonitor.progressText", MessageUtil.getMessage("download.file.title")); ProgressMonitorInputStream is = new ProgressMonitorInputStream(null, MessageUtil.getMessage("downloading.remote.file") + ' ' + fileName, new BufferedInputStream(method.getResponseBodyAsStream())); fileName = fileName.replace(' ', '_'); ProgressMonitor monitor = is.getProgressMonitor(); monitor.setMaximum(new Long(method.getResponseContentLength()).intValue()); monitor.setMillisToDecideToPopup(0); monitor.setMillisToPopup(0); File tempDir = new File(System.getProperty("java.io.tmpdir"), "silver-" + System.currentTimeMillis()); tempDir.mkdirs(); File tmpFile = new File(tempDir, fileName); FileOutputStream fos = new FileOutputStream(tmpFile); byte[] data = new byte[64]; int c = 0; try { while ((c = is.read(data)) > -1) { fos.write(data, 0, c); } } catch (InterruptedIOException ioinex) { logger.log(Level.INFO, "{0} {1}", new Object[] { MessageUtil.getMessage("info.user.cancel"), ioinex.getMessage() }); unlockFile(uri, lockToken); System.exit(0); } finally { fos.close(); } return tmpFile.getAbsolutePath(); }
From source file:edu.ucsb.eucalyptus.cloud.ws.Storage.java
private static void checkWalrusConnection() { HttpClient httpClient = new HttpClient(); GetMethod getMethod = null;/*from w w w . j a v a 2 s . com*/ try { java.net.URI addrUri = new URL(StorageProperties.WALRUS_URL).toURI(); String addrPath = addrUri.getPath(); String addr = StorageProperties.WALRUS_URL.replaceAll(addrPath, ""); getMethod = new GetMethod(addr); httpClient.executeMethod(getMethod); enableSnapshots = true; } catch (Exception ex) { LOG.error("Could not connect to Walrus. Snapshot functionality disabled. Please check the Walrus url."); enableSnapshots = false; } finally { if (getMethod != null) getMethod.releaseConnection(); } }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.java
private ExtendedGetMethod followRedirects(HttpClient httpClient, int redirectCount, ExtendedHttpMethod httpMethod, org.apache.http.HttpResponse httpResponse, HttpContext httpContext) throws Exception { ExtendedGetMethod getMethod = new ExtendedGetMethod(); getMethod.getMetrics().getTotalTimer().set(httpMethod.getMetrics().getTotalTimer().getStart(), httpMethod.getMetrics().getTotalTimer().getStop()); getMethod.getMetrics().setHttpMethod(httpMethod.getMethod()); captureMetrics(httpMethod, httpClient); String location = httpResponse.getFirstHeader("Location").getValue(); URI uri = new URI(new URI(httpMethod.getURI().toString(), true), location, true); java.net.URI newUri = new java.net.URI(uri.getScheme(), uri.getUserinfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); getMethod.setURI(newUri);// w w w . ja va 2s . c om org.apache.http.HttpResponse response = HttpClientSupport.execute(getMethod, httpContext); if (isRedirectResponse(response.getStatusLine().getStatusCode())) { if (redirectCount == 10) throw new Exception("Maximum number of Redirects reached [10]"); try { getMethod = followRedirects(httpClient, redirectCount + 1, getMethod, response, httpContext); } finally { //getMethod.releaseConnection(); } } for (Header header : httpMethod.getAllHeaders()) getMethod.addHeader(header); return getMethod; }
From source file:de.innovationgate.utils.URLBuilder.java
/** * Creates a URLBuilder that parses an existing URI * @param uri The URI to parse//from w w w.ja v a2 s.c om */ public URLBuilder(URI uri) throws URIException { this(uri.getScheme(), uri.getPort(), uri.getHost(), uri.getPath(), uri.getQuery(), uri.getFragment(), "UTF-8"); }
From source file:com.jivesoftware.os.jive.utils.http.client.ApacheHttpClient31BackedHttpClient.java
private void signWithOAuth(HttpMethod method) throws IOException { try {//from w ww. j a v a 2 s .c o m HostConfiguration hostConfiguration = client.getHostConfiguration(); URI uri = method.getURI(); URI newUri = new URI((isSSLEnabled) ? "https" : "http", uri.getUserinfo(), hostConfiguration.getHost(), hostConfiguration.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); method.setURI(newUri); //URI checkUri = method.getURI(); //String checkUriString = checkUri.toString(); CommonsHttp3OAuthConsumer oAuthConsumer = new CommonsHttp3OAuthConsumer(consumerKey, consumerSecret); oAuthConsumer.setTokenWithSecret(consumerKey, consumerSecret); oAuthConsumer.sign(method); } catch (Exception e) { throw new IOException("Failed to OAuth sign HTTPRequest", e); } }
From source file:de.innovationgate.utils.URLBuilder.java
/** * Creates a URLBuilder that parses an existing URI * @param uri The URI to parse//www.j a va 2 s.c o m * @param encoding The encoding of URL parameters. The URLBuilder will decode them. */ public URLBuilder(URI uri, String encoding) throws URIException { this(uri.getScheme(), uri.getPort(), uri.getHost(), uri.getPath(), uri.getQuery(), uri.getFragment(), encoding); }