List of usage examples for java.net URISyntaxException toString
public String toString()
From source file:adalid.jaas.google.GoogleRecaptcha.java
private static boolean verify(String userResponse) { if (userResponse == null) { return VERIFY_NULL_RESPONSE; }/* w w w. j av a 2 s .c o m*/ URIBuilder builder = new URIBuilder(); builder.setScheme("https"); builder.setHost("www.google.com"); builder.setPath("/recaptcha/api/siteverify"); // builder.clearParameters(); builder.setParameter("secret", SECRET_KEY); builder.setParameter("response", userResponse); URI uri; try { uri = builder.build(); } catch (URISyntaxException ex) { logger.log(Level.SEVERE, ex.toString(), ex); return false; } HttpUriRequest request = (HttpUriRequest) new HttpGet(uri); try (CloseableHttpClient client = HttpClients.createDefault()) { try (CloseableHttpResponse response = client.execute(request)) { StatusLine statusLine = response.getStatusLine(); logger.log(TRACE, "Status Line: {0}", statusLine); if (statusLine.getReasonPhrase().equals("OK")) { return success(response.getEntity()); } } catch (ClientProtocolException ex) { logger.log(Level.SEVERE, ex.toString(), ex); } } catch (IOException ex) { logger.log(Level.SEVERE, ex.toString(), ex); } return false; }
From source file:de.ailis.xadrian.utils.SwingUtils.java
/** * Opens a URL in the browser. It first tries to do this with the Desktop * API. If this fails then it tries to use the FreeDesktop-API. * //from w w w . j ava 2 s.com * @param url * The URL to open. */ public static void openBrowser(final String url) { try { openBrowser(new URI(url)); } catch (final URISyntaxException e) { LOG.error(e.toString(), e); } }
From source file:org.wikipedia.nirvana.WikiTools.java
private static String fetchQuery(Service service, String query) throws IOException, InterruptedException { URI uri = null;/*w w w . j a v a 2s .co m*/ try { uri = new URI(HTTP, service.DOMAIN, service.PATH, query, null); } catch (URISyntaxException e) { log.error(e.toString()); return null; } if (testMode) { if (savedQueries == null) savedQueries = new ArrayList<>(); savedQueries.add(query); } if (testMode && mockedResponses != null) { if (mockedResponses.isEmpty()) { throw new RuntimeException( "fetchQuery() called in test mode when no mocked responces is available!"); } return mockedResponses.remove(0); } String page = null; try { page = HTTPTools.fetch(uri.toASCIIString(), !fastMode, true, true); } catch (java.net.SocketTimeoutException e) { if (fastMode) { throw e; } else { log.warn(e.toString() + ", retry again ..."); Thread.sleep(TIMEOUT_DELAY); page = HTTPTools.fetch(uri.toASCIIString(), true, true, true); } } return page; }
From source file:org.apache.axis2.jaxws.utility.JavaUtils.java
/** * Convert a String to a URI, handling special characters in the String such as * spaces.//from w w w .j a v a 2 s . c om * * @param pathString The String to be converted to a URI * @return a URI or null if the String can't be converted. */ public static URI createURI(String pathString) { URI pathURI = null; if (pathString == null || "".equals(pathString)) { if (log.isDebugEnabled()) { log.debug("Path string argument is invalid [" + pathString + "]; returning null"); } return null; } try { pathURI = new URI(pathString); } catch (URISyntaxException ex1) { if (log.isDebugEnabled()) { log.debug("Unable to create URI from [" + pathString + "], trying alternative approach"); } /* * The URI creation requires special characters, such as spaces, be escaped or * converted. The 5 argument constuctor will do that for us. */ try { pathURI = new URI(null, null, pathString, null); } catch (URISyntaxException ex2) { if (log.isTraceEnabled()) { log.trace( "Unable to create URI using alternative approach; returning null. Exception caught during inital attempt: " + JavaUtils.stackToString(ex1)); log.trace("Exception caught during alternet attemt " + JavaUtils.stackToString(ex2)); } log.error(ex2.toString(), ex2); } } return pathURI; }
From source file:com.wind_now.statistics_api.latest.Builder.java
protected URI getUri(List<NameValuePair> params) { URI uri;/*from w ww.jav a2 s. c om*/ try { StringBuilder path = new StringBuilder(URL_PATH); params.stream().filter((nvp) -> (nvp.getName().equals("day"))).forEach((nvp) -> { path.append("latest"); path.append(nvp.getValue()); path.append("/"); }); params.stream().filter((nvp) -> (nvp.getName().equals("title"))).forEach((nvp) -> { path.append(nvp.getValue()); }); uri = new URIBuilder().setScheme(URL_SCHEME).setHost(URL_HOST).setPath(path.toString()) // .setParameters(params) .build(); System.out.println(uri); } catch (URISyntaxException e) { logger.severe(e.toString()); uri = null; } return uri; }
From source file:org.nuclos.common.activemq.NuclosHttpsTransportFactory.java
@Override protected Transport createTransport(URI location, WireFormat wf) throws MalformedURLException { if (location.getScheme().equals("myhttps")) { try {/* w w w .j a va2s .co m*/ location = new URI(location.toString().substring(2)); } catch (URISyntaxException e) { throw new MalformedURLException(e.toString()); } } final HttpsClientTransport result = (HttpsClientTransport) super.createTransport(location, wf); final HttpClient httpClient = getHttpClient(); result.setReceiveHttpClient(httpClient); result.setSendHttpClient(httpClient); return result; }
From source file:com.basho.riak.client.raw.http.HTTPClusterClient.java
/** * Make an {@link HttpRoute} for the given URL * //from w w w .j a va 2 s . com * @param url * @return a {@link HttpRoute} for the given URL */ private HttpRoute makeRoute(String url) throws IOException { try { URI uri = new URI(url); HttpHost host = new HttpHost(uri.getHost(), uri.getPort()); return new HttpRoute(host); } catch (URISyntaxException e) { throw new IOException(e.toString()); } }
From source file:com.edgenius.test.TestMain.java
protected List<TestItem> readTestcaseFile(String filename) throws IOException { System.out.println(//from w ww .j a v a 2 s . c o m "Load test file from URL:" + this.getClass().getClassLoader().getResource("testcase/" + filename)); URL url = this.getClass().getClassLoader().getResource("testcase/" + filename); TestItem item = null; int exp = 0; boolean withNewline = false; List<String> lines; try { lines = FileUtils.readLines(new File(url.toURI()), "UTF8"); } catch (URISyntaxException e) { throw new IOException(e.toString()); } List<TestItem> testcases = new ArrayList<TestItem>(); for (String line : lines) { if (!"".equals(line)) { if (line.startsWith("REM ")) continue; if (line.startsWith("===========")) { if (item != null) { testcases.add(item); } item = null; exp = 1; withNewline = false; continue; } if (line.startsWith("----------")) { exp = 2; withNewline = false; continue; } } if (exp == 1) { //if it is after first line of input if (withNewline) { item.expected += "\n"; } else { withNewline = true; } if (item == null) item = new TestItem(); item.expected += line; } else if (exp == 2) { //if it is after first line of input if (withNewline) { item.input += "\n"; } else { withNewline = true; } item.input += line; } } if (item != null) testcases.add(item); return testcases; }
From source file:com.ibm.connectors.splunklog.SplunkConnectionData.java
public URI getSplunkURI() throws ConnectorException { try {//ww w.j a va2 s .c o m this.setSplunkURI(this.myUriBuilder.build()); } catch (URISyntaxException e) { e.fillInStackTrace(); throw new ConnectorException(e.toString()); } return this.splunkURI; }
From source file:ca.uhn.fhir.model.primitive.UriDt.java
private String normalize(String theValue) { if (theValue == null) { return null; }//from ww w . j a v a 2 s. c o m URI retVal; try { retVal = new URI(theValue).normalize(); String urlString = retVal.toString(); if (urlString.endsWith("/") && urlString.length() > 1) { retVal = new URI(urlString.substring(0, urlString.length() - 1)); } } catch (URISyntaxException e) { ourLog.debug("Failed to normalize URL '{}', message was: {}", theValue, e.toString()); return theValue; } return retVal.toASCIIString(); }