List of usage examples for java.net URI getQuery
public String getQuery()
From source file:com.collective.celos.ci.deploy.WorkflowFilesDeployer.java
URI getTargetJsFileUri(URI uri) throws URISyntaxException { String path = uri.getPath() + File.separator + config.getWorkflowName() + ".js"; return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(), uri.getFragment());/*from w ww. j av a 2s. com*/ }
From source file:org.ambraproject.wombat.service.remote.AbstractRemoteService.java
@Override public CloseableHttpResponse getResponse(HttpUriRequest target) throws IOException { // Don't close the client, as this shuts down the connection pool. Do close every response or its entity stream. CloseableHttpClient client = createClient(); // We want to return an unclosed response, so close the response only if we throw an exception. boolean returningResponse = false; CloseableHttpResponse response = null; try {/*from www.jav a 2s. co m*/ try { response = client.execute(target); } catch (HttpHostConnectException e) { throw new ServiceConnectionException(e); } StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (isErrorStatus(statusCode)) { URI targetUri = target.getURI(); String address = targetUri.getPath(); if (!Strings.isNullOrEmpty(targetUri.getQuery())) { address += "?" + targetUri.getQuery(); } if (statusCode == HttpStatus.NOT_FOUND.value()) { throw new EntityNotFoundException(address); } else { String responseBody = IOUtils.toString(response.getEntity().getContent()); String message = String.format("Request to \"%s\" failed (%d): %s.", address, statusCode, statusLine.getReasonPhrase()); throw new ServiceRequestException(statusCode, message, responseBody); } } returningResponse = true; return response; } finally { if (!returningResponse && response != null) { response.close(); } } }
From source file:co.mcme.barry.listeners.ChatListener.java
@EventHandler(priority = EventPriority.MONITOR) public void onYTChat(AsyncPlayerChatEvent event) { String message = event.getMessage(); for (String str : message.split(" ")) { Matcher matcher = url.matcher(str); if (matcher.matches()) { try { URI uri = new URI(str); if (uri.getHost().contains("youtube.com")) { if (uri.getQuery().contains("v=")) { String id = uri.getQuery().replaceAll("v=", ""); String daturl = "http://gdata.youtube.com/feeds/api/videos/" + id + "?alt=json"; YoutubeVideo video = UrlWatcher.getYoutubeInfo(daturl); BarryPlugin.sendGlobalMessage(video.getMessageForTitle()); BarryPlugin.sendGlobalMessage(video.getMessageForDurationLinker(event.getPlayer())); }/*from w w w .j a v a 2 s . c o m*/ } else if (uri.getHost().contains("youtu.be")) { String[] split = str.split(".be/"); String id = split[1]; String daturl = "http://gdata.youtube.com/feeds/api/videos/" + id + "?alt=json"; YoutubeVideo video = UrlWatcher.getYoutubeInfo(daturl); BarryPlugin.sendGlobalMessage(video.getMessageForTitle()); BarryPlugin.sendGlobalMessage(video.getMessageForDurationLinker(event.getPlayer())); } } catch (URISyntaxException ex) { } } } }
From source file:ste.web.http.velocity.VelocityHandler.java
/** * Creates a velocity context filling it with all request parameters and * attributes (the former overwrite the latter). * * @param request the request to create the context upon * * @return the newly created context//w w w. j a va2s.co m */ private VelocityContext buildContext(HttpRequest request, HttpSessionContext httpContext) { VelocityContext context = new VelocityContext(); for (String name : httpContext.keySet()) { context.put(name, httpContext.getAttribute(name)); } try { URI uri = new URI(request.getRequestLine().getUri()); QueryString qs = QueryString.parse(uri.getQuery()); for (String name : qs.getNames()) { context.put(name, qs.get(name)); } } catch (URISyntaxException x) { // // if the URL is marformed, there is nothing to do here... // } return context; }
From source file:com.subgraph.vega.impl.scanner.urls.UriParser.java
private void processPath(IWebPath webPath, URI uri, boolean isLast, boolean hasTrailingSlash) { if (!isLast || (isLast && hasTrailingSlash)) { processDirectory(webPath);// w ww. j a v a 2 s . c om } else if (uri.getQuery() != null) { processPathWithQuery(webPath, uri); } else { processUnknown(webPath); } }
From source file:net.bluemix.todo.connector.CloudantServiceInfoCreator.java
@Override public CloudantServiceInfo createServiceInfo(Map<String, Object> serviceData) { Map<String, Object> credentials = (Map<String, Object>) serviceData.get("credentials"); String id = (String) serviceData.get("name"); try {/*from w w w . java 2 s.com*/ URI uri = new URI((String) credentials.get("url")); String scheme = uri.getScheme(); int port = uri.getPort(); String host = uri.getHost(); String path = uri.getPath(); String query = uri.getQuery(); String fragment = uri.getFragment(); String url = new URI(scheme, "", host, port, path, query, fragment).toString(); String[] userInfo = uri.getUserInfo().split(":"); return new CloudantServiceInfo(id, userInfo[0], userInfo[1], url); } catch (URISyntaxException e) { return null; } }
From source file:org.apache.pig.tools.DownloadResolver.java
/** * @param uri/*ww w.j a va 2 s .c om*/ * @return A map of all Query String Parameters */ private Map<String, String> parseQueryString(URI uri) { Map<String, String> paramMap = new HashMap<String, String>(); String queryString = uri.getQuery(); if (queryString != null) { String queryParams[] = queryString.split("&"); for (String param : queryParams) { String[] parts = param.split("="); if (parts.length == 2) { String name = parts[0].toLowerCase(); String value = parts[1]; paramMap.put(name, value); } } } return paramMap; }
From source file:org.apache.servicemix.jms.JmsComponent.java
protected Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception { // We receive an exchange for an EPR that has not been used yet. // Register a provider endpoint and restart processing. JmsEndpoint jmsEp = new JmsEndpoint(true); jmsEp.setServiceUnit(new DefaultServiceUnit(component)); jmsEp.setService(ep.getServiceName()); jmsEp.setEndpoint(ep.getEndpointName()); jmsEp.setRole(MessageExchange.Role.PROVIDER); URI uri = new URI(ep.getEndpointName()); Map map = URISupport.parseQuery(uri.getQuery()); if (IntrospectionSupport.setProperties(jmsEp, map, "jms.")) { uri = URISupport.createRemainingURI(uri, map); }/* w ww . j a va 2 s .c o m*/ if (uri.getPath() != null) { String path = uri.getSchemeSpecificPart(); while (path.startsWith("/")) { path = path.substring(1); } if (path.startsWith(AbstractJmsProcessor.STYLE_QUEUE + "/")) { jmsEp.setDestinationStyle(AbstractJmsProcessor.STYLE_QUEUE); jmsEp.setJmsProviderDestinationName(path.substring(AbstractJmsProcessor.STYLE_QUEUE.length() + 1)); } else if (path.startsWith(AbstractJmsProcessor.STYLE_TOPIC + "/")) { jmsEp.setDestinationStyle(AbstractJmsProcessor.STYLE_TOPIC); jmsEp.setJmsProviderDestinationName(path.substring(AbstractJmsProcessor.STYLE_TOPIC.length() + 1)); } } return jmsEp; }
From source file:com.microsoft.live.UploadRequestTest.java
/** * WinLive 633441: Make sure the query parameters on path get sent to * the HTTP PUT part of the upload.//from w w w.j ava 2 s .co m */ public void testSendPathQueryParameterToHttpPut() throws Throwable { JSONObject jsonResponseBody = new JSONObject(); jsonResponseBody.put(JsonKeys.UPLOAD_LOCATION, "http://test.com/location"); InputStream responseStream = new ByteArrayInputStream(jsonResponseBody.toString().getBytes()); MockHttpEntity responseEntity = new MockHttpEntity(responseStream); BasicStatusLine ok = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, ""); final MockHttpResponse uploadLocationResponse = new MockHttpResponse(responseEntity, ok); HttpClient client = new HttpClient() { /** the first request to the client is the upload location request. */ boolean uploadLocationRequest = true; @Override public HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException { if (uploadLocationRequest) { uploadLocationRequest = false; return uploadLocationResponse; } // This is really the only part we care about in this test. // That the 2nd request's uri has foo=bar in the query string. URI uri = request.getURI(); assertEquals("foo=bar&overwrite=choosenewname", uri.getQuery()); // for the test it doesn't matter what it contains, as long as it has valid json. // just return the previous reponse. return uploadLocationResponse; } @Override public HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public <T> T execute(HttpUriRequest arg0, ResponseHandler<? extends T> arg1) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public <T> T execute(HttpUriRequest arg0, ResponseHandler<? extends T> arg1, HttpContext arg2) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public <T> T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler<? extends T> arg2) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public <T> T execute(HttpHost arg0, HttpRequest arg1, ResponseHandler<? extends T> arg2, HttpContext arg3) throws IOException, ClientProtocolException { throw new UnsupportedOperationException(); } @Override public ClientConnectionManager getConnectionManager() { throw new UnsupportedOperationException(); } @Override public HttpParams getParams() { throw new UnsupportedOperationException(); } }; LiveConnectSession session = TestUtils.newMockLiveConnectSession(); HttpEntity entity = new MockHttpEntity(); String path = Paths.ME_SKYDRIVE + "?foo=bar"; String filename = "filename"; UploadRequest uploadRequest = new UploadRequest(session, client, path, entity, filename, OverwriteOption.Rename); uploadRequest.execute(); }
From source file:org.apache.activemq.artemis.utils.uri.URISchema.java
/** * It will create a new Object for the URI selected schema. * the propertyOverrides is used to replace whatever was defined on the URL string * @param uri The URI//from w ww . j av a 2s . com * @param propertyOverrides used to replace whatever was defined on the URL string * @return new Object * @throws Exception On error */ public T newObject(URI uri, Map<String, String> propertyOverrides, P param) throws Exception { return internalNewObject(uri, parseQuery(uri.getQuery(), propertyOverrides), param); }