List of usage examples for java.net URI getRawFragment
public String getRawFragment()
From source file:com.chigix.bio.proxy.buffer.FixedBufferTest.java
License:asdf
@Test public void testGoogleConnect() { System.out.println("BANKAI"); Socket tmp_socket = null;// ww w. j ava 2s . com try { tmp_socket = new Socket("www.google.com", 80); } catch (IOException ex) { Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex); } final Socket socket = tmp_socket; new Thread() { @Override public void run() { while (true) { try { int read; System.out.print(read = socket.getInputStream().read()); System.out.print("[" + (char) read + "]"); System.out.print(","); } catch (IOException ex) { Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex); } } } }.start(); try { //socket.getOutputStream().write("GET http://www.google.com/ HTTP/1.0\r\nHost: www.google.com\r\nConnection: close\r\n\n".getBytes()); //URI uri = new URI("/?gfe_rd=cr&ei=F07YVIjKBe_98wfq74LICw"); URI uri = new URI("/asdfwef?"); System.out.println(uri.getRawFragment()); System.out.println(uri.getRawPath()); System.out.println(uri.getRawQuery()); System.out.println(uri.getRawSchemeSpecificPart()); socket.getOutputStream() .write(("GET / HTTP/1.0\r\nHost: www.google.com\r\nConnection: close\r\n\r\n").getBytes()); System.out.println("REQUEST SENT"); } catch (IOException ex) { Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex); } catch (URISyntaxException ex) { Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex); } try { Thread.sleep(50000); } catch (InterruptedException ex) { Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.echocat.jomon.net.service.UriBasedServicesManager.java
@Nonnull protected URI toUri(@Nonnull URI original, @Nonnull InetSocketAddress address) { final String scheme = original.getScheme(); final int port = address.getPort(); final String userInfo = original.getRawUserInfo(); final String path = original.getRawPath(); final String query = original.getRawQuery(); final String fragment = original.getRawFragment(); final StringBuilder sb = new StringBuilder(); sb.append(scheme).append("://"); if (isNotEmpty(userInfo)) { sb.append(userInfo).append('@'); }/*from www. j a va2 s. c o m*/ sb.append(address.getHostString()); if (canAppendPort(scheme, port)) { sb.append(':').append(port); } if (isNotEmpty(path)) { sb.append(path); } if (isNotEmpty(query)) { sb.append('?').append(query); } if (isNotEmpty(fragment)) { sb.append('#').append(fragment); } return URI.create(sb.toString()); }
From source file:org.openanzo.servlet.EncryptedTokenAuthenticator.java
/** * Adds the give parameters to a URI string in the URI's query portion. It will add the '?' if needed, and will simply add the arguments if the URI already * has a query portion. It will also allow URIs with fragment portions (ex. '#foo') and place the query fragment and parameters in the appropriate place. It * will also escape any special URI characters in the parameter names or values. * // w w w . j a va2s .c om * This method assumes that the query string is in x-www-form-urlencoded format. * * @param uri * the URI string to modify * @param parameters * the map with the key/value parameters to add to the query portion of the URI * @return a String URI with the parameters added to the given URI. * @throws URISyntaxException */ public static String addQueryParametersToURI(String uri, MultiMap<String> parameters) throws URISyntaxException { URI inUri = new URI(uri); String paramStr = UrlEncoded.encode(parameters, null, false); String newQuery = inUri.getQuery() == null ? paramStr : inUri.getQuery() + "&" + paramStr; StringBuilder outUri = new StringBuilder(); if (inUri.getScheme() != null) { outUri.append(inUri.getScheme()); outUri.append(':'); } if (inUri.getRawAuthority() != null) { outUri.append("//"); outUri.append(inUri.getRawAuthority()); } if (inUri.getRawPath() != null) { outUri.append(inUri.getRawPath()); } if (StringUtils.isNotEmpty(newQuery)) { outUri.append('?'); outUri.append(newQuery); } if (inUri.getRawFragment() != null) { outUri.append("#"); outUri.append(inUri.getRawFragment()); } return outUri.toString(); }
From source file:org.eclipse.orion.internal.server.hosting.HostedSiteServlet.java
private URI createUri(URI uri, String queryString) throws URISyntaxException { String queryPart = queryString == null ? "" : "?" + queryString; //$NON-NLS-1$ //$NON-NLS-2$ String fragmentPart = uri.getFragment() == null ? "" : "#" + uri.getRawFragment();//$NON-NLS-1$ //$NON-NLS-2$ URI pathonly = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null);//ww w . j a va2s . c o m StringBuilder buf = new StringBuilder(); buf.append(pathonly.toString()).append(queryPart).append(fragmentPart); return new URI(buf.toString()); }
From source file:org.xwiki.wysiwyg.internal.plugin.alfresco.server.TicketAuthenticator.java
@Override public void authenticate(HttpRequestBase request) { String ticket = null;/*from w w w. jav a 2 s .com*/ //get ticket from DB AlfrescoTiket dbTiket = ticketManager.getTicket(); //if there is a ticket for current user,use it if (dbTiket != null) { ticket = dbTiket.getTiket(); } /*if (ticket != null) { if (!ticketManager.validateAuthenticationTicket(ticket)) { //if ticket is not valid on alfresco, perform authentication ticket = getAuthenticationTicket(); } } else { //if there is no ticket in DB, perform authentication ticket = getAuthenticationTicket(); }*/ // Add the ticket to the query string. URI uri = request.getURI(); List<NameValuePair> parameters = URLEncodedUtils.parse(uri, QUERY_STRING_ENCODING); parameters.add(new BasicNameValuePair(AUTH_TICKET_PARAM, ticket)); String query = URLEncodedUtils.format(parameters, QUERY_STRING_ENCODING); try { request.setURI(URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getRawPath(), query, uri.getRawFragment())); } catch (URISyntaxException e) { // This shouldn't happen. } }
From source file:com.subgraph.vega.internal.http.requests.HttpRequestBuilder.java
private void setPathFromUri(URI uri) { path = uri.getRawPath();/*from w ww . j av a2 s. c om*/ if (path != null) { if (path.length() == 0 || path.charAt(0) != '/') { path = '/' + path; } } else { path = ""; } if (uri.getRawQuery() != null) { path += '?' + uri.getRawQuery(); } if (uri.getRawFragment() != null) { path += '#' + uri.getRawFragment(); } }
From source file:org.orcid.core.adapter.impl.MapperFacadeFactory.java
private String extractFullPath(String uriString) { URI uri = validateAndConvertToURI(uriString); StringBuilder pathBuilder = new StringBuilder(uri.getRawPath()); String query = uri.getRawQuery(); if (query != null) { pathBuilder.append('?'); pathBuilder.append(query);/* w w w .j a va 2s. co m*/ } String fragment = uri.getRawFragment(); if (fragment != null) { pathBuilder.append(fragment); } return pathBuilder.toString(); }
From source file:org.cbioportal.security.spring.PortalSavedRequestAwareAuthenticationSuccessHandler.java
private String getRelativeURI(HttpServletRequest request, String targetURI) { String relativeURI = null;//from w w w . j av a 2 s . c o m try { URI originalURI = new URI(targetURI); logger.debug("getRelativeURI(): request.getServletContext() = '" + request.getServletContext() + "'"); logger.debug("getRelativeURI(): testing '" + new URI(request.getContextPath()) + "'"); // URI(String scheme, String authority, String path, String query, String fragment) // use relativize so we do not include context path e.g. /cbioportal/ // use resolve to make sure we have a "/" at the front relativeURI = new URI("/") .resolve(new URI(request.getContextPath()).relativize(new URI(null, null, originalURI.getRawPath(), originalURI.getRawQuery(), originalURI.getRawFragment()))) .toString(); logger.debug("getRelativeURI(): changing '" + targetURI + "' to '" + relativeURI + "'"); } catch (URISyntaxException e) { return null; } return relativeURI; }
From source file:cn.isif.util_plus.http.client.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery()); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }