List of usage examples for java.net URI isAbsolute
public boolean isAbsolute()
From source file:info.magnolia.testframework.htmlunit.AbstractMagnoliaHtmlUnitTest.java
protected <P extends Page> P assertRedirected(String reason, String expectedTargetURLPattern, Page page, User user, Instance instance) throws IOException, URISyntaxException { assertEquals(302, page.getWebResponse().getStatusCode()); final String location = page.getWebResponse().getResponseHeaderValue("Location"); // only test whether it has the proper start in order to ignore e.g. attached sessionIds assertTrue(// w w w.ja v a2 s . co m "Redirect location " + location + " does not match the expected pattern: " + expectedTargetURLPattern + " (" + reason + ")", location.matches(expectedTargetURLPattern)); // location can be relative (https://bz.apache.org/bugzilla/show_bug.cgi?id=56917) transfer it to absolute url final URI uri = new URI(location); final String url; if (uri.isAbsolute()) { url = location; } else { url = instance.getDomain() + location; } // since this is already redirected do not follow more redirects // also do not execute javascript on the target page - at least not until https://sourceforge.net/tracker/?func=detail&aid=3110090&group_id=47038&atid=448266 is solved return (P) openPage(url, user, false, false, DEFAULT_HEADERS); }
From source file:at.bitfire.davdroid.resource.WebDavCollection.java
Resource.AssetDownloader getDownloader() { return new Resource.AssetDownloader() { @Override// ww w . ja v a2 s. c om public byte[] download(URI uri) throws URISyntaxException, IOException, HttpException, DavException { if (!uri.isAbsolute()) throw new URISyntaxException(uri.toString(), "URI referenced from entity must be absolute"); // send credentials when asset has same URI authority as baseURI // we have to construct these helper URIs because // "https://server:443" is NOT equal to "https://server" otherwise URI baseUriAuthority = new URI(baseURI.getScheme(), null, baseURI.getHost(), baseURI.getPort(), null, null, null), assetUriAuthority = new URI(uri.getScheme(), null, uri.getHost(), baseURI.getPort(), null, null, null); if (baseUriAuthority.equals(assetUriAuthority)) { Log.d(TAG, "Asset is on same server, sending credentials"); WebDavResource file = new WebDavResource(collection, uri); file.get("image/*"); return file.getContent(); } else // resource is on an external server, don't send credentials return IOUtils.toByteArray(uri); } }; }
From source file:net.jotel.ws.client.WebSocketClient.java
public static void validateWebSocketUri(URI uri) throws WebSocketException { if (uri == null) { throw new WebSocketException("URI is empty!"); }// ww w.j av a2s . c om if (!uri.isAbsolute()) { throw new WebSocketException("Absolute URI required!"); } if (!StringUtils.equalsIgnoreCase("ws", uri.getScheme()) && !StringUtils.equalsIgnoreCase("wss", uri.getScheme())) { throw new WebSocketException("Unsupported URI scheme!"); } if (StringUtils.isNotEmpty(uri.getFragment())) { throw new WebSocketException("URI fragment is not allowed!"); } if (StringUtils.isBlank(uri.getHost())) { throw new WebSocketException("URI host component is empty!"); } }
From source file:com.collaborne.jsonschema.generator.driver.GeneratorDriver.java
/** * Create a {@link SchemaLoader} with the provided {@code rootUri} and {@code baseDirectory}. * * All schemas from {@code schemaFiles} are pre-loaded into the schema loader. * * @param rootUri//from w w w.j a v a2 s .c o m * @param baseDirectory * @param schemaFiles * @return * @throws IOException */ public SchemaLoader createSchemaLoader(URI rootUri, Path baseDirectory, List<Path> schemaFiles) throws IOException { URI baseDirectoryUri = baseDirectory.toAbsolutePath().normalize().toUri(); // We're not adding a path redirection here, because that changes the path of the loaded schemas to the redirected location. // FIXME: This really looks like a bug in the SchemaLoader itself! URITranslatorConfiguration uriTranslatorConfiguration = URITranslatorConfiguration.newBuilder() .setNamespace(rootUri).freeze(); LoadingConfigurationBuilder loadingConfigurationBuilder = LoadingConfiguration.newBuilder() .setURITranslatorConfiguration(uriTranslatorConfiguration); // ... instead, we use a custom downloader which executes the redirect Map<String, URIDownloader> downloaders = loadingConfigurationBuilder.freeze().getDownloaderMap(); URIDownloader redirectingDownloader = new URIDownloader() { @Override public InputStream fetch(URI source) throws IOException { URI relativeSourceUri = rootUri.relativize(source); if (!relativeSourceUri.isAbsolute()) { // Apply the redirect source = baseDirectoryUri.resolve(relativeSourceUri); } URIDownloader wrappedDownloader = downloaders.get(source.getScheme()); return wrappedDownloader.fetch(source); } }; for (Map.Entry<String, URIDownloader> entry : downloaders.entrySet()) { loadingConfigurationBuilder.addScheme(entry.getKey(), redirectingDownloader); } JsonNodeReader reader = new JsonNodeReader(objectMapper); for (Path schemaFile : schemaFiles) { URI schemaFileUri = schemaFile.toAbsolutePath().normalize().toUri(); URI relativeSchemaUri = baseDirectoryUri.relativize(schemaFileUri); URI schemaUri = rootUri.resolve(relativeSchemaUri); logger.info("{}: loading from {}", schemaUri, schemaFile); JsonNode schemaNode = reader.fromReader(Files.newBufferedReader(schemaFile)); // FIXME: (upstream?): the preloaded map is accessed via the "real URI", so we need that one here as well // This smells really wrong, after all we want all these to look like they came from rootUri() loadingConfigurationBuilder.preloadSchema(schemaFileUri.toASCIIString(), schemaNode); } return new SchemaLoader(loadingConfigurationBuilder.freeze()); }
From source file:org.structr.schema.export.StructrSchemaDefinition.java
@Override public Object resolveURI(final URI uri) { final URI id = getId(); if (id != null) { final URI rel = id.relativize(uri); if (!rel.isAbsolute()) { final String relString = "#/" + rel.toString(); return resolveJsonPointer(relString); }//from w w w . j a v a 2 s. c om } return null; }
From source file:org.structr.schema.export.StructrSchemaDefinition.java
@Override public String toJsonPointer(final URI uri) { final URI pointer = id.relativize(uri); if (!pointer.isAbsolute()) { final String jsonPointer = pointer.toString(); if (jsonPointer.startsWith("#/")) { return jsonPointer; } else if (jsonPointer.startsWith("/")) { return "#" + jsonPointer; } else {/*from w ww . j ava2s . co m*/ return "#/" + jsonPointer; } } return pointer.toString(); }
From source file:io.syndesis.runtime.credential.CredentialITCase.java
@Test public void shouldInitiateCredentialFlow() throws UnsupportedEncodingException { final ResponseEntity<AcquisitionResponse> acquisitionResponse = post( "/api/v1/connectors/test-provider/credentials", Collections.singletonMap("returnUrl", "/ui#state"), AcquisitionResponse.class, tokenRule.validToken(), HttpStatus.ACCEPTED); assertThat(acquisitionResponse.hasBody()).as("Should present a acquisition response in the HTTP body") .isTrue();//from w ww. j a va 2 s . c om final AcquisitionResponse response = acquisitionResponse.getBody(); assertThat(response.getType()).isEqualTo(Type.OAUTH2); final String redirectUrl = response.getRedirectUrl(); assertThat(redirectUrl).as("Should redirect to Salesforce and containthe correct callback URL") .startsWith("https://test/oauth2/authorize?client_id=testClientId&response_type=code&redirect_uri=") .contains(encode("/api/v1/credentials/callback", "ASCII")); final MultiValueMap<String, String> params = UriComponentsBuilder.fromHttpUrl(redirectUrl).build() .getQueryParams(); final String state = params.getFirst("state"); assertThat(state).as("state parameter should be set").isNotEmpty(); final State responseStateInstruction = response.state(); assertThat(responseStateInstruction).as("acquisition response should contain the state instruction") .isNotNull(); assertThat(responseStateInstruction.persist()).isEqualByComparingTo(State.Persist.COOKIE); assertThat(responseStateInstruction.spec()).isNotEmpty(); final CredentialFlowState credentialFlowState = clientSideState .restoreFrom(Cookie.valueOf(responseStateInstruction.spec()), CredentialFlowState.class); final CredentialFlowState expected = new OAuth2CredentialFlowState.Builder().key("test-state") .providerId("test-provider").build(); assertThat(credentialFlowState).as("The flow state should be as expected") .isEqualToIgnoringGivenFields(expected, "returnUrl"); final URI returnUrl = credentialFlowState.getReturnUrl(); assertThat(returnUrl).isNotNull(); assertThat(returnUrl.isAbsolute()).isTrue(); assertThat(returnUrl.getPath()).isEqualTo("/ui"); assertThat(returnUrl.getFragment()).isEqualTo("state"); }
From source file:org.mobicents.servlet.sip.restcomm.interpreter.tagstrategy.RcmlTagStrategy.java
protected URI resolveIfNotAbsolute(final URI base, final URI uri) { if (base.equals(uri)) { return uri; } else {/*from www .j a v a 2 s . c o m*/ if (!uri.isAbsolute()) { return base.resolve(uri); } else { return uri; } } }
From source file:org.neo4j.server.helpers.ServerBuilder.java
public ServerBuilder withRelativeWebAdminUriPath(String webAdminUri) { try {//from www. ja va 2 s . com URI theUri = new URI(webAdminUri); if (theUri.isAbsolute()) { this.webAdminUri = theUri.getPath(); } else { this.webAdminUri = theUri.toString(); } } catch (URISyntaxException e) { throw new RuntimeException(e); } return this; }
From source file:org.eel.kitchen.jsonschema.uri.URIManager.java
/** * Get the content at a given URI as a {@link JsonNode} * * @param uri the URI// www . j av a 2s . c om * @return the content * @throws JsonSchemaException scheme is not registered, failed to get * content, or content is not JSON */ public JsonNode getContent(final URI uri) throws JsonSchemaException { Preconditions.checkNotNull(uri, "null URI"); Preconditions.checkArgument(uri.isAbsolute(), "requested URI (" + uri + ") is not absolute"); final URI target = URIRedirections.containsKey(uri) ? URIRedirections.get(uri) : uri; /* * All errors at this level are fatal */ final Message.Builder msg = Domain.REF_RESOLVING.newMessage().setKeyword("N/A").addInfo("uri", target) .setFatal(true); if (!target.isAbsolute()) throw new JsonSchemaException(msg.setMessage("URI is not absolute").build()); final String scheme = target.getScheme(); final URIDownloader downloader = downloaders.get(scheme); if (downloader == null) { msg.setMessage("cannot handle scheme").addInfo("scheme", scheme); throw new JsonSchemaException(msg.build()); } final InputStream in; try { in = downloader.fetch(target); } catch (IOException e) { msg.setMessage("cannot fetch content from URI"); throw new JsonSchemaException(msg.build(), e); } try { // Note: ObjectMapper's .readTree() closes the InputStream after it // is done with it! return mapper.readTree(in); } catch (IOException e) { msg.setMessage("content fetched from URI is not valid JSON"); throw new JsonSchemaException(msg.build(), e); } }