List of usage examples for java.net URI getQuery
public String getQuery()
From source file:com.gsma.mobileconnect.impl.DiscoveryImpl.java
/** * See {@link IDiscovery#parseDiscoveryRedirect(String, IParsedDiscoveryRedirectCallback)} *//*from www .j a v a 2 s . c o m*/ public void parseDiscoveryRedirect(String redirectURL, IParsedDiscoveryRedirectCallback callback) throws URISyntaxException { ValidationUtils.validateParameter(redirectURL, "redirectURL"); ValidationUtils.validateParameter(callback, "callback"); URI uri = new URI(redirectURL); String query = uri.getQuery(); if (null == query) { callback.completed(new ParsedDiscoveryRedirect(null, null, null)); return; } List<NameValuePair> parameters = URLEncodedUtils.parse(uri.getQuery(), null); String mcc_mnc = HttpUtils.getParameterValue(parameters, Constants.MCC_MNC_PARAMETER_NAME); String subscriber_id = HttpUtils.getParameterValue(parameters, Constants.SUBSCRIBER_ID_PARAMETER_NAME); String mcc = null; String mnc = null; if (null != mcc_mnc) { String[] parts = mcc_mnc.split("_"); if (parts.length == 2) { mcc = parts[0]; mnc = parts[1]; } } callback.completed(new ParsedDiscoveryRedirect(mcc, mnc, subscriber_id)); }
From source file:org.apache.stratos.integration.common.extensions.StratosServerExtension.java
private int startActiveMQServer() throws AutomationFrameworkException { try {/* w ww . ja va2 s. c o m*/ String activemqBindAddress = getParameters().get(Util.ACTIVEMQ_BIND_ADDRESS); if (activemqBindAddress == null) { throw new AutomationFrameworkException("ActiveMQ bind address not found in automation.xml"); } URI givenURI = new URI(activemqBindAddress); int initAMQPort = givenURI.getPort(); // dynamically pick an open port starting from initial port given in automation.xml while (!Util.isPortAvailable(initAMQPort)) { initAMQPort++; } URI dynamicURL = new URI(givenURI.getScheme(), givenURI.getUserInfo(), givenURI.getHost(), initAMQPort, givenURI.getPath(), givenURI.getQuery(), givenURI.getFragment()); long time1 = System.currentTimeMillis(); log.info("Starting ActiveMQ with dynamic bind address: " + dynamicURL.toString()); broker.setDataDirectory(StratosServerExtension.class.getResource(File.separator).getPath() + File.separator + ".." + File.separator + "activemq-data"); broker.setBrokerName("testBroker"); broker.addConnector(dynamicURL.toString()); broker.start(); long time2 = System.currentTimeMillis(); log.info(String.format("ActiveMQ started in %d sec", (time2 - time1) / 1000)); return initAMQPort; } catch (Exception e) { throw new AutomationFrameworkException("Could not start ActiveMQ", e); } }
From source file:org.eclipse.orion.server.git.objects.Status.java
private URI statusToDiffLocation(URI u, String diffType) throws URISyntaxException { String uriPath = u.getPath(); String prefix = uriPath.substring(0, uriPath.indexOf(GitServlet.GIT_URI)); uriPath = uriPath.substring(prefix.length() + (GitServlet.GIT_URI + '/' + Status.RESOURCE).length()); uriPath = prefix + GitServlet.GIT_URI + '/' + Diff.RESOURCE + '/' + diffType + uriPath; return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), uriPath, u.getQuery(), u.getFragment());// www. j a v a 2s .com }
From source file:org.devnexus.aerogear.RestRunner.java
private HttpProvider getHttpProvider(URI relativeUri) { final String queryString; AuthorizationFields fields = loadAuth(relativeUri, "GET"); if (relativeUri == null || relativeUri.getQuery() == null) { queryString = ""; } else {//from ww w . ja v a 2s .c o m queryString = relativeUri.getQuery().toString(); } URL mergedURL = UrlUtils.appendToBaseURL(baseURL, relativeUri.getPath()); URL authorizedURL = addAuthorization(fields.getQueryParameters(), UrlUtils.appendQueryToBaseURL(mergedURL, queryString)); final HttpProvider httpProvider = httpProviderFactory.get(authorizedURL, timeout); httpProvider.setDefaultHeader("Content-TYpe", requestBuilder.getContentType()); addAuthHeaders(httpProvider, fields); return httpProvider; }
From source file:com.microsoft.tfs.client.common.ui.dialogs.connect.ACSCredentialsDialog.java
protected URI getSignInURI(final URI serverSigninURL) { String query = serverSigninURL.getQuery(); if (query.indexOf("protocol=") < 0) //$NON-NLS-1$ {//from w w w .j a v a 2s . c o m query += "&protocol=javascriptnotify"; //$NON-NLS-1$ } if (query.indexOf("force=") < 0) //$NON-NLS-1$ { query += "&force=1"; //$NON-NLS-1$ } if (query.indexOf("compact=") < 0) //$NON-NLS-1$ { query += "&compact=1"; //$NON-NLS-1$ } return URIUtils.newURI(serverSigninURL.getScheme(), serverSigninURL.getAuthority(), serverSigninURL.getPath(), query, serverSigninURL.getFragment()); }
From source file:org.jvoicexml.documentserver.schemestrategy.HttpSchemeStrategy.java
/** * {@inheritDoc}/* w w w . jav a 2 s . com*/ */ @Override public InputStream getInputStream(final String sessionId, final URI uri, final RequestMethod method, final long timeout, final Collection<KeyValuePair> parameters) throws BadFetchError { final HttpClient client = SESSION_STORAGE.getSessionIdentifier(sessionId); final URI fullUri; try { final URI fragmentLessUri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), uri.getQuery(), null); fullUri = addParameters(parameters, fragmentLessUri); } catch (URISyntaxException e) { throw new BadFetchError(e.getMessage(), e); } catch (SemanticError e) { throw new BadFetchError(e.getMessage(), e); } final String url = fullUri.toString(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("connecting to '" + url + "'..."); } final HttpUriRequest request; if (method == RequestMethod.GET) { request = new HttpGet(url); } else { request = new HttpPost(url); } attachFiles(request, parameters); try { final HttpParams params = client.getParams(); setTimeout(timeout, params); final HttpResponse response = client.execute(request); final StatusLine statusLine = response.getStatusLine(); final int status = statusLine.getStatusCode(); if (status != HttpStatus.SC_OK) { throw new BadFetchError(statusLine.getReasonPhrase() + " (HTTP error code " + status + ")"); } final HttpEntity entity = response.getEntity(); return entity.getContent(); } catch (IOException e) { throw new BadFetchError(e.getMessage(), e); } }
From source file:info.magnolia.ui.admincentral.shellapp.favorites.FavoritesPresenter.java
String getWebAppRootURI() { final URI currentUri = UI.getCurrent().getPage().getLocation(); String instancePrefix = currentUri.getScheme() + "://" + currentUri.getHost(); if (currentUri.getPort() > -1) { instancePrefix += ":" + currentUri.getPort(); }/*from w ww. j a v a2s . c o m*/ instancePrefix += currentUri.getPath(); // Path contains the ctx if (StringUtils.isNotBlank(currentUri.getQuery())) { instancePrefix += "?" + currentUri.getQuery(); } return instancePrefix; }
From source file:com.smartsheet.api.internal.oauth.OAuthFlowImpl.java
/** * Extract AuthorizationResult from the authorization response URL (i.e. the redirectURL with the response * parameters from Smartsheet OAuth server). * * Exceptions:/*from ww w. j a v a 2 s . co m*/ * - IllegalArgumentException : if authorizationResponseURL is null/empty, or a malformed URL * - AccessDeniedException : if the user has denied the authorization request * - UnsupportedResponseTypeException : if the response type isn't supported (note that this won't really happen in current implementation) * - InvalidScopeException : if some of the specified scopes are invalid * - OAuthAuthorizationCodeException : if any other error occurred during the operation * * @param authorizationResponseURL the authorization response URL * @return the authorization result * @throws URISyntaxException the URI syntax exception * @throws OAuthAuthorizationCodeException the o auth authorization code exception */ public AuthorizationResult extractAuthorizationResult(String authorizationResponseURL) throws URISyntaxException, OAuthAuthorizationCodeException { Util.throwIfNull(authorizationResponseURL); Util.throwIfEmpty(authorizationResponseURL); // Get all of the parms from the URL URI uri = new URI(authorizationResponseURL); String query = uri.getQuery(); if (query == null) { throw new OAuthAuthorizationCodeException("There must be a query string in the response URL"); } Map<String, String> map = new HashMap<String, String>(); for (String param : query.split("&")) { int index = param.indexOf('='); map.put(param.substring(0, index), param.substring(index + 1)); } // Check for an error response in the URL and throw it. String error = map.get("error"); if (error != null && !error.isEmpty()) { if ("access_denied".equals(error)) { throw new AccessDeniedException("Access denied."); } else if ("unsupported_response_type".equals(error)) { throw new UnsupportedResponseTypeException("response_type must be set to \"code\"."); } else if ("invalid_scope".equals(error)) { throw new InvalidScopeException("One or more of the requested access scopes are invalid. " + "Please check the list of access scopes"); } else { throw new OAuthAuthorizationCodeException("An undefined error was returned of type: " + error); } } AuthorizationResult authorizationResult = new AuthorizationResult(); authorizationResult.setCode(map.get("code")); authorizationResult.setState(map.get("state")); Long expiresIn; try { expiresIn = Long.parseLong(map.get("expires_in")); } catch (NumberFormatException ex) { expiresIn = 0L; } authorizationResult.setExpiresInSeconds(expiresIn); return authorizationResult; }
From source file:org.apache.ws.scout.transport.RMITransport.java
/** * Sends an element and returns an element. *//*w w w . j a v a 2 s . c o m*/ public Element send(Element request, URI endpointURI) throws TransportException { Element response = null; if (log.isDebugEnabled()) { log.debug("\nRequest message:\n" + XMLUtils.convertNodeToXMLString(request)); log.debug("Calling " + endpointURI + " using rmi"); } try { String host = endpointURI.getHost(); int port = endpointURI.getPort(); String scheme = endpointURI.getScheme(); String service = endpointURI.getPath(); String className = endpointURI.getQuery(); String methodName = endpointURI.getFragment(); Properties env = new Properties(); //It be a lot nicer if this is configured through properties, but for now //I'd like to keep the changes localized, so this seems pretty reasonable. String factoryInitial = SecurityActions.getProperty("java.naming.factory.initial"); if (factoryInitial == null) factoryInitial = "org.jnp.interfaces.NamingContextFactory"; String factoryURLPkgs = SecurityActions.getProperty("java.naming.factory.url.pkgs"); if (factoryURLPkgs == null) factoryURLPkgs = "org.jboss.naming"; env.setProperty("java.naming.factory.initial", factoryInitial); env.setProperty("java.naming.factory.url.pkgs", factoryURLPkgs); env.setProperty("java.naming.provider.url", scheme + "://" + host + ":" + port); log.debug("Initial Context using env=" + env.toString()); InitialContext context = new InitialContext(env); log.debug("Calling service=" + service + ", Class = " + className + ", Method=" + methodName); //Looking up the object (i.e. Publish) Object requestHandler = context.lookup(service); //Loading up the stub Class<?> c = Class.forName(className); //Getting a handle to method we want to call (i.e. publish.publish(Element element)) Method method = c.getMethod(methodName, Element.class); //Calling that method Node node = (Node) method.invoke(requestHandler, request); //The result is in the first element if (node.getFirstChild() != null) { response = (Element) node.getFirstChild(); } } catch (Exception ex) { throw new TransportException(ex); } if (log.isDebugEnabled()) { log.debug("\nResponse message:\n" + XMLUtils.convertNodeToXMLString(response)); } return response; }
From source file:edu.stanford.junction.extra.Encryption.java
@Override public boolean beforeActivityJoin() { // TODO: probably better to have mCreated or something. if (mKey != null) return true; try {/*from w ww .j a v a 2s .c o m*/ URI invite = getActor().getJunction().getAcceptedInvitation(); System.out.println("JOINING " + invite); if (invite != null) { String params = invite.getQuery(); QueryString qs = new QueryString(params); String b64key = qs.getParameter(URL_KEY_PARAM); if (b64key == null) return true; mKey = Base64Coder.decode(b64key); init(); } } catch (Exception e) { e.printStackTrace(); } return true; }