List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:org.eclipse.wst.json.core.internal.download.HttpClientProvider.java
public static File getFile(URL url) throws IOException { if (url == null) { return null; }//from w w w . j a va 2 s . c o m if (PROTOCOL_FILE.equals(url.getProtocol()) || PROTOCOL_PLATFORM.equalsIgnoreCase(url.getProtocol())) { File file; try { file = new File(new URI(url.toExternalForm())); } catch (Exception e) { file = new File(url.getFile()); } if (!file.exists()) { return null; } return file; } File file = getCachedFile(url); long urlLastModified = getLastModified(url); if (file.exists()) { long lastModified = file.lastModified(); if (urlLastModified > lastModified) { file = download(file, url); if (file != null) { file.setLastModified(urlLastModified); } } } else { file = download(file, url); if (file != null && urlLastModified > -1) { file.setLastModified(urlLastModified); } } return file; }
From source file:com.jetbrains.pluginUtils.xml.JDOMXIncluder.java
@NotNull private static List<Content> parseRemote(final Stack<String> bases, final URL remote, @Nullable Element fallbackElement) { try {/*from www .j a v a 2 s .c om*/ Document doc = JDOMUtil.loadResourceDocument(remote); bases.push(remote.toExternalForm()); Element root = doc.getRootElement(); final List<Content> list = resolve(root, bases); bases.pop(); return list; } catch (JDOMException e) { throw new XIncludeException(e); } catch (IOException e) { if (fallbackElement != null) { // TODO[yole] return contents of fallback element (we don't have fallback elements with content ATM) return Collections.emptyList(); } throw new XIncludeException(e); } }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
public static HTTPResponse get(URL url, String username, String password, long timeout, int maxRedirect, String charset, String useragent, ProxyData proxy, Header[] headers) throws IOException { return _invoke(new GetMethod(url.toExternalForm()), url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers, null, null); }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
public static HTTPResponse head(URL url, String username, String password, int timeout, int maxRedirect, String charset, String useragent, ProxyData proxy, Header[] headers) throws IOException { return _invoke(new HeadMethod(url.toExternalForm()), url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers, null, null); }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
public static HTTPResponse delete(URL url, String username, String password, int timeout, int maxRedirect, String charset, String useragent, ProxyData proxy, Header[] headers) throws IOException { return _invoke(new DeleteMethod(url.toExternalForm()), url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers, null, null); }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
public static HTTPResponse put(URL url, String username, String password, int timeout, int maxRedirect, String charset, String useragent, ProxyData proxy, Header[] headers, Object body) throws IOException { return _invoke(new PutMethod(url.toExternalForm()), url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers, null, body); }
From source file:io.fabric8.apiman.gateway.ApimanGatewayStarter.java
private static URL waitForDependency(URL url, String serviceName, String key, String value, String username, String password) throws InterruptedException { boolean isFoundRunningService = false; ObjectMapper mapper = new ObjectMapper(); int counter = 0; URL endpoint = null; while (!isFoundRunningService) { endpoint = resolveServiceEndpoint(url.getProtocol(), url.getHost(), String.valueOf(url.getPort())); if (endpoint != null) { String isLive = null; try { URL statusURL = new URL(endpoint.toExternalForm() + url.getPath()); HttpURLConnection urlConnection = (HttpURLConnection) statusURL.openConnection(); urlConnection.setConnectTimeout(500); if (urlConnection instanceof HttpsURLConnection) { try { KeyStoreUtil.Info tPathInfo = new KeyStoreUtil().new Info(TRUSTSTORE_PATH, TRUSTSTORE_PASSWORD_PATH); TrustManager[] tms = KeyStoreUtil.getTrustManagers(tPathInfo); KeyStoreUtil.Info kPathInfo = new KeyStoreUtil().new Info(CLIENT_KEYSTORE_PATH, CLIENT_KEYSTORE_PASSWORD_PATH); KeyManager[] kms = KeyStoreUtil.getKeyManagers(kPathInfo); final SSLContext sc = SSLContext.getInstance("TLS"); sc.init(kms, tms, new java.security.SecureRandom()); final SSLSocketFactory socketFactory = sc.getSocketFactory(); HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory); HttpsURLConnection httpsConnection = (HttpsURLConnection) urlConnection; httpsConnection.setHostnameVerifier(new DefaultHostnameVerifier()); httpsConnection.setSSLSocketFactory(socketFactory); } catch (Exception e) { log.error(e.getMessage(), e); throw e; }/*from ww w . j av a 2s. c om*/ } if (Utils.isNotNullOrEmpty(username)) { String encoded = Base64.getEncoder() .encodeToString((username + ":" + password).getBytes("UTF-8")); log.info(username + ":******"); urlConnection.setRequestProperty("Authorization", "Basic " + encoded); } isLive = IOUtils.toString(urlConnection.getInputStream()); Map<String, Object> esResponse = mapper.readValue(isLive, new TypeReference<Map<String, Object>>() { }); if (esResponse.containsKey(key) && value.equals(String.valueOf(esResponse.get(key)))) { isFoundRunningService = true; } else { if (counter % 10 == 0) log.info(endpoint.toExternalForm() + " not yet up (host=" + endpoint.getHost() + ")" + isLive); } } catch (Exception e) { if (counter % 10 == 0) log.info(endpoint.toExternalForm() + " not yet up. (host=" + endpoint.getHost() + ")" + e.getMessage()); } } else { if (counter % 10 == 0) log.info("Could not find " + serviceName + " in namespace, waiting.."); } counter++; Thread.sleep(1000l); } return endpoint; }
From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java
public static HTTPResponse post(URL url, String username, String password, long timeout, int maxRedirect, String charset, String useragent, ProxyData proxy, Header[] headers, Map<String, String> params) throws IOException { return _invoke(new PostMethod(url.toExternalForm()), url, username, password, timeout, maxRedirect, charset, useragent, proxy, headers, params, null); }
From source file:com.autentia.tnt.util.JPivotUtils.java
/** * Ejecuta una query MDX sobre un cubo OLAP utilizando el datasource por defecto. <br> * El resultado lo almacena en el contexto de sesin para que pueda ser recogido y pintado por las etiquetas de JPivot. * /*from ww w . j av a 2 s. c o m*/ * @param mdxQuery query a ejecutar * @param cubeSchema URL del que representa el cubo OLAP * @return * @throws SAXException * @throws IOException * @throws OlapException */ public static OlapModel executeOlapQuery(String mdxQuery, URL schema, HttpSession session) throws SAXException, IOException, OlapException { final RequestContext context = RequestContext.instance(); // final URL schema = JpivotUtils.class.getResource(cubeSchema);//new URL("file:///"+cubeSchema);// final MondrianModelFactory.Config cfg = new MondrianModelFactory.Config(); cfg.setMdxQuery(mdxQuery); cfg.setSchemaUrl(schema.toExternalForm()); cfg.setDataSource(DATA_SOURCE); final MondrianModel mondrianModel = MondrianModelFactory.instance(cfg); final OlapModel olapModel = (OlapModel) mondrianModel.getTopDecorator(); olapModel.setLocale(context.getLocale()); // olapModel.setLocale(FacesContext.getCurrentInstance().getViewRoot().getLocale()); olapModel.setServletContext(context.getSession().getServletContext()); // olapModel.setServletContext((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()); // olapModel. olapModel.initialize(); if (log.isDebugEnabled()) { java.util.Enumeration attributeNames = session.getAttributeNames(); while (attributeNames.hasMoreElements()) { String name = (String) attributeNames.nextElement(); log.debug("--- name: " + name + "; type:" + session.getAttribute(name).getClass() + " ---"); } } // borramos de la sesion los datos que ha metido JPivot // y el model de la consulta que volveremos a meter // Esto es necesario porque los tags de JPivot no machacan los // valores si ya estn en sesin; por lo que al cambiar de informe // sigue mostrando el informe selecionado previamente session.removeAttribute(JPivotUtils.QUERY_SESSION_NAME); session.removeAttribute(JPivotUtils.TABLE_SESSION_NAME); session.removeAttribute(JPivotUtils.NAVI_SESSION_NAME); session.removeAttribute(JPivotUtils.SORTFORM_SESSION_NAME); session.removeAttribute(JPivotUtils.PRINT_SESSION_NAME); session.removeAttribute(JPivotUtils.PRINTFORM_SESSION_NAME); session.removeAttribute(JPivotUtils.CHART_SESSION_NAME); session.removeAttribute(JPivotUtils.CHARTFORM_SESSION_NAME); session.removeAttribute(JPivotUtils.TOOLBAR_SESSION_NAME); session.setAttribute(JPivotUtils.QUERY_SESSION_NAME, olapModel); return olapModel; }
From source file:io.fabric8.apiman.ApimanStarter.java
private static URL waitForDependency(URL url, String path, String serviceName, String key, String value, String username, String password) throws InterruptedException { boolean isFoundRunningService = false; ObjectMapper mapper = new ObjectMapper(); int counter = 0; URL endpoint = null; while (!isFoundRunningService) { endpoint = resolveServiceEndpoint(url.getProtocol(), url.getHost(), String.valueOf(url.getPort())); if (endpoint != null) { String isLive = null; try { URL statusURL = new URL(endpoint.toExternalForm() + path); HttpURLConnection urlConnection = (HttpURLConnection) statusURL.openConnection(); urlConnection.setConnectTimeout(500); if (urlConnection instanceof HttpsURLConnection) { try { KeyStoreUtil.Info tPathInfo = new KeyStoreUtil().new Info(ApimanStarter.TRUSTSTORE_PATH, ApimanStarter.TRUSTSTORE_PASSWORD_PATH); TrustManager[] tms = KeyStoreUtil.getTrustManagers(tPathInfo); KeyStoreUtil.Info kPathInfo = new KeyStoreUtil().new Info( ApimanStarter.CLIENT_KEYSTORE_PATH, ApimanStarter.CLIENT_KEYSTORE_PASSWORD_PATH); KeyManager[] kms = KeyStoreUtil.getKeyManagers(kPathInfo); final SSLContext sc = SSLContext.getInstance("TLS"); sc.init(kms, tms, new java.security.SecureRandom()); final SSLSocketFactory socketFactory = sc.getSocketFactory(); HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory); HttpsURLConnection httpsConnection = (HttpsURLConnection) urlConnection; httpsConnection.setHostnameVerifier(new DefaultHostnameVerifier()); httpsConnection.setSSLSocketFactory(socketFactory); } catch (Exception e) { log.error(e.getMessage(), e); throw e; }/*from w w w . j ava 2 s . c o m*/ } if (Utils.isNotNullOrEmpty(username)) { String encoded = Base64.getEncoder() .encodeToString((username + ":" + password).getBytes("UTF-8")); urlConnection.setRequestProperty("Authorization", "Basic " + encoded); log.info(username + ":" + "*****"); } isLive = IOUtils.toString(urlConnection.getInputStream()); Map<String, Object> esResponse = mapper.readValue(isLive, new TypeReference<Map<String, Object>>() { }); if (esResponse.containsKey(key) && value.equals(String.valueOf(esResponse.get(key)))) { isFoundRunningService = true; } else { if (counter % 10 == 0) log.info(endpoint.toExternalForm() + " not yet up. " + isLive); } } catch (Exception e) { if (counter % 10 == 0) log.info(endpoint.toExternalForm() + " not yet up. " + e.getMessage()); } } else { if (counter % 10 == 0) log.info("Could not find " + serviceName + " in namespace, waiting.."); } counter++; Thread.sleep(1000l); } return endpoint; }