List of usage examples for java.net URI resolve
public URI resolve(String str)
From source file:org.eclipse.orion.server.cf.commands.GetIsRouteAvailableCommand.java
@Override protected ServerStatus _doIt() { try {//from w w w . ja va 2s .c o m // CF API // http://apidocs.cloudfoundry.org/195/routes/check_a_route_exists.html // GET /v2/routes/reserved/domain/:domain_guid/host/:host // e.g. // GET /v2/routes/reserved/domain/c11da0e2-517a-4d53-98a0-5d340fee4b78/host/sample-java-cloudant URI targetURI = URIUtil.toURI(getCloud().getUrl()); String path = "/v2/routes/reserved/domain/" + this.guid + "/host/" + this.host; URI requestURI = targetURI.resolve(path); GetMethod getIsRouteAvailableMethod = new GetMethod(requestURI.toString()); HttpUtil.configureHttpMethod(getIsRouteAvailableMethod, target.getCloud()); return HttpUtil.executeMethod(getIsRouteAvailableMethod); } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
From source file:org.ldp4j.server.data.SafeResourceResolverTest.java
@Test public void testRoundtrip() throws ContentTransformationException { URI application = URI.create("http://www.example.org/target/"); URI endpoint = application.resolve("resource/"); URI alternative = URI.create("http://www.ldp4j.org/target/resource/"); URI r1 = application.resolve("other/"); URI r2 = endpoint.resolve("other/"); URI r3 = endpoint.resolve("other/another/"); ManagedIndividualId id1 = resourceId(1, "example"); ManagedIndividualId id2 = resourceId(2, "example"); ManagedIndividualId id3 = resourceId(3, "example"); ManagedIndividualId id4 = resourceId(4, "example"); ManagedIndividualId id5 = resourceId(5, "example"); final Map<URI, ManagedIndividualId> resolutions = ImmutableMap.<URI, ManagedIndividualId>builder() .put(application, id1).put(endpoint, id2).put(r1, id3).put(r2, id4).put(r3, id5).build(); final Set<URI> checked = new HashSet<URI>(); ResourceResolver resolver = new ResourceResolver() { @Override/*from w w w . j a v a 2 s.c o m*/ public URI resolveResource(ManagedIndividualId id) { return null; } @Override public ManagedIndividualId resolveLocation(URI path) { checked.add(path); return resolutions.get(path); } }; String rawEntity = loadResource("/data/example_without_base.ttl"); SafeResourceResolver safeResolver = SafeResourceResolver.builder().withApplication(application) .withEndpoint(endpoint).withAlternative(alternative).withEntity(rawEntity, this.mediaType).build(); safeResolver = safeResolver.setResourceResolver(resolver); DataSet dataSet = unmarshall(rawEntity, endpoint, safeResolver); System.out.println(dataSet); assertThat(checked, hasItems(application, endpoint, r1, r2, r3)); assertThat(dataSet.individualOfId(id1), notNullValue()); assertThat(dataSet.individualOfId(id2), notNullValue()); assertThat(dataSet.individualOfId(id3), notNullValue()); assertThat(dataSet.individualOfId(id4), notNullValue()); assertThat(dataSet.individualOfId(id5), notNullValue()); }
From source file:org.eclipse.orion.server.cf.commands.GetSpaceByNameCommand.java
public ServerStatus _doIt() { try {/* w w w . j ava 2s . com*/ // check the org first URI targetURI = URIUtil.toURI(target.getUrl()); URI orgsURI = targetURI.resolve("/v2/organizations"); //$NON-NLS-1$ GetMethod getOrgsMethod = new GetMethod(orgsURI.toString()); ServerStatus confStatus = HttpUtil.configureHttpMethod(getOrgsMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; ServerStatus getOrgsStatus = HttpUtil.executeMethod(getOrgsMethod); if (!getOrgsStatus.isOK() && getOrgsStatus.getHttpCode() != HttpServletResponse.SC_PARTIAL_CONTENT) return getOrgsStatus; JSONObject result = getOrgsStatus.getJsonData(); JSONArray orgs = result.getJSONArray("resources"); //$NON-NLS-1$ if (orgs.length() == 0) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Organization not found", null); Org organization = getOrganization(orgs, orgName); if (organization == null) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Organization not found", null); // now get the space String spaceUrl = organization.getCFJSON().getJSONObject("entity").getString("spaces_url"); //$NON-NLS-1$//$NON-NLS-2$ URI spaceURI = targetURI.resolve(spaceUrl); GetMethod getSpaceMethod = new GetMethod(spaceURI.toString()); confStatus = HttpUtil.configureHttpMethod(getSpaceMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; ServerStatus getSpaceStatus = HttpUtil.executeMethod(getSpaceMethod); if (!getSpaceStatus.isOK()) return getSpaceStatus; result = getSpaceStatus.getJsonData(); JSONArray spaces = result.getJSONArray("resources"); //$NON-NLS-1$ if (spaces.length() == 0) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Space not found", null); Space space = getSpace(spaces, spaceName); if (space == null) return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Space not found", null); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, space.toJSON()); } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
From source file:pcgen.system.RecentFileList.java
RecentFileList(String contextProp) { this.contextProp = contextProp; String[] recentFiles = PCGenSettings.getInstance().getStringArray(contextProp); if (!ArrayUtils.isEmpty(recentFiles)) { URI userdir = new File(ConfigurationSettings.getUserDir()).toURI(); for (int i = recentFiles.length - 1; i >= 0; i--) { addRecentFile(new File(userdir.resolve(recentFiles[i]))); }/*from w w w .j av a 2 s. com*/ } }
From source file:org.eclipse.orion.server.cf.commands.CreateApplicationCommand.java
@Override protected ServerStatus _doIt() { try {/*from w w w . j a v a2 s . c o m*/ if (reset) { // TODO: if the app exists, and reset flag is true, we need to reset the app first } /* create cloud foundry application */ URI targetURI = URIUtil.toURI(target.getUrl()); URI appsURI = targetURI.resolve("/v2/apps"); //$NON-NLS-1$ PostMethod createAppMethod = new PostMethod(appsURI.toString()); HttpUtil.configureHttpMethod(createAppMethod, target); /* set request body */ JSONObject createAppRequst = new JSONObject(); createAppRequst.put(CFProtocolConstants.V2_KEY_SPACE_GUID, target.getSpace().getCFJSON() .getJSONObject(CFProtocolConstants.V2_KEY_METADATA).getString(CFProtocolConstants.V2_KEY_GUID)); createAppRequst.put(CFProtocolConstants.V2_KEY_NAME, appName); createAppRequst.put(CFProtocolConstants.V2_KEY_INSTANCES, appInstances); createAppRequst.put(CFProtocolConstants.V2_KEY_BUILDPACK, buildPack != null ? buildPack : JSONObject.NULL); createAppRequst.put(CFProtocolConstants.V2_KEY_COMMAND, appCommand); createAppRequst.put(CFProtocolConstants.V2_KEY_MEMORY, appMemory); createAppRequst.put(CFProtocolConstants.V2_KEY_STACK_GUID, JSONObject.NULL); if (env != null) createAppRequst.put(CFProtocolConstants.V2_KEY_ENVIRONMENT_JSON, env); createAppMethod.setRequestEntity( new StringRequestEntity(createAppRequst.toString(), "application/json", "utf-8")); //$NON-NLS-1$ //$NON-NLS-2$ ServerStatus status = HttpUtil.executeMethod(createAppMethod); if (!status.isOK()) return status; /* extract application guid */ JSONObject appResp = status.getJsonData(); application.setGuid(appResp.getJSONObject(CFProtocolConstants.V2_KEY_METADATA) .getString(CFProtocolConstants.V2_KEY_GUID)); application.setName(appName); return status; } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
From source file:org.apache.ode.bpel.compiler.DefaultResourceFinder.java
public URI resolve(URI parent, URI child) { parent = relativize(parent);/* w w w.j a va 2 s . c o m*/ child = relativize(child); URI result = parent.resolve(child); URI result2 = _absoluteDir.toURI().resolve(result); if (__log.isDebugEnabled()) { __log.debug("resolving URI: parent " + parent + " child " + child + " result " + result + " resultAbsolute:" + result2); } return result2; }
From source file:org.gradle.internal.resource.transport.sftp.SftpResourceUploader.java
private void ensureParentDirectoryExists(ChannelSftp channel, URI uri) { String parentPath = FilenameUtils.getFullPathNoEndSeparator(uri.getPath()); if (parentPath.equals("")) { return;/*from ww w.j a v a2s .com*/ } URI parent = uri.resolve(parentPath); try { channel.lstat(parentPath); return; } catch (com.jcraft.jsch.SftpException e) { if (e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE) { throw new ResourceException(parent, String.format("Could not lstat resource '%s'.", parent), e); } } ensureParentDirectoryExists(channel, parent); try { channel.mkdir(parentPath); } catch (com.jcraft.jsch.SftpException e) { throw new ResourceException(parent, String.format("Could not create resource '%s'.", parent), e); } }
From source file:org.kalypso.simulation.core.util.AbstractSimulationDataProvider.java
@Override public Object getInputForID(final String id) throws SimulationException { final String path = m_idhash.get(id); if (path == null) throw new NoSuchElementException( Messages.getString("org.kalypso.simulation.core.util.AbstractSimulationDataProvider.0") + id); //$NON-NLS-1$ final DataType inputType = m_modelspec == null ? null : m_modelspec.getInput(id); // default to xs:anyURI if no type is given final QName type = inputType == null ? QNAME_ANY_URI : inputType.getType(); // URI types are treated as URLs, if (type.equals(QNAME_ANY_URI)) { try {/*from w w w. j a v a 2 s. c o m*/ final URI baseURL = getBaseURL().toURI(); final URI relativeURI = baseURL.resolve(URIUtil.encodePath(path)); // try to silently convert the URI to a URL try { final URL url = relativeURI.toURL(); return url; } catch (final MalformedURLException e) { // gobble } return relativeURI; } catch (final IOException e) { throw new SimulationException( Messages.getString("org.kalypso.simulation.core.util.AbstractSimulationDataProvider.1"), e); //$NON-NLS-1$ } catch (final URISyntaxException e) { throw new SimulationException( Messages.getString("org.kalypso.simulation.core.util.AbstractSimulationDataProvider.2"), e); //$NON-NLS-1$ } } else { final ITypeRegistry<IMarshallingTypeHandler> typeRegistry = MarshallingTypeRegistrySingleton .getTypeRegistry(); final IMarshallingTypeHandler handler = typeRegistry.getTypeHandlerForTypeName(type); if (handler != null) { try { return handler.parseType(path); } catch (final ParseException e) { throw new SimulationException(Messages.getString( "org.kalypso.simulation.core.util.AbstractSimulationDataProvider.3", path, type), e); //$NON-NLS-1$ } } } throw new SimulationException( Messages.getString("org.kalypso.simulation.core.util.AbstractSimulationDataProvider.4") + type, //$NON-NLS-1$ null); }
From source file:org.vaadin.addons.javaee.container.rest.RestEntityContainer.java
public RestEntityContainer(Class<ENTITY> entityClass, String resourcePath) { super(entityClass); this.setResourcePath(resourcePath); URI location = UI.getCurrent().getPage().getLocation(); baseRestURI = location.resolve("/facade/rest"); restURI = baseRestURI.resolve("/facade/rest/" + resourcePath); }
From source file:org.eclipse.orion.server.cf.commands.GetLogsCommand.java
private ServerStatus prepareJSONResp(JSONArray logsJSON, String instance, String appUrl) { try {/*from w ww .j av a 2 s. c o m*/ String instanceLogsAppUrl = appUrl + "/instances/" + instance + "/files/logs"; URI targetURI = URIUtil.toURI(target.getUrl()); URI instanceLogsAppURI = targetURI.resolve(instanceLogsAppUrl); GetMethod getInstanceLogsMethod = new GetMethod(instanceLogsAppURI.toString()); HttpUtil.configureHttpMethod(getInstanceLogsMethod, target); ServerStatus getStatus = HttpUtil.executeMethod(getInstanceLogsMethod); if (!getStatus.isOK()) { return getStatus; } String response = getStatus.getJsonData().optString("response"); if (response == null) { return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Log request: invalid response from the server", getStatus.getJsonData(), null); } String[] logFiles = response.split("\n"); URI baseUri = new URI( baseRequestLocation.endsWith("/") ? baseRequestLocation : baseRequestLocation + "/"); for (int i = 0; i < logFiles.length; i++) { String logFileEntry = logFiles[i]; String[] logFileEntryParts = logFileEntry.split("\\s+"); if (logFileEntryParts.length != 2) { continue; } Log log = new Log(appName, logFileEntryParts[0]); log.setLocation(baseUri.resolve(log.getName())); log.setSize(logFileEntryParts[1]); logsJSON.put(log.toJSON()); } } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK); }