List of usage examples for java.net URISyntaxException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:eu.planets_project.services.datatypes.Content.java
/** * Create content by reference.// ww w . jav a2s .c o m * @param reference The URL reference to the actual content * @return A content instance referencing the given location */ public static DigitalObjectContent byReference(final URL reference) { URI uriReference = null; /* we do not really expect a URI syntax exception on conversion from URL ... */ try { uriReference = reference.toURI(); } catch (URISyntaxException use) { System.out.println(use.getClass().getName() + ": " + use.getMessage()); } return new ImmutableContent(uriReference); }
From source file:org.kitodo.dataaccess.format.xml.Namespaces.java
/** * Converts a URI to a globally unique name space. The name space is formed * with the host name of the machine the program is running on. * * @param uri// ww w .ja v a2 s . co m * URI to create a globally unique URI for * @return globally unique namespace * @throws IOException * if it fails */ public static String namespaceFromURI(URI uri) throws IOException { try { String host = uri.getHost(); String path = uri.getPath(); if (host == null) { host = InetAddress.getLocalHost().getCanonicalHostName(); if ((path != null) && path.startsWith("//")) { int pathStart = path.indexOf('/', 2); String remote = path.substring(2, pathStart); path = path.substring(pathStart); host = remote.contains(".") ? remote : remote.concat(host.substring(InetAddress.getLocalHost().getHostName().length())); } } String scheme = uri.getScheme(); if ((scheme == null) || !scheme.toLowerCase().startsWith("http")) { scheme = "http"; } return new URI(scheme, uri.getUserInfo(), host, uri.getPort(), path, uri.getQuery(), "") .toASCIIString(); } catch (URISyntaxException e) { String message = e.getMessage(); throw new IllegalArgumentException(message != null ? message : e.getClass().getName(), e); } }
From source file:de.kaiserpfalzEdv.office.ui.web.widgets.ImageSource.java
public ImageSource(final String fileName) { this.fileName = fileName; image = getClass().getClassLoader().getResourceAsStream(fileName); LOG.trace("Created: {}", this); try {//from w ww . jav a 2 s .co m LOG.trace(" from file: {}", getClass().getClassLoader().getResource(fileName).toURI()); } catch (URISyntaxException e) { LOG.error(e.getClass().getSimpleName() + " caught: " + e.getMessage(), e); } }
From source file:io.github.jhipster.security.uaa.LoadBalancedResourceDetails.java
@Override public String getAccessTokenUri() { if (loadBalancerClient != null && tokenServiceId != null && !tokenServiceId.isEmpty()) { try {//from w ww. j a va 2 s. c o m return loadBalancerClient.reconstructURI(loadBalancerClient.choose(tokenServiceId), new URI(super.getAccessTokenUri())).toString(); } catch (URISyntaxException e) { log.error("{}: {}", e.getClass().toString(), e.getMessage()); return super.getAccessTokenUri(); } } else { return super.getAccessTokenUri(); } }
From source file:org.sakaiproject.shortenedurl.impl.BitlyUrlService.java
/** * Make a GET request and append the Map of parameters onto the query string. * @param address the fully qualified URL to make the request to * @param parameters the Map of parameters, ie key,value pairs * @return/* w w w . j a va 2 s.c o m*/ */ private String doGet(String address, Map<String, String> parameters) { try { List<NameValuePair> queryParams = new ArrayList<NameValuePair>(); for (Map.Entry<String, String> entry : parameters.entrySet()) { queryParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } URI uri = URIUtils.createURI(null, address, -1, null, URLEncodedUtils.format(queryParams, "UTF-8"), null); log.info(uri.toString()); return doGet(uri.toString()); } catch (URISyntaxException e) { log.error(e.getClass() + ":" + e.getMessage()); } return null; }
From source file:tech.beshu.ror.httpclient.ApacheHttpCoreClient.java
@Override public CompletableFuture<RRHttpResponse> send(RRHttpRequest request) { CompletableFuture<HttpResponse> promise = new CompletableFuture<>(); URI uri;/* w w w. j a v a 2s. c om*/ HttpRequestBase hcRequest; try { if (request.getMethod() == HttpMethod.POST) { uri = new URIBuilder(request.getUrl().toASCIIString()).build(); hcRequest = new HttpPost(uri); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); request.getQueryParams().entrySet() .forEach(x -> urlParameters.add(new BasicNameValuePair(x.getKey(), x.getValue()))); ((HttpPost) hcRequest).setEntity(new UrlEncodedFormEntity(urlParameters)); } else { uri = new URIBuilder(request.getUrl().toASCIIString()).addParameters(request.getQueryParams() .entrySet().stream().map(e -> new BasicNameValuePair(e.getKey(), e.getValue())) .collect(Collectors.toList())).build(); hcRequest = new HttpGet(uri); } } catch (URISyntaxException e) { throw context.rorException(e.getClass().getSimpleName() + ": " + e.getMessage()); } catch (UnsupportedEncodingException e) { throw context.rorException(e.getClass().getSimpleName() + ": " + e.getMessage()); } request.getHeaders().entrySet().forEach(e -> hcRequest.addHeader(e.getKey(), e.getValue())); AccessController.doPrivileged((PrivilegedAction<Void>) () -> { hcHttpClient.execute(hcRequest, new FutureCallback<HttpResponse>() { public void completed(final HttpResponse hcResponse) { int statusCode = hcResponse.getStatusLine().getStatusCode(); logger.debug("HTTP REQ SUCCESS with status: " + statusCode + " " + request); promise.complete(hcResponse); } public void failed(final Exception ex) { logger.debug("HTTP REQ FAILED " + request); logger.info("HTTP client failed to connect: " + request + " reason: " + ex.getMessage()); promise.completeExceptionally(ex); } public void cancelled() { promise.completeExceptionally(new RuntimeException("HTTP REQ CANCELLED: " + request)); } }); return null; }); return promise.thenApply(hcResp -> new RRHttpResponse(hcResp.getStatusLine().getStatusCode(), () -> { try { return hcResp.getEntity().getContent(); } catch (IOException e) { throw new RuntimeException("Cannot read content", e); } })); }
From source file:org.paxle.parser.sitemap.impl.PingServlet.java
@Override public void doGet(HttpServletRequest req, HttpServletResponse rsp) throws IOException { String uriString = null;// www . j a v a 2 s . c o m try { uriString = req.getParameter("sitemap"); if (uriString == null || uriString.length() == 0) { rsp.setStatus(401); return; } // parsing the URI URI uri = new URI(uriString); // TODO downloading and parsing the sitemap // TODO: create a new crawling profile // TODO: whould we register as data provider? } catch (URISyntaxException e) { this.logger.error(String.format("Invalid syntax: %s", uriString)); rsp.setStatus(400); return; } catch (Throwable e) { this.logger.error(String.format("Unexpected '%s' while triggering sitemap parser for URI '%s': %s", e.getClass().getName(), uriString, e.getMessage())); rsp.setStatus(401); return; } }
From source file:de.uni_koblenz.west.splendid.tools.NQuadSourceAggregator.java
private void process(InputStream in, Writer writer) { NxParser parser = new NxParser(in); Node[] quad = null;/*from w w w. j av a2 s.co m*/ while (parser.hasNext()) { try { quad = parser.next(); // ignore path information, just consider host name String host = new URI(quad[3].toString()).getHost(); if (!isIPAddress(host)) host = truncateHostName(host); quad[3] = new Resource("http://" + host); ctxCounter.add((Resource) quad[3]); writer.write(quad[0].toN3()); writer.write(" "); writer.write(quad[1].toN3()); writer.write(" "); writer.write(quad[2].toN3()); writer.write(" "); writer.write(quad[3].toN3()); writer.write(" ."); writer.write(LINE_SEP); } catch (URISyntaxException e) { System.out.println("Invalid URI: " + e.getMessage()); continue; } catch (Exception e) { System.out.println("ERROR: " + e.getClass() + " - " + e.getMessage()); continue; } } }
From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java
private ResolvedRepositoryData resolveTargetRepository(RequestMethod method, HttpServletRequest req) throws IOException { ResolvedRepositoryData repoData = new ResolvedRepositoryData(); String op = StringUtils.trimToEmpty(req.getParameter("service")), uriPath = req.getPathInfo(); if (StringUtils.isEmpty(op)) { int pos = uriPath.lastIndexOf('/'); if ((pos > 0) && (pos < (uriPath.length() - 1))) { op = uriPath.substring(pos + 1); }//from w ww. j a va 2 s .c o m } if (!ALLOWED_SERVICES.contains(op)) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "resolveTargetRepository(" + method + " " + uriPath + ")", new UnsupportedOperationException("Unsupported operation: " + op)); } repoData.setOperation(op); String repoName = extractRepositoryName(uriPath); if (StringUtils.isEmpty(repoName)) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "resolveTargetRepository(" + method + " " + uriPath + ")", new IllegalArgumentException("Failed to extract repo name from " + uriPath)); } repoData.setRepoName(repoName); // TODO access an injected resolver that returns the back-end location URL String query = req.getQueryString(); try { if (StringUtils.isEmpty(query)) { repoData.setRepoLocation(new URI("http://localhost:8080/git-backend/git" + uriPath)); } else { repoData.setRepoLocation(new URI("http://localhost:8080/git-backend/git" + uriPath + "?" + query)); } } catch (URISyntaxException e) { throw new MalformedURLException(e.getClass().getSimpleName() + ": " + e.getMessage()); } return repoData; }
From source file:com.openshift.internal.restclient.authorization.AuthorizationClient.java
private IAuthorizationContext getContextUsingCredentials(final String baseURL, CredentialsProvider credentialsProvider) { CloseableHttpResponse response = null; CloseableHttpClient client = null;//from w w w . j a va 2 s .c o m try { OpenShiftAuthorizationRedirectStrategy redirectStrategy = new OpenShiftAuthorizationRedirectStrategy( openshiftClient); RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(TIMEOUT) .setConnectTimeout(TIMEOUT).setConnectionRequestTimeout(TIMEOUT) .setStaleConnectionCheckEnabled(true).build(); client = HttpClients.custom().setRedirectStrategy(redirectStrategy) .setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault())) .setHostnameVerifier(hostnameVerifier).setDefaultCredentialsProvider(credentialsProvider) .setSslcontext(sslContext).setDefaultRequestConfig(defaultRequestConfig).build(); HttpGet request = new HttpGet(new URIBuilder(String.format("%s/oauth/authorize", baseURL)) .addParameter("response_type", "token") .addParameter("client_id", "openshift-challenging-client").build()); request.addHeader("X-CSRF-Token", "1"); response = client.execute(request); return redirectStrategy.getAuthorizationContext(); } catch (URISyntaxException e) { throw new OpenShiftException(e, String .format("Unvalid URI while trying to get an authorization context for server %s", baseURL)); } catch (ClientProtocolException e) { throw new OpenShiftException(e, String.format( "Client protocol exception while trying to get authorization context for server %s", baseURL)); } catch (IOException e) { throw new OpenShiftException(e, String.format("%s while trying to get an authorization context for server %s", e.getClass().getName(), baseURL)); } finally { close(response); close(client); } }