List of usage examples for java.net URL getPath
public String getPath()
From source file:com.db.comserv.main.utilities.HttpCaller.java
private static void logExtAccess(final String type, final URL url, final String method, final int responseStatus, final int responseBytes, final long takenMs) { LogUtil.logExtAccess(url.getHost(), type, method, responseStatus, responseBytes, takenMs, ServletUtil.filterUrl(url.getPath() + (url.getQuery() == null ? "" : "?" + url.getQuery()))); }
From source file:com.wordnik.swagger.codegen.util.FileUtil.java
public static void copyDirectoryFromUrl(final URL originUrl, final File destination) { try {// w ww .ja v a 2s .c o m final URLConnection urlConnection = originUrl.openConnection(); if (urlConnection instanceof JarURLConnection) { FileUtil.copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection); } else { FileUtil.copyDirectory(new File(originUrl.getPath()), destination); } } catch (final IOException e) { e.printStackTrace(); } }
From source file:co.cask.cdap.security.server.ExternalAuthenticationServerTestBase.java
/** * LDAP server and related handler configurations. *//*from w w w.ja v a2 s .c o m*/ private static CConfiguration getConfiguration(CConfiguration cConf) { String configBase = Constants.Security.AUTH_HANDLER_CONFIG_BASE; // Use random port for testing cConf.setInt(Constants.Security.AUTH_SERVER_BIND_PORT, Networks.getRandomPort()); cConf.setInt(Constants.Security.AuthenticationServer.SSL_PORT, Networks.getRandomPort()); cConf.set(Constants.Security.AUTH_HANDLER_CLASS, LDAPAuthenticationHandler.class.getName()); cConf.set(Constants.Security.LOGIN_MODULE_CLASS_NAME, LDAPLoginModule.class.getName()); cConf.set(configBase.concat("debug"), "true"); cConf.set(configBase.concat("hostname"), "localhost"); cConf.set(configBase.concat("port"), Integer.toString(ldapPort)); cConf.set(configBase.concat("userBaseDn"), "dc=example,dc=com"); cConf.set(configBase.concat("userRdnAttribute"), "cn"); cConf.set(configBase.concat("userObjectClass"), "inetorgperson"); URL keytabUrl = ExternalAuthenticationServerTestBase.class.getClassLoader().getResource("test.keytab"); Assert.assertNotNull(keytabUrl); cConf.set(Constants.Security.CFG_CDAP_MASTER_KRB_KEYTAB_PATH, keytabUrl.getPath()); cConf.set(Constants.Security.CFG_CDAP_MASTER_KRB_PRINCIPAL, "test_principal"); return cConf; }
From source file:com.xebialabs.xlt.ci.server.XLTestServerImpl.java
public static URL createSensibleURL(String relativeUrl, URL serverUrl) throws MalformedURLException, URISyntaxException { // normalize URL parts: // spec should not end with "/" // relative URL should start with "/" String spec = removeTrailingSlashes(serverUrl.getPath()); if (!relativeUrl.startsWith("/")) { relativeUrl = "/" + relativeUrl; }/* w w w . j a v a 2 s . co m*/ return new URL(serverUrl, spec + relativeUrl); }
From source file:com.ms.commons.test.classloader.util.AntxconfigUtil.java
@SuppressWarnings("unchecked") private static void autoconf(File tmp, String autoconfigPath, String autoconfigFile, PrintStream out) throws Exception { Enumeration<URL> urls = AntxconfigUtil.class.getClassLoader().getResources(autoconfigFile); for (; urls.hasMoreElements();) { URL url = urls.nextElement(); // copy xml File autoconfFile = new File(tmp, autoconfigFile); writeUrlToFile(url, autoconfFile); // copy vm SAXBuilder b = new SAXBuilder(); Document document = b.build(autoconfFile); List<Element> elements = XPath.selectNodes(document, GEN_PATH); for (Element element : elements) { String path = url.getPath(); String vm = element.getAttributeValue("template"); String vmPath = StringUtils.substringBeforeLast(path, "/") + "/" + vm; URL vmUrl = new URL(url.getProtocol(), url.getHost(), vmPath); File vmFile = new File(tmp, autoconfigPath + "/" + vm); writeUrlToFile(vmUrl, vmFile); }//from ww w. j av a 2s . com // call antxconfig String args = ""; if (new File(DEFAULT_ANTX_FILE).isFile()) { args = " -u " + DEFAULT_ANTX_FILE; } Process p = Runtime.getRuntime().exec(ANTXCONFIG_CMD + args, null, tmp); BufferedInputStream in = new BufferedInputStream(p.getInputStream()); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String s; while ((s = br.readLine()) != null) { out.println(new String(s.getBytes(), ENDODING)); } FileUtils.deleteDirectory(new File(tmp, autoconfigPath)); } }
From source file:com.celamanzi.liferay.portlets.rails286.OnlineUtils.java
/** * @author Reinaldo Silva //w w w .j av a2 s .c o m */ protected static Cookie[] getRequestCookies(RenderRequest request, java.net.URL url) { javax.servlet.http.Cookie[] sr_cookies; org.apache.commons.httpclient.Cookie[] cookies; sr_cookies = request.getCookies(); cookies = new org.apache.commons.httpclient.Cookie[sr_cookies.length]; log.debug("Servlet request cookies -------v"); for (int i = 0; i < sr_cookies.length; i++) { cookies[i] = new org.apache.commons.httpclient.Cookie(url.getHost(), sr_cookies[i].getName(), sr_cookies[i].getValue(), url.getPath(), sr_cookies[i].getMaxAge(), sr_cookies[i].getSecure()); log.debug("Servlet-Cookie: " + cookies[i].toString() + ", original-domain=" + sr_cookies[i].getDomain() + ", domain=" + url.getHost() + ", original-path=" + sr_cookies[i].getPath() + ", path=" + cookies[i].getPath() + ", max-age=" + cookies[i].getExpiryDate() + ", secure=" + cookies[i].getSecure()); } return cookies; }
From source file:cn.org.rapid_framework.generator.util.ResourceHelper.java
/** * Determine whether the given URL points to a resource in a jar file, * that is, has protocol "jar", "zip", "wsjar" or "code-source". * <p>"zip" and "wsjar" are used by BEA WebLogic Server and IBM WebSphere, respectively, * but can be treated like jar files. The same applies to "code-source" URLs on Oracle * OC4J, provided that the path contains a jar separator. * @param url the URL to check/*from w ww . j a va 2s.c om*/ * @return whether the URL has been identified as a JAR URL */ public static boolean isJarURL(URL url) { String protocol = url.getProtocol(); return (URL_PROTOCOL_JAR.equals(protocol) || URL_PROTOCOL_ZIP.equals(protocol) || URL_PROTOCOL_WSJAR.equals(protocol) || (URL_PROTOCOL_CODE_SOURCE.equals(protocol) && url.getPath().contains(JAR_URL_SEPARATOR))); }
From source file:org.silvertunnel.netlib.adapter.httpclient.HttpClientUtil.java
public static byte[] simpleBytesAction(URL url) throws IOException { int port = (url.getPort() < 0) ? 80 : url.getPort(); TcpipNetAddress httpServerNetAddress = new TcpipNetAddress(url.getHost(), port); Map<String, Object> localProperties = new HashMap<String, Object>(); NetSocket lowerLayerNetSocket = lowerNetLayer.createNetSocket(localProperties, /*localAddress*/ null, httpServerNetAddress);/*from w w w. j a v a 2 s .c om*/ String pathOnHttpServer = url.getPath(); if (pathOnHttpServer == null || pathOnHttpServer.length() < 1) { pathOnHttpServer = "/"; } long timeoutInMs = 10L * 1000L; return HttpUtil.getInstance().get(lowerLayerNetSocket, httpServerNetAddress, pathOnHttpServer, timeoutInMs); }
From source file:org.silvertunnel.netlib.adapter.httpclient.HttpClientUtil.java
public static InputStream simpleAction(URL url) throws IOException { int port = (url.getPort() < 0) ? 80 : url.getPort(); TcpipNetAddress httpServerNetAddress = new TcpipNetAddress(url.getHost(), port); Map<String, Object> localProperties = new HashMap<String, Object>(); NetSocket lowerLayerNetSocket = lowerNetLayer.createNetSocket(localProperties, /*localAddress*/ null, httpServerNetAddress);/*from w w w . j a v a2 s. c o m*/ String pathOnHttpServer = url.getPath(); if (pathOnHttpServer == null || pathOnHttpServer.length() < 1) { pathOnHttpServer = "/"; } long timeoutInMs = 10L * 1000L; return HttpUtil.getInstance().getReponseBodyInputStream(lowerLayerNetSocket, httpServerNetAddress, pathOnHttpServer, timeoutInMs); }
From source file:edu.uci.ics.crawler4j.url.URLCanonicalizer.java
public static String getCanonicalURL(String href, String context) { try {/*w w w . j a va2 s.c o m*/ URL canonicalURL = new URL(UrlResolver.resolveUrl(context == null ? "" : context, href)); String host = canonicalURL.getHost().toLowerCase(); if (StringUtils.isBlank(host)) { // This is an invalid Url. return null; } String path = canonicalURL.getPath(); /* * Normalize: no empty segments (i.e., "//"), no segments equal to * ".", and no segments equal to ".." that are preceded by a segment * not equal to "..". */ path = new URI(path).normalize().toString(); /* * Convert '//' -> '/' */ int idx = path.indexOf("//"); while (idx >= 0) { path = path.replace("//", "/"); idx = path.indexOf("//"); } /* * Drop starting '/../' */ while (path.startsWith("/../")) { path = path.substring(3); } /* * Trim */ path = path.trim(); final SortedMap<String, String> params = createParameterMap(canonicalURL.getQuery()); final String queryString; if (params != null && params.size() > 0) { String canonicalParams = canonicalize(params); queryString = (canonicalParams.isEmpty() ? "" : "?" + canonicalParams); } else { queryString = ""; } /* * Add starting slash if needed */ if (path.length() == 0) { path = "/" + path; } /* * Drop default port: example.com:80 -> example.com */ int port = canonicalURL.getPort(); if (port == canonicalURL.getDefaultPort()) { port = -1; } String protocol = canonicalURL.getProtocol().toLowerCase(); String pathAndQueryString = normalizePath(path) + queryString; URL result = new URL(protocol, host, port, pathAndQueryString); return result.toExternalForm(); } catch (MalformedURLException ex) { return null; } catch (URISyntaxException ex) { return null; } }