List of usage examples for java.net URI toASCIIString
public String toASCIIString()
From source file:org.apache.olingo.client.core.serialization.JsonDeltaDeserializer.java
protected ResWrap<Delta> doDeserialize(final JsonParser parser) throws IOException { final ObjectNode tree = parser.getCodec().readTree(parser); final Delta delta = new Delta(); final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ? URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null;//from w ww .ja va 2 s .c om if (contextURL != null) { delta.setBaseURI( URI.create(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA))); } if (tree.hasNonNull(Constants.JSON_COUNT)) { delta.setCount(tree.get(Constants.JSON_COUNT).asInt()); } if (tree.hasNonNull(Constants.JSON_NEXT_LINK)) { delta.setNext(URI.create(tree.get(Constants.JSON_NEXT_LINK).textValue())); } if (tree.hasNonNull(Constants.JSON_DELTA_LINK)) { delta.setDeltaLink(URI.create(tree.get(Constants.JSON_DELTA_LINK).textValue())); } if (tree.hasNonNull(Constants.VALUE)) { JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(serverMode); for (JsonNode jsonNode : tree.get(Constants.VALUE)) { final ObjectNode item = (ObjectNode) jsonNode; final ContextURL itemContextURL = item.hasNonNull(Constants.JSON_CONTEXT) ? ContextURLParser.parse(URI.create(item.get(Constants.JSON_CONTEXT).textValue())) : null; item.remove(Constants.JSON_CONTEXT); if (itemContextURL == null || itemContextURL.isEntity()) { delta.getEntities() .add(entityDeserializer.doDeserialize(item.traverse(parser.getCodec())).getPayload()); } else if (itemContextURL.isDeltaDeletedEntity()) { delta.getDeletedEntities().add(parser.getCodec().treeToValue(item, DeletedEntity.class)); } else if (itemContextURL.isDeltaLink()) { delta.getAddedLinks().add(parser.getCodec().treeToValue(item, DeltaLink.class)); } else if (itemContextURL.isDeltaDeletedLink()) { delta.getDeletedLinks().add(parser.getCodec().treeToValue(item, DeltaLink.class)); } } } return new ResWrap<Delta>(contextURL, null, delta); }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.GmdConverter.java
protected void addDistributionInfo(MetacardImpl metacard, XstreamPathValueTracker pathValueTracker) { String resourceUrl = null;/*from w w w . j ava 2s. c o m*/ Attribute downloadUrlAttr = metacard.getAttribute(Metacard.RESOURCE_DOWNLOAD_URL); if (downloadUrlAttr != null) { resourceUrl = (String) downloadUrlAttr.getValue(); } if (StringUtils.isNotBlank(resourceUrl)) { pathValueTracker.add(new Path(GmdMetacardType.LINKAGE_URI_PATH), resourceUrl); } else { URI resourceUri = metacard.getResourceURI(); if (resourceUri != null) { pathValueTracker.add(new Path(GmdMetacardType.LINKAGE_URI_PATH), resourceUri.toASCIIString()); } } }
From source file:cn.openwatch.internal.http.loopj.AsyncHttpClient.java
/** * Will encode url, if not disabled, and adds params on the end of it * * @param url String with URL, should be valid URL without params * @param params RequestParams to be appended on the end of URL * @param shouldEncodeUrl whether url should be encoded (replaces spaces with %20) * @return encoded url if requested with params appended if any available */// www. j ava 2 s. com public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url, RequestParams params) { if (url == null) return null; if (shouldEncodeUrl) { try { String decodedURL = URLDecoder.decode(url, "UTF-8"); URL _url = new URL(decodedURL); URI _uri = new URI(_url.getProtocol(), _url.getUserInfo(), _url.getHost(), _url.getPort(), _url.getPath(), _url.getQuery(), _url.getRef()); url = _uri.toASCIIString(); } catch (Exception ex) { // Should not really happen, added just for sake of validity } } if (params != null) { // Construct the query string and trim it, in case it // includes any excessive white spaces. String paramString = params.getParamString().trim(); // Only add the query string if it isn't empty and it // isn't equal to '?'. if (!paramString.equals("") && !paramString.equals("?")) { url += url.contains("?") ? "&" : "?"; url += paramString; } } return url; }
From source file:nl.flotsam.calendar.web.UriHttpMessageConverter.java
@Override protected void writeInternal(URI uri, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { OutputStream out = null;/* w ww . j a v a2 s . c o m*/ try { out = outputMessage.getBody(); if (MediaType.APPLICATION_FORM_URLENCODED == outputMessage.getHeaders().getContentType()) { IOUtils.write(URLEncoder.encode(uri.toASCIIString(), "UTF-8"), out, "US-ASCII"); } else { IOUtils.write(uri.toASCIIString(), out, "US-ASCII"); } } finally { IOUtils.closeQuietly(out); } }
From source file:org.callimachusproject.client.HttpClientRedirectTest.java
/** * The interpreted (absolute) URI that was used to generate the last * request.//from w w w . ja va2 s .c om */ private URI getHttpLocation(HttpUriRequest originalRequest, HttpClientContext ctx) { try { URI original = originalRequest.getURI(); HttpHost target = ctx.getTargetHost(); List<URI> redirects = ctx.getRedirectLocations(); URI absolute = URIUtils.resolve(original, target, redirects); return new URI(TermFactory.newInstance(absolute.toASCIIString()).getSystemId()); } catch (URISyntaxException e) { return null; } }
From source file:org.apache.olingo.client.core.communication.request.v4.AsyncRequestWrapperImpl.java
@Override public final AsyncRequestWrapper<R> callback(URI url) { extendHeader(HeaderName.prefer.toString(), new ODataPreferences(ODataServiceVersion.V40).callback(url.toASCIIString())); return this; }
From source file:org.trancecode.xproc.binding.DataPortBinding.java
private void writeContent(final SaxonBuilder builder) { final URI uri = URI.create(href); if (uri.getScheme() != null && !StringUtils.equals("file", uri.getScheme()) && !StringUtils.equals("http", uri.getScheme())) { throw XProcExceptions.xd0012(this.getLocation(), uri.toASCIIString()); }/*from w w w .j av a 2 s. c o m*/ try { final URL url; if (uri.isAbsolute()) { url = uri.toURL(); } else { url = node.getBaseURI().resolve(uri).toURL(); } final QName contentTypeAtt = (wrapper == null) ? XProcXmlModel.Attributes.CONTENT_TYPE : XProcXmlModel.Attributes.C_CONTENT_TYPE; final QName encodingAtt = (wrapper == null) ? XProcXmlModel.Attributes.ENCODING : XProcXmlModel.Attributes.C_ENCODING; final URLConnection urlConnection = url.openConnection(); final ContentType guessContentType; if (StringUtils.equals("http", url.getProtocol())) { guessContentType = Steps.getContentType(urlConnection.getContentType(), node); } else { if (contentType != null) { guessContentType = contentType; } else { guessContentType = Steps .getContentType("application/octet-stream ; encoding=" + Steps.ENCODING_BASE64, node); } } final Charset charset; if (contentType != null && contentType.getParameter("charset") != null) { charset = Charset.forName(contentType.getParameter("charset")); } else { charset = Charset.forName("UTF-8"); } final InputStream stream = urlConnection.getInputStream(); builder.attribute(contentTypeAtt, Steps.contentTypeToString(guessContentType)); if (StringUtils.equals("text", guessContentType.getPrimaryType()) || StringUtils.contains(guessContentType.getSubType(), "xml")) { if (guessContentType.getParameter("encoding") != null) { builder.attribute(encodingAtt, guessContentType.getParameter("encoding")); } builder.startContent(); builder.text(IOUtils.toString(stream, charset.name())); } else { builder.attribute(encodingAtt, Steps.ENCODING_BASE64); builder.startContent(); builder.text(Base64.encodeBytes(IOUtils.toByteArray(stream), Base64.DO_BREAK_LINES)); } } catch (final IOException ioe) { throw XProcExceptions.xd0029(this.getLocation()); } }
From source file:org.trancecode.xproc.step.HttpRequestStepProcessor.java
@Override protected void execute(final StepInput input, final StepOutput output) { final XdmNode sourceDoc = input.readNode(XProcPorts.SOURCE); final XdmNode request = SaxonAxis.childElement(sourceDoc); if (!XProcXmlModel.Elements.REQUEST.equals(request.getNodeName())) { throw XProcExceptions.xc0040(input.getStep().getLocation()); }/*from w w w .j a va 2s . c o m*/ final Map<QName, Object> serializationOptions = Steps.getSerializationOptions(input, DEFAULT_SERIALIZATION_OPTIONS); LOG.trace(" serializationOptions = {}", serializationOptions); final RequestParser parser = new RequestParser(serializationOptions); final Processor processor = input.getPipelineContext().getProcessor(); final XProcHttpRequest xProcRequest = parser.parseRequest(request, processor); final URI uri = xProcRequest.getHttpRequest().getURI(); if (uri.getScheme() != null && !StringUtils.equals("file", uri.getScheme()) && !StringUtils.equals("http", uri.getScheme())) { throw XProcExceptions.xd0012(input.getLocation(), uri.toASCIIString()); } final BasicHttpContext localContext = new BasicHttpContext(); final HttpClient httpClient = prepareHttpClient(xProcRequest, localContext); try { final ResponseHandler<XProcHttpResponse> responseHandler = new HttpResponseHandler(processor, xProcRequest.isDetailled(), xProcRequest.isStatusOnly(), xProcRequest.getOverrideContentType()); final XProcHttpResponse response = httpClient.execute(xProcRequest.getHttpRequest(), responseHandler, localContext); final SaxonBuilder builder = new SaxonBuilder(processor.getUnderlyingConfiguration()); builder.startDocument(); if (response.getNodes() != null) { builder.nodes(response.getNodes()); } builder.endDocument(); output.writeNodes(XProcPorts.RESULT, builder.getNode()); } catch (final IOException e) { // TODO e.printStackTrace(); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:io.cloudslang.content.httpclient.consume.FinalLocationConsumer.java
public void consume(Map<String, String> returnResult) { URI location; try {//from ww w. j a va 2s. c o m location = URIUtils.resolve(uri, targetHost, redirectLocations); } catch (URISyntaxException e) { //this is not a fatal error throw new IllegalArgumentException( "could not determine '" + CSHttpClient.FINAL_LOCATION + "': " + e.getMessage(), e); } returnResult.put(CSHttpClient.FINAL_LOCATION, location.toASCIIString()); }
From source file:com.microsoft.tfs.core.clients.reporting.ReportingClient.java
/** * <p>//from ww w . j a v a 2 s . c o m * TEE will automatically correct the endpoints registered URL when creating * the web service, however we must provide a mechansim to correct fully * qualified URI's provided as additional URI from the same webservice. * </p> * <p> * We compare the passed uri with the registered web service endpoint, if * they share the same root (i.e. http://TFSERVER) then we correct the * passed uri to be the same as the corrected web service enpoint (i.e. * http://tfsserver.mycompany.com) * </p> * * @see WSSClient#getFixedURI(String) */ public String getFixedURI(final String uri) { Check.notNull(uri, "uri"); //$NON-NLS-1$ try { // Get what the server thinks the url is. String url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE, ServiceInterfaceNames.REPORTING); if (url == null || url.length() == 0) { // Might be a Rosario server url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE, ServiceInterfaceNames.REPORTING_WEB_SERVICE_URL); if (url == null || url.length() == 0) { // Couldn't figure this out - just give up and return what // we // were passed. return uri; } is2010Server = true; } final URI registeredEndpointUri = new URI(url); final URI passedUri = new URI(uri); if (passedUri.getScheme().equals(registeredEndpointUri.getScheme()) && passedUri.getHost().equals(registeredEndpointUri.getHost()) && passedUri.getPort() == registeredEndpointUri.getPort()) { final URI endpointUri = ((SOAPService) getProxy()).getEndpoint(); final URI fixedUri = new URI(endpointUri.getScheme(), endpointUri.getHost(), passedUri.getPath(), passedUri.getQuery(), passedUri.getFragment()); return fixedUri.toASCIIString(); } } catch (final URISyntaxException e) { // ignore; } return uri; }