List of usage examples for java.net URI toASCIIString
public String toASCIIString()
From source file:org.paxle.data.db.impl.CommandProfileFilter.java
void checkLinks(final ICommandProfile profile, final ICommand command, IParserDocument parserDoc, final Counter c) { if (parserDoc == null) return;//from www . j a va 2s .co m // getting the link map Map<URI, LinkInfo> linkMap = parserDoc.getLinks(); if (linkMap != null) { /* ================================================ * Check CRAWL_DEPTH * ================================================ */ if (command.getDepth() + 1 > profile.getMaxDepth()) { // reject all links for (LinkInfo meta : linkMap.values()) { if (!meta.hasStatus(Status.OK)) continue; meta.setStatus(Status.FILTERED, "Max. crawl-depth exceeded."); } // collect data c.c += linkMap.size(); c.blocked.putAll(linkMap); } /* ================================================ * Check LINK_FILTER match * ================================================ */ LinkFilterMode filterMode = profile.getLinkFilterMode(); String filterExpr = profile.getLinkFilterExpression(); if (filterMode.equals(LinkFilterMode.regexp)) { Pattern regexpPattern = Pattern.compile(filterExpr); for (Entry<URI, LinkInfo> entry : linkMap.entrySet()) { final URI link = entry.getKey(); final LinkInfo meta = entry.getValue(); // skip already blocked links if (!meta.hasStatus(Status.OK)) continue; // check against regexp Matcher m = regexpPattern.matcher(link.toASCIIString()); if (!m.matches()) { c.c++; meta.setStatus(Status.FILTERED, "Blocked by regexp filter"); c.blocked.put(link, meta); } } } } /* ================================================ * Check SUB-DOCUMENTS * ================================================ */ Map<String, IParserDocument> subDocs = parserDoc.getSubDocs(); if (subDocs != null) { for (IParserDocument subDoc : subDocs.values()) { this.checkLinks(profile, command, subDoc, c); } } }
From source file:org.apache.camel.component.http.HttpProducer.java
/** * Creates the HttpMethod to use to call the remote server, either its GET or POST. * * @param exchange the exchange/*from ww w. ja v a 2 s .c om*/ * @return the created method as either GET or POST * @throws CamelExchangeException is thrown if error creating RequestEntity */ @SuppressWarnings("deprecation") protected HttpMethod createMethod(Exchange exchange) throws Exception { // creating the url to use takes 2-steps String url = HttpHelper.createURL(exchange, getEndpoint()); URI uri = HttpHelper.createURI(exchange, url, getEndpoint()); // get the url and query string from the uri url = uri.toASCIIString(); String queryString = uri.getRawQuery(); // execute any custom url rewrite String rewriteUrl = HttpHelper.urlRewrite(exchange, url, getEndpoint(), this); if (rewriteUrl != null) { // update url and query string from the rewritten url url = rewriteUrl; uri = new URI(url); // use raw query to have uri decimal encoded which http client requires queryString = uri.getRawQuery(); } // remove query string as http client does not accept that if (url.indexOf('?') != -1) { url = url.substring(0, url.indexOf('?')); } // create http holder objects for the request RequestEntity requestEntity = createRequestEntity(exchange); HttpMethods methodToUse = HttpHelper.createMethod(exchange, getEndpoint(), requestEntity != null); HttpMethod method = methodToUse.createMethod(url); if (queryString != null) { // need to encode query string queryString = UnsafeUriCharactersEncoder.encode(queryString); method.setQueryString(queryString); } LOG.trace("Using URL: {} with method: {}", url, method); if (methodToUse.isEntityEnclosing()) { ((EntityEnclosingMethod) method).setRequestEntity(requestEntity); if (requestEntity != null && requestEntity.getContentType() == null) { LOG.debug("No Content-Type provided for URL: {} with exchange: {}", url, exchange); } } // there must be a host on the method if (method.getHostConfiguration().getHost() == null) { throw new IllegalArgumentException("Invalid uri: " + url + ". If you are forwarding/bridging http endpoints, then enable the bridgeEndpoint option on the endpoint: " + getEndpoint()); } return method; }
From source file:org.exist.xquery.functions.fn.FunUnparsedText.java
private Source getSource(final String uriParam) throws XPathException { try {/*from w w w. j a v a 2 s .c o m*/ URI uri = new URI(uriParam); if (uri.getScheme() == null) { uri = new URI(XmldbURI.EMBEDDED_SERVER_URI_PREFIX + uriParam); } if (uri.getFragment() != null) { throw new XPathException(this, ErrorCodes.FOUT1170, "href argument may not contain fragment identifier"); } final Source source = SourceFactory.getSource(context.getBroker(), "", uri.toASCIIString(), false); if (!context.getBroker().getCurrentSubject().hasDbaRole()) { throw new XPathException(this, ErrorCodes.FOUT1170, "non-dba user not allowed to read from file system"); } return source; } catch (IOException | PermissionDeniedException | URISyntaxException e) { throw new XPathException(this, ErrorCodes.FOUT1170, e.getMessage()); } }
From source file:org.apache.olingo.client.core.op.AbstractODataBinder.java
@Override public ODataEntitySet getODataEntitySet(final Feed resource, final URI defaultBaseURI) { if (LOG.isDebugEnabled()) { final StringWriter writer = new StringWriter(); client.getSerializer().feed(resource, writer); writer.flush();/*from w ww. jav a 2 s . c om*/ LOG.debug("Feed -> ODataEntitySet:\n{}", writer.toString()); } final URI base = defaultBaseURI == null ? resource.getBaseURI() : defaultBaseURI; final URI next = resource.getNext(); final ODataEntitySet entitySet = next == null ? client.getObjectFactory().newEntitySet() : client.getObjectFactory().newEntitySet(URIUtils.getURI(base, next.toASCIIString())); if (resource.getCount() != null) { entitySet.setCount(resource.getCount()); } for (Entry entryResource : resource.getEntries()) { entitySet.addEntity(getODataEntity(entryResource)); } return entitySet; }
From source file:ca.uhn.fhir.model.primitive.UriDt.java
private String normalize(String theValue) { if (theValue == null) { return null; }// ww w.j av 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(); }
From source file:org.sakaiproject.shortenedurl.impl.RandomisedUrlService.java
/** * Encodes a full URL./*w w w . ja v a 2 s. c om*/ * * @param rawUrl the URL to encode. */ private String encodeUrl(String rawUrl) { if (StringUtils.isBlank(rawUrl)) { return null; } String encodedUrl = null; try { URL url = new URL(rawUrl); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); encodedUrl = uri.toASCIIString(); } catch (Exception e) { log.warn("encoding url: " + rawUrl + ", " + e.getMessage(), e); } return encodedUrl; }
From source file:hsyndicate.rest.client.SyndicateUGHttpClient.java
private void initialize(URI serviceURI, String sessionName, String sessionKey, API_CALL api_call) { if (serviceURI == null) { throw new IllegalArgumentException("serviceURI is null"); }/*from w w w . ja v a 2 s. c om*/ LOG.info("connect to " + serviceURI.toASCIIString()); this.serviceURI = serviceURI; this.sessionName = sessionName; this.sessionKey = sessionKey; this.client = new RestfulClient(serviceURI, sessionName, sessionKey); this.api_call = api_call; }
From source file:org.koiroha.jyro.workers.crawler.Crawler.java
/** * Retrieve content of specified object. * * @param content content to retrieve/*from w w w .j av a 2 s .c o m*/ * @throws WorkerException if fail to retrieve */ private Content retrieveContent(URI uri, URI referer) throws IOException { // execute request HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(uri); request.setHeader("User-Agent", userAgent); if (referer != null) { request.setHeader("Referer", referer.toASCIIString()); } HttpResponse response = null; String contentType = null; byte[] binary = null; InputStream in = null; try { // read response content response = client.execute(request); HttpEntity entity = response.getEntity(); if (entity != null) { Header header = entity.getContentType(); if (header != null) { contentType = header.getValue(); } // read content in = entity.getContent(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; long remaining = maxContentLength; while (true) { int len = (int) Math.min(buffer.length, remaining); len = in.read(buffer, 0, len); if (len < 0) { break; } out.write(buffer, 0, len); remaining -= len; } binary = out.toByteArray(); } } finally { IO.close(in); } Content content = new Content(uri); Content.Request req = new Content.Request(request.getRequestLine().getMethod(), URI.create(request.getRequestLine().getUri()), request.getRequestLine().getProtocolVersion().toString()); Content.Response res = new Content.Response(response.getStatusLine().getProtocolVersion().toString(), response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); return null; }
From source file:org.opensaml.ws.soap.client.HTTPSOAPTransport.java
/** {@inheritDoc} */ public void send(URI endpointURI, MessageContext messageContext) throws TransportException { try {//from w w w.j a v a2 s.co m PostMethod postMethod = new PostMethod(endpointURI.toASCIIString()); PostMethodHttpOutTransport outTransport = new PostMethodHttpOutTransport(postMethod); messageContext.setOutboundMessageTransport(outTransport); messageEncoder.encode(messageContext); httpClient.executeMethod(postMethod); PostMethodHttpInTransport inTransport = new PostMethodHttpInTransport(postMethod); messageContext.setInboundMessageTransport(inTransport); messageDecoder.decode(messageContext); } catch (IOException e) { throw new TransportException("Unable to establish connection to peer", e); } catch (MessageEncodingException e) { throw new TransportException("Unable to encode message onto outbound transport", e); } catch (MessageDecodingException e) { throw new TransportException("Unable to decode message from inbound transport", e); } catch (SecurityException e) { throw new TransportException("Inbound transport and response did not meet security policy requirements", e); } }
From source file:mecard.security.PAPISecurity.java
/** * Used to get a signature for special HTTP X-header. Used in public PAPI web service * methods. Since public methods don't take a authentication token in the rest request * you must supply a special X-header (X-PAPI-AccessToken) which is the hash of the * HTTP method, URI, and Access Secret.//from www . j a v a2s.c o m * * Using Public Methods as an Authenticated Staff User * In some scenarios, as an authenticated staff user, you may want to call a public method that requires the * patrons password. Instead of looking up the patrons password, you may build the authentication * signature using the AccessSecret. Because the public method does not contain the AccessToken in the URI, * you simply pass in a custom HTTP header field called X-PAPI-AccessToken. The PAPI Service will look * for the X-PAPI-AccessToken header field and act accordingly. * Note: * This process may fail to work if a firewall or network device is configured to remove non-standard HTTP header * fields. * * @param HTTPMethod POST, or GET * @param uri the authentication URI, like 'http://localhost/PAPIService/REST/public/v1/1033/100/1/patron' * @return the signature used on the end of the Authorization HTTP header. */ public String getXPAPIAccessTokenHeader(String HTTPMethod, URI uri) { // Authorization - PWS [PAPIAccessKeyID]:[Signature] // PWS must be in caps // No space before or after : // [PAPIAccessKeyID] - Assigned by Polaris // [Signature] - The signature is the following, encoded with SHA1 UTF-8: // [HTTPMethod][URI][Date][PatronPassword] String signature = this.getPAPIHash(this.PAPISecret, // From the properties file. HTTPMethod, uri.toASCIIString(), this.getPolarisDate(), ""); return "PWS " + this.PAPIAccessKeyId + ":" + signature; }