List of usage examples for java.net URI toASCIIString
public String toASCIIString()
From source file:org.sonatype.nexus.repository.httpclient.HttpClientFactoryImpl.java
private void applyRequestExecutor(final Builder builder, final String userAgent, final String urlParameters) { if (userAgent != null || urlParameters != null) { builder.getHttpClientBuilder().setRequestExecutor(new HttpRequestExecutor() { @Override//from w ww .j a va 2 s. c o m public void preProcess(final HttpRequest request, final HttpProcessor processor, final HttpContext ctx) throws HttpException, IOException { if (userAgent != null) { // NEXUS-7575: In case of HTTP Proxy tunnel, add generic UA while performing CONNECT if (!request.containsHeader(HTTP.USER_AGENT)) { request.addHeader(new BasicHeader(HTTP.USER_AGENT, userAgent)); } } super.preProcess(request, processor, ctx); } @Override public HttpResponse execute(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException { HttpResponse response = null; if (urlParameters != null) { HttpRequestWrapper wrappedRequest = HttpRequestWrapper.wrap(request); URI uri = wrappedRequest.getURI(); if (uri != null) { String uriString = uri.toASCIIString(); try { wrappedRequest.setURI( new URI(uriString + (uri.getQuery() == null ? "?" : "&") + urlParameters)); } catch (URISyntaxException e) { throw new HttpException( "Unable to add url parameters " + urlParameters + " to " + uriString, e); } response = super.execute(wrappedRequest, conn, context); } } if (response == null) { response = super.execute(request, conn, context); } return response; } }); } }
From source file:org.apache.olingo.client.core.communication.request.AsyncRequestWrapperImpl.java
@Override public final AsyncRequestWrapper<R> callback(URI url) { extendHeader(HttpHeader.PREFER, new ODataPreferences().callback(url.toASCIIString())); return this; }
From source file:org.apache.olingo.commons.core.serialization.JsonDeltaDeserializer.java
protected ResWrap<Delta> doDeserialize(final JsonParser parser) throws IOException { final ObjectNode tree = parser.getCodec().readTree(parser); final DeltaImpl delta = new DeltaImpl(); final URI contextURL = tree.hasNonNull(Constants.JSON_CONTEXT) ? URI.create(tree.get(Constants.JSON_CONTEXT).textValue()) : null;//from w ww . j a v a 2 s . c o m if (contextURL != null) { delta.setBaseURI(StringUtils.substringBefore(contextURL.toASCIIString(), Constants.METADATA)); } if (tree.hasNonNull(jsonCount)) { delta.setCount(tree.get(jsonCount).asInt()); } if (tree.hasNonNull(jsonNextLink)) { delta.setNext(URI.create(tree.get(jsonNextLink).textValue())); } if (tree.hasNonNull(jsonDeltaLink)) { delta.setDeltaLink(URI.create(tree.get(jsonDeltaLink).textValue())); } if (tree.hasNonNull(Constants.VALUE)) { JsonEntityDeserializer entityDeserializer = new JsonEntityDeserializer(version, 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, DeletedEntityImpl.class)); } else if (itemContextURL.isDeltaLink()) { delta.getAddedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class)); } else if (itemContextURL.isDeltaDeletedLink()) { delta.getDeletedLinks().add(parser.getCodec().treeToValue(item, DeltaLinkImpl.class)); } } } return new ResWrap<Delta>(contextURL, null, delta); }
From source file:org.apache.activemq.network.MQTTNetworkOfBrokersFailoverTest.java
private CountDownLatch listenForConsumersOn(BrokerService broker) throws Exception { final CountDownLatch latch = new CountDownLatch(1); URI brokerUri = broker.getVmConnectorURI(); final ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerUri.toASCIIString()); final Connection connection = cf.createConnection(); connection.start();/* www. j ava2 s . c om*/ final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination dest = session .createTopic("ActiveMQ.Advisory.Consumer.Queue.Consumer.foo:AT_LEAST_ONCE.VirtualTopic.foo.bar"); MessageConsumer consumer = session.createConsumer(dest); consumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message message) { latch.countDown(); // shutdown this connection Dispatch.getGlobalQueue().execute(new Runnable() { @Override public void run() { try { session.close(); connection.close(); } catch (JMSException e) { e.printStackTrace(); } } }); } }); return latch; }
From source file:com.redblackit.web.server.mvc.UrlChildLocation.java
/** * Method to return a location URL for child by appending the childId to the parent URl, * relying on the childId toString() method. If the supplied childId is * null, it returns the parent URL as-is. * * @return location URL/* w ww . ja va 2s.c o m*/ */ public String getLocationUrl() { final String locationUrl; if (childId == null) { locationUrl = requestUrl; } else { URI childUri = new UriTemplate("{parentURL}/{childId}").expand( (requestUrl.endsWith("/") ? requestUrl.substring(0, requestUrl.length() - 1) : requestUrl), childId); locationUrl = childUri.toASCIIString(); } return locationUrl; }
From source file:com.netflix.genie.agent.execution.services.impl.FetchingCacheServiceImpl.java
@VisibleForTesting String getResourceCacheId(final URI uri) { return DigestUtils.md5DigestAsHex(uri.toASCIIString().getBytes(StandardCharsets.UTF_8)); }
From source file:org.eclipse.jetty.demo.Main.java
/** * Create Default Servlet (must be named "default") *//* www . ja v a 2 s .c o m*/ private ServletHolder defaultServletHolder(URI baseUri) { ServletHolder holderDefault = new ServletHolder("default", DefaultServlet.class); LOG.info("Base URI: " + baseUri); holderDefault.setInitParameter("resourceBase", baseUri.toASCIIString()); holderDefault.setInitParameter("dirAllowed", "true"); return holderDefault; }
From source file:org.jclouds.libvirt.compute.domain.LibvirtComputeServiceContextModule.java
@Provides @Singleton//from w w w.j av a 2s . c om protected Connect createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException { // ConnectAuth connectAuth = null; return new Connect(endpoint.toASCIIString()); }
From source file:com.meetme.plugins.jira.gerrit.webpanel.GerritReviewsIssueLeftPanel.java
@Override public Map<String, Object> getContextMap(Map<String, Object> context) { setUpRequestParams(context);//from w w w.j a v a 2 s. c om final Issue issue = (Issue) context.get(KEY_ISSUE); final MapBuilder<String, Object> paramsBuilder = MapBuilder.newBuilder(context); // determine which one is checked? final String gerritIssueType = getGerritIssueType(); final String gerritIssueStatus = getGerritIssueStatus(); final String gerritReviewStatus = getGerritReviewStatus(); log.debug("issuetype=" + gerritIssueType + ", issuestatus=" + gerritIssueStatus + ", reviewstatus=" + gerritReviewStatus); paramsBuilder.add("gerritIssueType", gerritIssueType); // Gerrit 2.5 introduces Dashboards. Provide an easy-to-access Dashboard fragment URI baseUri = this.config.getHttpBaseUrl(); if (baseUri != null) { String baseUrl = baseUri.toASCIIString(); if (!StringUtils.isBlank(baseUrl)) { String searchQuery = String.format(this.config.getIssueSearchQuery(), issue.getKey()); String part = String.format("&For+%s=%s", issue.getKey(), searchQuery); paramsBuilder.add("dashboardUrl", baseUrl + "#/dashboard/?title=From+JIRA" + part); paramsBuilder.add("dashboardPart", part); paramsBuilder.add("dashboardKey", issue.getKey()); } } List<GerritChange> changes = new ArrayList<GerritChange>(); try { if (IssueTypeOptionsFactory.wantsIssue(gerritIssueType) && (IssueStatusOptionsFactory.wantsUnresolved(gerritIssueStatus) || IssueStatusOptionsFactory.isIssueOpen(issue))) { addIssueChanges(changes, issue); } if (IssueTypeOptionsFactory.wantsSubtasks(gerritIssueType)) { addSubtaskChanges(changes, issue, gerritIssueStatus); } if (!ReviewStatusOptionsFactory.wantsClosedReviews(gerritReviewStatus)) { removeClosedReviews(changes); } Collections.sort(changes); paramsBuilder.add(KEY_CHANGES, changes); } catch (GerritQueryException e) { paramsBuilder.add(KEY_ERROR, e.getMessage()); } log.debug("Showing changes: " + changes); return paramsBuilder.toMap(); }
From source file:edu.si.services.sidora.rest.batch.beans.BatchRequestControllerBean.java
/** * Check Resource MimeType using Apache Tika * @param exchange/*from w w w.ja v a2s .c o m*/ * @throws URISyntaxException * @throws MalformedURLException */ public void getMIMEType(Exchange exchange) throws URISyntaxException, MalformedURLException { /** * TODO: * * Need to make sure that mimetypes are consistent with what's used in workbench. * See link for workbench mimetype list * * https://github.com/Smithsonian/sidora-workbench/blob/master/workbench/includes/utils.inc#L1119 * */ out = exchange.getIn(); URL url = new URL(out.getHeader("resourceFile", String.class)); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); String resourceFile = uri.toASCIIString(); String resourceFileExt = FilenameUtils.getExtension(resourceFile); String mimeType = null; if (resourceFileExt.equalsIgnoreCase("nef")) { mimeType = "image/x-nikon-nef"; } else if (resourceFileExt.equalsIgnoreCase("dng")) { mimeType = "image/x-adobe-dng"; } else { LOG.debug("Checking {} for MIME Type", resourceFile); mimeType = new Tika().detect(resourceFile); } LOG.debug("Batch Process " + resourceFile + " || MIME=" + mimeType); out.setHeader("dsMIME", mimeType); }