List of usage examples for java.net URL toString
public String toString()
From source file:ch.epfl.bbp.uima.uimafit.CpeBuilder.java
private static CpeIntegratedCasProcessor createProcessor(String key, AnalysisEngineDescription aDesc) throws IOException, SAXException, CpeDescriptorException { URL descUrl = materializeDescriptor(aDesc).toURI().toURL(); CpeInclude cpeInclude = UIMAFramework.getResourceSpecifierFactory().createInclude(); cpeInclude.set(descUrl.toString()); CpeComponentDescriptor ccd = UIMAFramework.getResourceSpecifierFactory().createDescriptor(); ccd.setInclude(cpeInclude);//from www .ja v a 2 s. c o m CpeIntegratedCasProcessor proc = CpeDescriptorFactory.produceCasProcessor(key); proc.setCpeComponentDescriptor(ccd); proc.setAttributeValue(CpeDefaultValues.PROCESSING_UNIT_THREAD_COUNT, 1); proc.setActionOnMaxError(ACTION_ON_MAX_ERROR); proc.setMaxErrorCount(0); return proc; }
From source file:eu.prestoprime.p4gui.connection.AccessConnection.java
public static String getResource(P4Service service, URL url) { String path = url.toString(); try {/*from w w w. ja v a 2s . com*/ P4HttpClient client = new P4HttpClient(service.getUserID()); HttpRequestBase request = new HttpGet(path); HttpResponse response = client.executeRequest(request); HttpEntity entity = response.getEntity(); if (entity != null) { String line; StringBuffer sb = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); while ((line = reader.readLine()) != null) { sb.append(line.trim()); } return sb.toString(); } } catch (Exception e) { logger.error("Unable to get the result..."); } return null; }
From source file:com.norconex.commons.lang.url.URLStreamer.java
/** * Streams URL content.//from w ww . j a v a 2 s . c o m * @param url the URL to stream * @param creds credentials for a protected URL * @return a URL content InputStream */ public static InputStream stream(URL url, Credentials creds) { return stream(url.toString(), creds, null); }
From source file:org.wso2.am.integration.test.utils.http.HTTPSClientUtils.java
/** * do HTTP POST operation for the given URL with JSON entity * @param url//from ww w . j a va 2 s. c o m * @param headers * @param json * @return org.wso2.carbon.automation.test.utils.http.client.HttpResponse * @throws IOException */ public static org.wso2.carbon.automation.test.utils.http.client.HttpResponse doPost(URL url, Map<String, String> headers, String json) throws IOException { CloseableHttpClient httpClient = getHttpsClient(); HttpResponse response = sendPOSTMessage(httpClient, url.toString(), headers, json); return constructResponse(response); }
From source file:com.zimbra.cs.servlet.util.AuthUtil.java
public static String getRedirectURL(HttpServletRequest req, Server server, boolean isAdminRequest, boolean relative) throws ServiceException, MalformedURLException { String redirectUrl;/*from w w w.j a va 2 s . co m*/ if (isAdminRequest) { redirectUrl = getAdminURL(server, relative); } else { redirectUrl = getMailURL(server, relative); } if (!relative) { URL url = new URL(redirectUrl); // replace host of the URL to the host the request was sent to String reqHost = req.getServerName(); String host = url.getHost(); if (!reqHost.equalsIgnoreCase(host)) { URL destUrl = new URL(url.getProtocol(), reqHost, url.getPort(), url.getFile()); redirectUrl = destUrl.toString(); } } return redirectUrl; }
From source file:com.norconex.commons.lang.url.URLStreamer.java
/** * Streams URL content to a String./*w w w. j a v a 2s. c o m*/ * @param url the URL to stream * @param creds credentials for a protected URL * @return a URL content as a String */ public static String streamToString(URL url, Credentials creds) { return streamToString(url.toString(), creds, null); }
From source file:spark.protocol.SparqlCall.java
/** * Executes a SPARQL HTTP protocol request for the given command, and returns the response. * @param command The SPARQL protocol command. * @return The HTTP response./*from www.j a v a 2 s. c o m*/ */ static HttpResponse executeRequest(ProtocolCommand command, String mimeType) { HttpClient client = ((ProtocolConnection) command.getConnection()).getHttpClient(); URL url = ((ProtocolDataSource) command.getConnection().getDataSource()).getUrl(); HttpUriRequest req; try { String params = "query=" + encode(command.getCommand()); String u = url.toString() + "?" + params; if (u.length() > QUERY_LIMIT) { // POST connection try { req = new HttpPost(url.toURI()); } catch (URISyntaxException e) { throw new SparqlException("Endpoint <" + url + "> not in an acceptable format", e); } ((HttpPost) req).setEntity((HttpEntity) new StringEntity(params)); } else { // GET connection req = new HttpGet(u); } if (command.getTimeout() != Command.NO_TIMEOUT) { HttpParams reqParams = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(reqParams, (int) (command.getTimeout() * 1000)); req.setParams(reqParams); } // Add Accept and Content-Type (for POST'ed queries) headers to the request. addHeaders(req, mimeType); // There's a small chance the request could be aborted before it's even executed, we'll have to live with that. command.setRequest(req); //dump(client, req); HttpResponse response = client.execute(req); StatusLine status = response.getStatusLine(); int code = status.getStatusCode(); // TODO the client doesn't handle redirects for posts; should we do that here? if (code >= SUCCESS_MIN && code <= SUCCESS_MAX) { return response; } else { throw new SparqlException("Unexpected status code in server response: " + status.getReasonPhrase() + "(" + code + ")"); } } catch (UnsupportedEncodingException e) { throw new SparqlException("Unabled to encode data", e); } catch (ClientProtocolException cpe) { throw new SparqlException("Error in protocol", cpe); } catch (IOException e) { throw new SparqlException(e); } }
From source file:edu.du.penrose.systems.util.HttpClientUtils_2.java
static public WebPage academicSearch(URL initialLink) { WebPage wp = new WebPage(); HttpClient client = new HttpClient(); GetMethod getMethod = new GetMethod(initialLink.toString()); getMethod.setFollowRedirects(true);//from w ww . j a va2 s. c o m try { // System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); // System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); // System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug"); // System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); // getMethod.setRequestHeader("User-Agent", "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"); // in case they check int statusCode = client.executeMethod(getMethod); String contents = getMethod.getResponseBodyAsString(); String formPage = getMethod.getURI().toString(); // page we were sent to. wp.setStatus(statusCode); wp.setWebPage(contents); // System.out.println();System.out.println();System.out.println();System.out.println();System.out.println(contents); String sid = getSID(contents); String postURL = "http://web.ebscohost.com/ehost/search?vid=1&hid=9&sid=" + sid; PostMethod postMethod = new PostMethod( "http://web.ebscohost.com/ehost/search?vid=1&hid=9&sid=c3220986-66e4-4fd1-ba6a-30504f3694ad%40sessionmgr13"); postMethod.setRequestHeader("User-Agent", "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"); // in case they check // postMethod.setFollowRedirects( true ); causes error postMethod.setParameter(SESSION_ID, sid); setResolution(postMethod, contents); setNonchangingFields(postMethod); statusCode = client.executeMethod(postMethod); if (statusCode > 300) { String resultsPage = getMethod.getURI().toString(); // page we were sent to. getMethod = new GetMethod(resultsPage); getMethod.setRequestHeader("User-Agent", "Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101"); // in case they check statusCode = client.executeMethod(getMethod); contents = getMethod.getResponseBodyAsString(); wp.setStatus(statusCode); wp.setWebPage(contents); } contents = postMethod.getResponseBodyAsString(); wp.setStatus(statusCode); wp.setWebPage(contents); System.out.println(); System.out.println(); System.out.println(); System.out.println(); System.out.println(contents); } catch (Exception e) { System.out.println(e); } finally { getMethod.releaseConnection(); } return wp; }
From source file:com.norconex.commons.lang.url.URLStreamer.java
/** * Streams URL content./*from ww w.j a v a2 s . co m*/ * @param url the URL to stream * @param creds credentials for a protected URL * @param proxy proxy to use to stream the URL * @return a URL content InputStream */ public static InputStream stream(URL url, Credentials creds, HttpHost proxy) { return stream(url.toString(), creds, proxy, null); }
From source file:com.networknt.utility.Util.java
public static String getFrameworkVersion() { // this doesn't work. // TODO make it work. Class clazz = Util.class; URL location = clazz.getResource('/' + clazz.getName().replace('.', '/') + ".class"); System.out.println("location = " + location); //location = jar:file:/Users/stevehu/project/light-example-4j/petstore/target/swagger-light-server-1.0.0.jar!/com/networknt/utility/Util.class return location.toString(); }