List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:com.blacklocus.webapp.RunServer.java
@Override public void go() throws Exception { WebAppContext webApp = new WebAppContext(); // Effectively removes the "no-JSP support" warning, because we don't want dirty, stinkin' JSP support ever. webApp.setDefaultsDescriptor("webdefault-nojsp.xml"); // Fixes serving static resources correctly. Without this, no charset is set in the Content-Type header and // 'good' browsers do a terrible job at guessing. Does not affect Java resources, which must specify // their own @Produces (usually by extending BaseJsonResource). webApp.addFilter(new StaticResourceUTF8CharEncodingFilterHolder(), "/*", EnumSet.allOf(DispatcherType.class)); //////////////////// // Prepare jersey // as a filter-specifically because that can support falling back to static content when no java resource matches FilterHolder jerseyFilter = new FilterHolder(ServletContainer.class); jerseyFilter.setName(prcCls.getName()); jerseyFilter.setInitParameter(ServletContainer.APPLICATION_CONFIG_CLASS, prcCls.getCanonicalName()); jerseyFilter.setInitParameter(ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX, $.getString(PROP_STATIC_CONTENT_REGEX)); jerseyFilter.setInitParameter(ResourceConfig.PROPERTY_DEFAULT_RESOURCE_COMPONENT_PROVIDER_FACTORY_CLASS, SingletonFactory.class.getCanonicalName()); jerseyFilter.setInitParameter(ResourceConfig.FEATURE_DISABLE_WADL, "true"); jerseyFilter.setInitParameter(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, AccessControlAllowOriginAllContainerResponseFilter.class.getCanonicalName()); jerseyFilter.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); Map<String, String> addtionalInitParams = getAdditionalJerseyInitParameters(); for (Map.Entry<String, String> initParam : addtionalInitParams.entrySet()) { // must iterate because jerseyFilter.setInitParameters replaces everything jerseyFilter.setInitParameter(initParam.getKey(), initParam.getValue()); }/*from www.ja v a2 s .co m*/ webApp.addFilter(jerseyFilter, "/*", EnumSet.allOf(DispatcherType.class)); //////////////////////////////////////// // prepare static resources locations final Resource staticResources; String explicitStaticDirs = propSet.getString(PROP_STATIC_DIRS); if (explicitStaticDirs == null) { // Single static resource directory in the classpath:static/ folder. //noinspection ConstantConditions URL staticDir = prcCls.getClassLoader().getResource("static"); staticResources = staticDir == null ? Resource.newResource("") : Resource.newResource(staticDir.toExternalForm()); } else { // Explicitly named static resource directories. There may be multiple. First match wins. staticResources = new ResourceCollection(explicitStaticDirs.split(";")); } webApp.setBaseResource(staticResources); /////////////////////////////////// // initialize network listeners SERVER = new Server( new InetSocketAddress(propSet.getString(PROP_JETTY_HOST), propSet.getInt(PROP_JETTY_PORT))); SslSelectChannelConnector ssl = createSsl(); if (ssl != null) { SERVER.addConnector(ssl); } SERVER.setHandler(webApp); SERVER.start(); SERVER.join(); // blocks this thread }
From source file:org.apache.commons.rdf.integrationtests.JSONLDParsingTest.java
private void jsonldParse(URL url) throws JsonParseException, IOException, JsonLdError { Object aliceJson = JsonUtils.fromURL(url, JsonUtils.getDefaultHttpClient()); JsonLdOptions options = new JsonLdOptions(); options.setBase(url.toExternalForm()); RDFDataset ds = (RDFDataset) JsonLdProcessor.toRDF(aliceJson); JsonLdGraph graph = new JsonLdRDF().asGraph(ds); checkGraph(graph);//from w w w . j ava 2s . c om }
From source file:com.intuit.tank.http.multipart.MultiPartRequest.java
/** * Execute the POST./*from ww w . j ava 2 s. co m*/ */ public void doPost(BaseResponse response) { PostMethod httppost = null; String theUrl = null; try { URL url = BaseRequestHandler.buildUrl(protocol, host, port, path, urlVariables); theUrl = url.toExternalForm(); httppost = new PostMethod(url.toString()); String requestBody = getBody(); List<Part> parts = buildParts(); httppost.setRequestEntity( new MultipartRequestEntity(parts.toArray(new Part[parts.size()]), httppost.getParams())); sendRequest(response, httppost, requestBody); } catch (MalformedURLException e) { LOG.error(LogUtil.getLogMessage("Malformed URL Exception: " + e.toString(), LogEventType.IO), e); // swallowing error. validatin will check if there is no response // and take appropriate action throw new RuntimeException(e); } catch (Exception ex) { // logger.error(LogUtil.getLogMessage(ex.toString()), ex); // swallowing error. validatin will check if there is no response // and take appropriate action throw new RuntimeException(ex); } finally { if (null != httppost) { httppost.releaseConnection(); } if (APITestHarness.getInstance().getTankConfig().getAgentConfig().getLogPostResponse()) { LOG.info( LogUtil.getLogMessage( "Response from POST to " + theUrl + " got status code " + response.getHttpCode() + " BODY { " + response.getResponseBody() + " }", LogEventType.Informational)); } } }
From source file:org.wildfly.test.integration.elytron.securitydomain.SecurityDomainTestCase.java
private URL prepareRolesPrintingURL(URL webAppURL) throws MalformedURLException { return new URL( webAppURL.toExternalForm() + RolePrintingServlet.SERVLET_PATH.substring(1) + "?" + queryRoles); }
From source file:org.gradle.api.internal.artifacts.repositories.transport.http.HttpResourceCollection.java
public List list(String parent) throws IOException { // Parse standard directory listing pages served up by Apache ApacheURLLister urlLister = new ApacheURLLister(); List<URL> urls = urlLister.listAll(new URL(parent)); if (urls != null) { List<String> ret = new ArrayList<String>(urls.size()); for (URL url : urls) { ret.add(url.toExternalForm()); }/*from w ww . j a v a2 s .c o m*/ return ret; } return null; }
From source file:guineu.desktop.impl.helpsystem.GuineuHelpMap.java
/** * Gets the ID for this URL./*from w w w. j a va2 s . c o m*/ * * @param url * The URL to get the ID for. * @return The id (Map.ID) or null if URL is not an ID. */ public ID getIDFromURL(URL url) { String tmp; URL tmpURL; if (url == null) { return null; } String urlString = url.toExternalForm(); for (Enumeration<String> e = getAllIDs(); e.hasMoreElements();) { String key = (String) e.nextElement(); try { tmp = (String) lookup.get(key); tmpURL = new URL(tmp); // Sometimes tmp will be null because not all keys are ids if (tmpURL == null) { continue; } String tmpString = tmpURL.toExternalForm(); if (urlString.compareTo(tmpString) == 0) { return ID.create(key, helpset); } } catch (Exception ex) { } } return null; }
From source file:com.opensymphony.xwork2.util.finder.UrlSet.java
/** * Try to find a classes directory inside a war file add its normalized url to this set *//*from ww w.j av a 2 s . com*/ public UrlSet includeClassesUrl(ClassLoaderInterface classLoaderInterface, FileProtocolNormalizer normalizer) throws IOException { Enumeration<URL> rootUrlEnumeration = classLoaderInterface.getResources(""); while (rootUrlEnumeration.hasMoreElements()) { URL url = rootUrlEnumeration.nextElement(); String externalForm = StringUtils.removeEnd(url.toExternalForm(), "/"); if (externalForm.endsWith(".war/WEB-INF/classes")) { //if it is inside a war file, get the url to the file externalForm = StringUtils.substringBefore(externalForm, "/WEB-INF/classes"); URL warUrl = new URL(externalForm); URL normalizedUrl = normalizer.normalizeToFileProtocol(warUrl); URL finalUrl = ObjectUtils.defaultIfNull(normalizedUrl, warUrl); Map<String, URL> newUrls = new HashMap<String, URL>(this.urls); if ("jar".equals(finalUrl.getProtocol()) || "file".equals(finalUrl.getProtocol())) { newUrls.put(finalUrl.toExternalForm(), finalUrl); } return new UrlSet(newUrls); } } return this; }
From source file:org.callimachusproject.xproc.Pipeline.java
private void loadConfig(XdmNodeFactory resolver, XProcConfiguration config) throws IOException { ClassLoader cl = getClass().getClassLoader(); Enumeration<URL> resources = cl.getResources("META-INF/xmlcalabash.xml"); while (resources.hasMoreElements()) { try {//from w w w . jav a 2s . c om URL puri = resources.nextElement(); InputStream in = puri.openStream(); config.parse(resolver.parse(puri.toExternalForm(), in)); } catch (SAXException sae) { throw new XProcException(sae); } } }
From source file:ch.ledcom.maven.sitespeed.analyzer.SiteSpeedAnalyzer.java
public Document analyze(URL url) throws IOException, JDOMException, InterruptedException { InputStream in = null;//w w w .j a va 2 s . c o m boolean threw = true; try { log.info("Starting analysis of [" + url.toExternalForm() + "]"); List<String> command = constructCommand(url); logCommand(command); ProcessBuilder pb = new ProcessBuilder(command); pb.redirectErrorStream(); Process p = pb.start(); // FIXME: we need to filter the InputStream as it seems we can get // content outside of the XML document (see sitespeed.io) in = p.getInputStream(); byte[] result = IOUtils.toByteArray(in); log.info("Result of analysis:" + ArrayUtils.toString(result)); Document doc = docBuilder.get().build(new ByteArrayInputStream(result)); log.info(XmlPrettyPrinter.prettyPrint(doc)); int status = p.waitFor(); if (status != 0) { throw new RuntimeException("PhantomJS returned with status [" + status + "]"); } threw = false; return doc; } finally { Closeables.close(in, threw); } }
From source file:org.nabucco.alfresco.enhScriptEnv.common.webscripts.processor.ClasspathScriptContent.java
/** * {@inheritDoc}/* w w w .j av a 2 s . c o m*/ */ @Override public String getPath() { final URL resource = getClass().getClassLoader().getResource(this.path); if (resource == null) { throw new WebScriptException( MessageFormat.format("Unable to retrieve resource for script {0}", getPathDescription())); } final String path = resource.toExternalForm(); return path; }