List of usage examples for java.net URI getRawPath
public String getRawPath()
From source file:net.ripe.rpki.validator.fetchers.ValidatingCertificateRepositoryObjectFetcher.java
private void checkHashValueForCrl(URI uri, ValidationResult result, X509Crl crl, ManifestCms manifest) { String crlFileName = new File(uri.getRawPath()).getName(); // FIXME: is this really the right way to go with error locations? // this way the manifest check error does end up with the CRL which I believe is right.. result.setLocation(new ValidationLocation(uri)); result.rejectIfFalse(manifest.containsFile(crlFileName), ValidationString.VALIDATOR_MANIFEST_DOES_NOT_CONTAIN_FILE, crlFileName); if (result.hasFailureForCurrentLocation()) { return;/* ww w . j av a 2 s .c om*/ } result.rejectIfFalse(manifest.verifyFileContents(crlFileName, crl.getEncoded()), ValidationString.VALIDATOR_FILE_CONTENT); }
From source file:org.kitodo.production.services.data.UserServiceIT.java
@Test public void shouldGetHomeDirectory() throws Exception { assumeTrue(!SystemUtils.IS_OS_WINDOWS && !SystemUtils.IS_OS_MAC); User user = userService.getById(1);/* www . j ava 2 s. c o m*/ String homeDirectory = ConfigCore.getParameter(ParameterCore.DIR_USERS); File script = new File(ConfigCore.getParameter(ParameterCore.SCRIPT_CREATE_DIR_USER_HOME)); ExecutionPermission.setExecutePermission(script); URI homeDirectoryForUser = userService.getHomeDirectory(user); boolean condition = homeDirectoryForUser.getRawPath().contains(homeDirectory + user.getLogin()); assertTrue("Home directory of user is incorrect!", condition); user = userService.getById(2); homeDirectoryForUser = userService.getHomeDirectory(user); condition = homeDirectoryForUser.getRawPath().contains(user.getLogin()); assertTrue("Home directory of user is incorrect!", condition); ExecutionPermission.setNoExecutePermission(script); }
From source file:com.ge.predix.acs.privilege.management.SubjectPrivilegeManagementController.java
@ApiOperation(value = "Creates/Updates a given Subject.", tags = { "Attribute Management" }) @RequestMapping(method = PUT, value = V1 + SUBJECT_URL, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<BaseSubject> putSubject(@RequestBody final BaseSubject subject, @PathVariable("subjectIdentifier") final String subjectIdentifier) { try {//www. j av a 2 s.c o m this.failIfParentsSpecified(Collections.singletonList(subject)); if (StringUtils.isEmpty(subject.getSubjectIdentifier())) { subject.setSubjectIdentifier(subjectIdentifier); } validSubjectIdentifierOrFail(subject, subjectIdentifier); boolean createdSubject = this.service.upsertSubject(subject); URI subjectUri = UriTemplateUtils.expand(SUBJECT_URL, "subjectIdentifier:" + subjectIdentifier); if (createdSubject) { return created(subjectUri.getRawPath(), false); } return created(subjectUri.getRawPath(), true); } catch (RestApiException e) { // NOTE: This block is necessary to avoid accidentally // converting the HTTP status code to an unintended one throw e; } catch (Exception e) { throw new RestApiException(HttpStatus.UNPROCESSABLE_ENTITY, e); } }
From source file:com.chigix.bio.proxy.buffer.FixedBufferTest.java
License:asdf
@Test public void testGoogleConnect() { System.out.println("BANKAI"); Socket tmp_socket = null;//from w ww . j a va 2s . c om 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.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. * //from w w w .ja v a 2s.c o m * 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.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('@'); }//w ww. ja v a 2 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:com.alibaba.dubbo.rpc.protocol.springmvc.support.ApacheHttpClient.java
HttpUriRequest toHttpUriRequest(Request request, Request.Options options) throws UnsupportedEncodingException, MalformedURLException, URISyntaxException { RequestBuilder requestBuilder = RequestBuilder.create(request.method()); //per request timeouts // RequestConfig requestConfig = RequestConfig // .custom() // .setConnectTimeout(options.connectTimeoutMillis()) // .setSocketTimeout(options.readTimeoutMillis()) // .build(); //requestBuilder.setConfig(requestConfig); URI uri = new URIBuilder(request.url()).build(); requestBuilder.setUri(uri.getScheme() + "://" + uri.getAuthority() + uri.getRawPath()); //request query params List<NameValuePair> queryParams = URLEncodedUtils.parse(uri, requestBuilder.getCharset().name()); for (NameValuePair queryParam : queryParams) { requestBuilder.addParameter(queryParam); }//w w w.j ava 2s . com //request headers boolean hasAcceptHeader = false; for (Map.Entry<String, Collection<String>> headerEntry : request.headers().entrySet()) { String headerName = headerEntry.getKey(); if (headerName.equalsIgnoreCase(ACCEPT_HEADER_NAME)) { hasAcceptHeader = true; } if (headerName.equalsIgnoreCase(Util.CONTENT_LENGTH)) { // The 'Content-Length' header is always set by the Apache client and it // doesn't like us to set it as well. continue; } for (String headerValue : headerEntry.getValue()) { requestBuilder.addHeader(headerName, headerValue); } } //some servers choke on the default accept string, so we'll set it to anything if (!hasAcceptHeader) { requestBuilder.addHeader(ACCEPT_HEADER_NAME, "*/*"); } //request body if (request.body() != null) { HttpEntity entity = null; if (request.charset() != null) { ContentType contentType = getContentType(request); String content = new String(request.body(), request.charset()); entity = new StringEntity(content, contentType); } else { entity = new ByteArrayEntity(request.body()); } requestBuilder.setEntity(entity); } return requestBuilder.build(); }
From source file:feign.httpclient.ApacheHttpClient.java
HttpUriRequest toHttpUriRequest(Request request, Request.Options options) throws UnsupportedEncodingException, MalformedURLException, URISyntaxException { RequestBuilder requestBuilder = RequestBuilder.create(request.method()); //per request timeouts RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(options.connectTimeoutMillis()) .setSocketTimeout(options.readTimeoutMillis()).build(); requestBuilder.setConfig(requestConfig); URI uri = new URIBuilder(request.url()).build(); requestBuilder.setUri(uri.getScheme() + "://" + uri.getAuthority() + uri.getRawPath()); //request query params List<NameValuePair> queryParams = URLEncodedUtils.parse(uri, requestBuilder.getCharset().name()); for (NameValuePair queryParam : queryParams) { requestBuilder.addParameter(queryParam); }//from ww w. j av a2 s .c o m //request headers boolean hasAcceptHeader = false; for (Map.Entry<String, Collection<String>> headerEntry : request.headers().entrySet()) { String headerName = headerEntry.getKey(); if (headerName.equalsIgnoreCase(ACCEPT_HEADER_NAME)) { hasAcceptHeader = true; } if (headerName.equalsIgnoreCase(Util.CONTENT_LENGTH)) { // The 'Content-Length' header is always set by the Apache client and it // doesn't like us to set it as well. continue; } for (String headerValue : headerEntry.getValue()) { requestBuilder.addHeader(headerName, headerValue); } } //some servers choke on the default accept string, so we'll set it to anything if (!hasAcceptHeader) { requestBuilder.addHeader(ACCEPT_HEADER_NAME, "*/*"); } //request body if (request.body() != null) { HttpEntity entity = null; if (request.charset() != null) { ContentType contentType = getContentType(request); String content = new String(request.body(), request.charset()); entity = new StringEntity(content, contentType); } else { entity = new ByteArrayEntity(request.body()); } requestBuilder.setEntity(entity); } return requestBuilder.build(); }
From source file:net.ripe.rpki.validator.util.UriToFileMapper.java
public File map(URI uri, ValidationResult result) { Validate.notNull(result);/* w w w.j a va 2 s . c om*/ Validate.notNull(uri); result.rejectIfFalse(RSYNC_SCHEME.equalsIgnoreCase(uri.getScheme()), VALIDATOR_URI_RSYNC_SCHEME, uri.toString()); result.rejectIfNull(uri.getHost(), VALIDATOR_URI_HOST, uri.toString()); result.rejectIfNull(uri.getRawPath(), VALIDATOR_URI_PATH, uri.toString()); String s = uri.toString(); result.rejectIfTrue(s.contains("/../") || s.endsWith("/.."), VALIDATOR_URI_SAFETY, uri.toString()); if (result.hasFailureForCurrentLocation()) { return null; } return new File(new File(targetDirectory, getHostPortAsString(uri)), uri.getRawPath()); }