List of usage examples for java.net URI toString
public String toString()
From source file:com.googlecode.jsonschema2pojo.rules.SchemaRuleTest.java
@Test public void refsToOtherSchemasAreLoaded() throws URISyntaxException, JClassAlreadyExistsException { URI schemaUri = getClass().getResource("/schema/address.json").toURI(); ObjectNode schemaWithRef = new ObjectMapper().createObjectNode(); schemaWithRef.put("$ref", schemaUri.toString()); JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME); TypeRule mockTypeRule = mock(TypeRule.class); when(mockRuleFactory.getTypeRule()).thenReturn(mockTypeRule); when(mockRuleFactory.getSchemaStore()).thenReturn(new SchemaStore()); ArgumentCaptor<JsonNode> captureJsonNode = ArgumentCaptor.forClass(JsonNode.class); ArgumentCaptor<Schema> captureSchema = ArgumentCaptor.forClass(Schema.class); rule.apply(NODE_NAME, schemaWithRef, jclass, null); verify(mockTypeRule).apply(eq(NODE_NAME), captureJsonNode.capture(), eq(jclass.getPackage()), captureSchema.capture());/* w w w .j a v a 2 s . c o m*/ assertThat(captureSchema.getValue().getId(), is(equalTo(schemaUri))); assertThat(captureSchema.getValue().getContent(), is(equalTo(captureJsonNode.getValue()))); assertThat(captureJsonNode.getValue().get("description").asText(), is(equalTo("An Address following the convention of http://microformats.org/wiki/hcard"))); }
From source file:org.cloudfoundry.identity.uaa.integration.ImplicitTokenGrantIntegrationTests.java
@Test public void authzViaJsonEndpointSucceedsWithAcceptForm() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_FORM_URLENCODED)); String credentials = String.format("{ \"username\":\"%s\", \"password\":\"%s\" }", testAccounts.getUserName(), testAccounts.getPassword()); MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("credentials", credentials); ResponseEntity<Void> result = serverRunning.postForResponse(implicitUrl(), headers, formData); URI location = result.getHeaders().getLocation(); assertNotNull(location);//w w w.j a v a 2s . c o m assertTrue("Wrong location: " + location, location.toString().matches(REDIRECT_URL_PATTERN)); }
From source file:com.github.jknack.handlebars.helper.DefaultHelperRegistry.java
@Override public HelperRegistry registerHelpers(final URI location) throws Exception { return registerHelpers(location.getPath(), Files.read(location.toString())); }
From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java
public CommonsVfsConnection(final ConnectionDescription desc, final FileSystemAuthProvider fsAuthProvider) throws FileSystemException { try {// w w w.java 2 s. c o m this.desc = desc; FileSystemOptions options = new FileSystemOptions(); if (null != fsAuthProvider) { fsAuthProvider.authSetup(desc, options); } int port = desc.getPort().orElse(Integer.valueOf(1)).intValue(); String host = desc.getHost().orElse(null); URI url = new URI(desc.getScheme(), null, host, port, desc.getPath(), null, null); base = VFS.getManager().resolveFile(url.toString(), options); root = new AbstractFile(this, ".", null, true, base.exists()); //$NON-NLS-1$ canSetLastModifiedFile = base.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FILE); canSetLastModifiedFolder = base.getFileSystem().hasCapability(Capability.SET_LAST_MODIFIED_FOLDER); } catch (org.apache.commons.vfs2.FileSystemException | URISyntaxException e) { throw new FileSystemException(e); } }
From source file:org.jasig.portlet.calendar.adapter.exchange.ExchangeHttpWebServiceMessageSender.java
public WebServiceConnection createConnection(URI uri) throws IOException { // construct a PostMethod for the supplied URI final PostMethod postMethod = new PostMethod(uri.toString()); if (isAcceptGzipEncoding()) { postMethod.addRequestHeader(HttpTransportConstants.HEADER_ACCEPT_ENCODING, HttpTransportConstants.CONTENT_ENCODING_GZIP); }/*from w w w. j av a 2 s. co m*/ // attempt to find a cached HttpClient instance in the ThreadLocal final HttpClient client = getClient(); return new CommonsHttpConnection(client, postMethod); }
From source file:eu.scape_project.archiventory.identifiers.DroidIdentification.java
/** * Run droid identification on file/*from w ww .j a v a 2s . c om*/ * * @param filePath Absolute file path * @return Result list * @throws FileNotFoundException * @throws IOException */ @Override public HashMap<String, String> identify(File file) throws FileNotFoundException { HashMap<String, String> droidIdRes = new HashMap<String, String>(); InputStream in = null; IdentificationRequest request = null; try { URI resourceUri = file.toURI(); in = new FileInputStream(file); logger.debug("Identification of resource: " + resourceUri.toString()); RequestMetaData metaData = new RequestMetaData(file.length(), file.lastModified(), file.getName()); logger.debug("File length: " + file.length()); logger.debug("File modified: " + file.lastModified()); logger.debug("File name: " + file.getName()); RequestIdentifier identifier = new RequestIdentifier(resourceUri); request = new FileSystemIdentificationRequest(metaData, identifier); request.open(in); IdentificationResultCollection results = bsi.matchBinarySignatures(request); bsi.removeLowerPriorityHits(results); if (results == null || results.getResults() == null || results.getResults().isEmpty()) { logger.debug("No identification result"); } else { List<IdentificationResult> result = results.getResults(); if (result != null && !result.isEmpty()) { for (IdentificationResult ir : result) { String mime = ir.getMimeType(); if (mime != null && !mime.isEmpty()) { // take first mime, ignore others if (!droidIdRes.containsKey("mime")) { droidIdRes.put("mime", mime); } } String puid = ir.getPuid(); if (puid != null && !puid.isEmpty()) { // take first puid, ignore others if (!droidIdRes.containsKey("puid")) { droidIdRes.put("puid", puid); } } } } } in.close(); request.close(); } catch (IOException ex) { logger.error("I/O Exception", ex); } finally { try { in.close(); request.close(); } catch (IOException _) { } } if (!droidIdRes.containsKey("mime")) { droidIdRes.put("mime", "application/octet-stream"); } if (!droidIdRes.containsKey("puid")) { droidIdRes.put("puid", "fmt/0"); } return droidIdRes; }
From source file:io.github.swagger2markup.extensions.SchemaExtension.java
private void schemaSection(Context context, SchemaMetadata schema, int levelOffset) { ContentExtension contentExtension = new ContentExtension(globalContext, context); URI schemaUri = definitionSchemaUri(context, context.getDefinitionName().get(), schema); logger.info("Processing schema: {}", schemaUri.toString()); contentExtension.importContent(schemaUri, reader -> { context.getMarkupDocBuilder().sectionTitleLevel(1 + levelOffset, schema.title); try {//from www .j av a 2s .c o m context.getMarkupDocBuilder().listingBlock(org.apache.commons.io.IOUtils.toString(reader).trim(), schema.language); } catch (IOException e) { throw new RuntimeException(String.format("Failed to read schema URI : %s", schemaUri), e); } }); }
From source file:com.create.application.configuration.TestConfiguration.java
@Bean(name = "authenticatedUserResourceDetails") @Lazy/*from w w w.j av a 2 s .co m*/ public OAuth2ProtectedResourceDetails authenticatedUserResourceDetails( @Value("${security.oauth2.client.accessTokenUri:/oauth/token}") String accessTokenUri, @Value("${security.oauth2.client.client-id}") String clientId, @Value("${security.oauth2.client.client-secret}") String clientSecret, LocalHostUriTemplateHandler localHostUriTemplateHandler) { final URI expandedAccessTokenUri = localHostUriTemplateHandler.expand(accessTokenUri); return ResourceOwnerPasswordResourceDetailsBuilder.aResourceOwnerPasswordResourceDetails() .withAccessTokenUri(expandedAccessTokenUri.toString()).withClientId(clientId) .withClientSecret(clientSecret).withUsername(TICKET_SERVICE_USER).withPassword(USER_PASSWORD) .withGrantTypePassword().build(); }
From source file:io.crate.integrationtests.BlobHttpIntegrationTest.java
public List<String> getRedirectLocations(CloseableHttpClient client, String uri, InetSocketAddress address) throws IOException { CloseableHttpResponse response = null; try {/*from w w w . j a v a 2 s . c om*/ HttpClientContext context = HttpClientContext.create(); HttpHead httpHead = new HttpHead(String.format(Locale.ENGLISH, "http://%s:%s/_blobs/%s", address.getHostName(), address.getPort(), uri)); response = client.execute(httpHead, context); List<URI> redirectLocations = context.getRedirectLocations(); if (redirectLocations == null) { // client might not follow redirects automatically if (response.containsHeader("location")) { List<String> redirects = new ArrayList<>(1); for (Header location : response.getHeaders("location")) { redirects.add(location.getValue()); } return redirects; } return Collections.emptyList(); } List<String> redirects = new ArrayList<>(1); for (URI redirectLocation : redirectLocations) { redirects.add(redirectLocation.toString()); } return redirects; } finally { if (response != null) { IOUtils.closeWhileHandlingException(response); } } }
From source file:com.adobe.acs.commons.remoteassets.impl.RemoteAssetsBinarySyncImpl.java
/** * @see RemoteAssetsBinarySync#syncAsset(Resource) * @param resource Resource/*from w w w .ja va2 s . co m*/ * @return boolean true if sync successful, else false */ @Override public boolean syncAsset(Resource resource) { ResourceResolver remoteAssetsResolver = null; try { remoteAssetsResolver = this.remoteAssetsConfig.getResourceResolver(); Resource localRes = remoteAssetsResolver.getResource(resource.getPath()); Asset asset = DamUtil.resolveToAsset(localRes); URI pathUri = new URI(null, null, asset.getPath(), null); String baseUrl = this.remoteAssetsConfig.getServer().concat(pathUri.toString()) .concat("/_jcr_content/renditions/"); Iterator<? extends Rendition> renditions = asset.listRenditions(); while (renditions.hasNext()) { Rendition assetRendition = renditions.next(); if (StringUtils.isEmpty(assetRendition.getMimeType())) { continue; } String renditionName = assetRendition.getName(); String remoteUrl = String.format("%s%s", baseUrl, renditionName); setRenditionOnAsset(remoteUrl, assetRendition, asset, renditionName); } ModifiableValueMap localResProps = localRes.adaptTo(ModifiableValueMap.class); localResProps.remove(RemoteAssets.IS_REMOTE_ASSET); localResProps.remove(RemoteAssets.REMOTE_SYNC_FAILED); remoteAssetsResolver.commit(); return true; } catch (Exception e) { LOG.error("Error transferring remote asset '{}' to local server", resource.getPath(), e); try { if (remoteAssetsResolver != null) { remoteAssetsResolver.revert(); } } catch (Exception re) { LOG.error("Failed to rollback asset changes", re); } flagAssetAsFailedSync(remoteAssetsResolver, resource); } finally { this.remoteAssetsConfig.closeResourceResolver(remoteAssetsResolver); } return false; }