List of usage examples for java.net URI getQuery
public String getQuery()
From source file:org.piraso.ui.api.views.URLTabView.java
@Override protected void populateMessage(MessageAwareEntry m) throws Exception { List<URI> urls = URLParser.parseUrls(m.getMessage()); int i = 0;/* w w w. j a v a2s. com*/ for (URI uri : urls) { try { if (i != 0) { insertKeyword(txtEditor, "\n\n"); } insertKeyword(txtEditor, String.format("[%d] Scheme: ", ++i)); insertCode(txtEditor, uri.getScheme()); insertKeyword(txtEditor, "\n Host: "); insertCode(txtEditor, uri.getHost()); if (uri.getPort() > 80) { insertKeyword(txtEditor, "\n Port: "); insertCode(txtEditor, String.valueOf(uri.getPort())); } insertKeyword(txtEditor, "\n Path: "); insertCode(txtEditor, uri.getPath()); String queryString = uri.getQuery(); if (StringUtils.isNotBlank(queryString)) { List<NameValuePair> params = URLEncodedUtils.parse(uri, "UTF-8"); insertKeyword(txtEditor, "\n Query String: "); for (NameValuePair nvp : params) { insertCode(txtEditor, "\n "); insertIdentifier(txtEditor, nvp.getName() + ": "); insertCode(txtEditor, nvp.getValue()); } } } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.hortonworks.registries.schemaregistry.webservice.SchemaRegistryResource.java
/** * Checks whether the current instance is a leader. If so, it invokes the given {@code supplier}, else current * request is redirected to the leader node in registry cluster. * * @param uriInfo//from w w w . java 2 s .c o m * @param supplier * @return */ private Response handleLeaderAction(UriInfo uriInfo, Supplier<Response> supplier) { LOG.info("URI info [{}]", uriInfo.getRequestUri()); if (!leadershipParticipant.get().isLeader()) { URI location = null; try { String currentLeaderLoc = leadershipParticipant.get().getCurrentLeader(); URI leaderServerUrl = new URI(currentLeaderLoc); URI requestUri = uriInfo.getRequestUri(); location = new URI(leaderServerUrl.getScheme(), leaderServerUrl.getAuthority(), requestUri.getPath(), requestUri.getQuery(), requestUri.getFragment()); LOG.info("Redirecting to URI [{}] as this instance is not the leader", location); } catch (Exception e) { throw new RuntimeException(e); } return Response.temporaryRedirect(location).build(); } else { LOG.info("Invoking here as this instance is the leader"); return supplier.get(); } }
From source file:com.mirth.connect.connectors.ws.WebServiceConnectorServlet.java
public URI getURIWithCredentials(URI wsdlUrl, String username, String password) throws URISyntaxException { /* add the username:password to the URL if using authentication */ if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) { String hostWithCredentials = username + ":" + password + "@" + wsdlUrl.getHost(); if (wsdlUrl.getPort() > -1) { hostWithCredentials += ":" + wsdlUrl.getPort(); }/*from w ww. j a v a 2s . c o m*/ wsdlUrl = new URI(wsdlUrl.getScheme(), hostWithCredentials, wsdlUrl.getPath(), wsdlUrl.getQuery(), wsdlUrl.getFragment()); } return wsdlUrl; }
From source file:org.talend.core.nexus.HttpClientTransport.java
private IProxySelectorProvider createProxySelectorProvider() { IProxySelectorProvider proxySelectorProvider = new TalendProxySelector.AbstractProxySelectorProvider() { private Thread currentThread = Thread.currentThread(); @Override/* w ww. ja v a 2 s. c om*/ public List<Proxy> select(URI uri) { // return Collections.EMPTY_LIST; List<Proxy> newProxys = new ArrayList<>(); if (uri == null) { return newProxys; } String schema = uri.getScheme(); if (schema != null && schema.toLowerCase().startsWith("socket")) { //$NON-NLS-1$ try { URI newUri = new URI("https", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); List<Proxy> proxys = TalendProxySelector.getInstance().getDefaultProxySelector() .select(newUri); if (proxys != null && !proxys.isEmpty()) { newProxys.addAll(proxys); } else { newUri = new URI("http", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); proxys = TalendProxySelector.getInstance().getDefaultProxySelector().select(newUri); if (proxys != null && !proxys.isEmpty()) { newProxys.addAll(proxys); } } } catch (URISyntaxException e) { ExceptionHandler.process(e); } } return newProxys; } @Override public boolean canHandle(URI uri) { if (Thread.currentThread() == currentThread) { return true; } return false; } }; return proxySelectorProvider; }
From source file:com.t3.macro.api.views.MacroButtonView.java
public static Object executeLink(String link) throws MacroException { try {//from w w w . j av a2 s . c om URI u = new URI(link); MacroButtonProperties mbp; Token t = null; //campaign macro if ("CampaignPanel".equals(u.getHost())) { CampaignFunctions cf = new CampaignFunctions(); MacroButtonView mv = cf.getCampaignMacro(URLDecoder.decode(u.getPath(), "utf8").substring(1)); if (mv == null) throw new IllegalArgumentException( "Campaign macro '" + URLDecoder.decode(u.getPath(), "utf8") + " not found."); else mbp = mv.macro; } //global macro else if ("GlobalPanel".equals(u.getHost())) { CampaignFunctions cf = new CampaignFunctions(); MacroButtonView mv = cf.getGlobalMacro(URLDecoder.decode(u.getPath(), "utf8").substring(1)); if (mv == null) throw new IllegalArgumentException( "Global macro '" + URLDecoder.decode(u.getPath(), "utf8").substring(1) + " not found."); else mbp = mv.macro; } //token macro else { t = TabletopTool.getFrame().findToken(new GUID(u.getHost())); mbp = t.getMacro(URLDecoder.decode(u.getPath(), "utf8").substring(1), false); } HashMap<String, Object> arguments = new HashMap<String, Object>(); if (u.getQuery() != null) { for (String a : StringUtils.split(u.getQuery(), '&')) { String[] aps = StringUtils.split(a, '='); arguments.put(aps[0], URLDecoder.decode(aps[1], "utf8")); } } return mbp.executeMacro(t, arguments); } catch (UnsupportedEncodingException | URISyntaxException e) { throw new MacroException(e); } }
From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java
private void serveRequest(RequestMethod method, HttpServletRequest req, HttpServletResponse rsp) throws IOException, ServletException { if (logger.isDebugEnabled()) { logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]"); }//from w w w . j ava2 s .c o m if ((loopRetryTimeout > 0L) && (!loopDetected)) { long now = System.currentTimeMillis(), diff = now - initTimestamp; if ((diff > 0L) && (diff < loopRetryTimeout)) { try { MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(new ObjectName( "net.community.chest.gitcloud.facade.backend.git:name=BackendRepositoryResolver")); if (mbeanInfo != null) { logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " detected loop: " + mbeanInfo.getClassName() + "[" + mbeanInfo.getDescription() + "]"); loopDetected = true; } } catch (JMException e) { if (logger.isDebugEnabled()) { logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " failed " + e.getClass().getSimpleName() + " to detect loop: " + e.getMessage()); } } } } ResolvedRepositoryData repoData = resolveTargetRepository(method, req); if (repoData == null) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]", new NoSuchElementException("Failed to resolve repository")); } String username = authenticate(req); // TODO check if the user is allowed to access the repository via the resolve operation (push/pull) if at all (e.g., private repo) logger.info("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "] user=" + username); /* * NOTE: this feature requires enabling cross-context forwarding. * In Tomcat, the 'crossContext' attribute in 'Context' element of * 'TOMCAT_HOME\conf\context.xml' must be set to true, to enable cross-context */ if (loopDetected) { // TODO see if can find a more efficient way than splitting and re-constructing URI uri = repoData.getRepoLocation(); ServletContext curContext = req.getServletContext(); String urlPath = uri.getPath(), urlQuery = uri.getQuery(); String[] comps = StringUtils.split(urlPath, '/'); String appName = comps[0]; ServletContext loopContext = Validate.notNull(curContext.getContext("/" + appName), "No cross-context for %s", appName); // build the relative path in the re-directed context StringBuilder sb = new StringBuilder( urlPath.length() + 1 + (StringUtils.isEmpty(urlQuery) ? 0 : urlQuery.length())); for (int index = 1; index < comps.length; index++) { sb.append('/').append(comps[index]); } if (!StringUtils.isEmpty(urlQuery)) { sb.append('?').append(urlQuery); } String redirectPath = sb.toString(); RequestDispatcher dispatcher = Validate.notNull(loopContext.getRequestDispatcher(redirectPath), "No dispatcher for %s", redirectPath); dispatcher.forward(req, rsp); if (logger.isDebugEnabled()) { logger.debug("serveRequest(" + method + ")[" + req.getRequestURI() + "][" + req.getQueryString() + "]" + " forwarded to " + loopContext.getContextPath() + "/" + redirectPath); } } else { executeRemoteRequest(method, repoData.getRepoLocation(), req, rsp); } }
From source file:com.mellanox.jxio.ClientSession.java
/** * Constructor of ClientSession.// w w w. j a v a 2s .c o m * * @param eqh * - EventQueueHAndler on which the events * (onResponse, onSessionEstablished etc) of this client will arrive * @param uri * - URI of the server to which this Client will connect * of the server * @param callbacks * - implementation of Interface ClientSession.Callbacks */ public ClientSession(EventQueueHandler eqh, URI uri, Callbacks callbacks) { if (LOG.isDebugEnabled()) { LOG.debug("CS CTOR entry"); } this.eqh = eqh; this.callbacks = callbacks; if (!uri.getScheme().equals("rdma") && !uri.getScheme().equals("tcp")) { LOG.fatal("mal formatted URI: " + uri); } String uriStr = uri.toString(); long cacheId = eqh.getId(); if (uri.getPath().compareTo("") == 0) { uriStr += "/"; } if (uri.getQuery() == null) { uriStr += "?" + WorkerCache.CACHE_TAG + "=" + cacheId; } else { uriStr += "&" + WorkerCache.CACHE_TAG + "=" + cacheId; } final long id = Bridge.startSessionClient(uriStr, eqh.getId()); this.name = "jxio.CS[" + Long.toHexString(id) + "]"; this.nameForLog = this.name + ": "; if (id == 0) { LOG.error(this.toLogString() + "there was an error creating session"); } if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "connecting to " + uriStr); } this.setId(id); this.eqh.addEventable(this); if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "CS CTOR done"); } }
From source file:org.accelio.jxio.ClientSession.java
/** * Constructor of ClientSession./*from w ww . j a va 2s .com*/ * * @param eqh * - EventQueueHAndler on which the events * (onResponse, onSessionEstablished etc) of this client will arrive * @param uri * - URI of the server to which this Client will connect * of the server * @param callbacks * - implementation of Interface ClientSession.Callbacks */ public ClientSession(EventQueueHandler eqh, URI uri, Callbacks callbacks) { if (LOG.isDebugEnabled()) { LOG.debug("CS CTOR entry"); } this.eqh = eqh; this.callbacks = callbacks; if (!uri.getScheme().equals("rdma") && !uri.getScheme().equals("tcp")) { LOG.fatal("mal formatted URI: " + uri); } String uriStr = uri.toString(); long cacheId = eqh.getId(); if (uri.getPath().compareTo("") == 0) { uriStr += "/"; } if (uri.getQuery() == null) { uriStr += "?" + WorkerCache.CACHE_TAG + "=" + cacheId; } else { uriStr += "&" + WorkerCache.CACHE_TAG + "=" + cacheId; } final long id = Bridge.startSessionClient(uriStr, eqh.getId()); this.name = "jxio.CS[" + Long.toHexString(id) + "]"; this.nameForLog = this.name + ": "; if (id == 0) { LOG.error(this.toLogString() + "there was an error creating session"); return; } if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "connecting to " + uriStr); } this.setId(id); this.eqh.addEventable(this); if (!Bridge.connectSessionClient(this.getId())) { LOG.error(this.toLogString() + "there was an error connecting session"); return; } if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "CS CTOR done"); } }
From source file:org.cryptomator.frontend.webdav.mount.WindowsWebDavMounter.java
@Override public WebDavMount mount(URI uri, Map<MountParam, Optional<String>> mountParams) throws CommandFailedException { final String driveLetter = mountParams.getOrDefault(MountParam.WIN_DRIVE_LETTER, Optional.empty()) .orElse(AUTO_ASSIGN_DRIVE_LETTER); if (driveLetters.getOccupiedDriveLetters().contains(CharUtils.toChar(driveLetter))) { throw new CommandFailedException("Drive letter occupied."); }//from w w w . j a va 2 s. com final String hostname = mountParams.getOrDefault(MountParam.HOSTNAME, Optional.empty()).orElse(LOCALHOST); try { final URI adjustedUri = new URI(uri.getScheme(), uri.getUserInfo(), hostname, uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); CommandResult mountResult = mount(adjustedUri, driveLetter); return new WindowsWebDavMount( AUTO_ASSIGN_DRIVE_LETTER.equals(driveLetter) ? getDriveLetter(mountResult.getStdOut()) : driveLetter); } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid host: " + hostname); } }
From source file:edu.stanford.junction.addon.JunctionServiceFactory.java
@Override public void onMessageReceived(MessageHeader header, JSONObject message) { // TODO: verify you got an activity request // somehow get the Activity object // that means the request needs // * a host//from w w w . j av a2 s .c om // * an activity descriptor try { URI activityURI = new URI(message.getString("activity")); // TODO: support a factory mapping from serviceName => class String className = message.getString("serviceName"); Class c = null; try { c = Class.forName(className); } catch (Exception e) { System.out.println("Could not find class for service " + className + "."); } JunctionService service = null; Method method = null; try { method = c.getMethod("newInstance"); } catch (Exception e) { System.out.println("No newInstance method found for " + c + "."); } service = (JunctionService) method.invoke(null); String queryPart = activityURI.getQuery(); System.out.println("query part is " + queryPart); String localRole = "Unknown"; int i; if ((i = queryPart.indexOf("role=")) >= 0) { localRole = queryPart.substring(i + 14); if ((i = localRole.indexOf("&")) > 0) { localRole = localRole.substring(0, i); } } System.out.println("Setting service role to " + localRole); service.setRole(localRole); System.out.println("service actorID is " + service.getActorID()); //JunctionMaker.getInstance().newJunction(activityURI,service); } catch (Exception e) { e.printStackTrace(); } }