List of usage examples for java.net URI resolve
public URI resolve(String str)
From source file:org.eclipse.orion.server.cf.handlers.v1.SpacesHandlerV1.java
@Override protected CFJob handleGet(Space space, HttpServletRequest request, HttpServletResponse response, final String pathString) { final JSONObject targetJSON = extractJSONData( IOUtilities.getQueryParameter(request, CFProtocolConstants.KEY_TARGET)); return new CFJob(request, false) { @Override//from w w w . j ava 2 s. c o m protected IStatus performJob() { try { URL targetUrl = null; if (targetJSON != null) { try { targetUrl = new URL(targetJSON.getString(CFProtocolConstants.KEY_URL)); } catch (Exception e) { // do nothing } } Target target = CFActivator.getDefault().getTargetRegistry().getTarget(userId, targetUrl); if (target == null) { return HttpUtil.createErrorStatus(IStatus.WARNING, "CF-TargetNotSet", "Target not set"); } IPath path = new Path(pathString); final String spaceId = path.segment(0); /* get space */ URI targetURI = URIUtil.toURI(target.getUrl()); URI orgsURI = targetURI.resolve("/v2/spaces/" + spaceId); GetMethod getDomainsMethod = new GetMethod(orgsURI.toString()); HttpUtil.configureHttpMethod(getDomainsMethod, target); getDomainsMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$ ServerStatus status = HttpUtil.executeMethod(getDomainsMethod); if (!status.isOK()) return status; Space space = new Space().setCFJSON(status.getJsonData()); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, space.toJSON()); } catch (Exception e) { String msg = NLS.bind("Failed to handle request for {0}", pathString); //$NON-NLS-1$ ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); logger.error(msg, e); return status; } } }; }
From source file:com.blackducksoftware.integration.hubdiff.HubDiffTest.java
@Before public void setup() throws IOException, URISyntaxException { URI basePath = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI(); expectedFile = new File(basePath.resolve("expected.csv")); actualFile = new File(basePath.resolve("actual.csv")); resultsFile = new File(basePath.resolve("results.txt")); swaggerDocFile1 = new File(basePath.resolve("api-docs-3.4.2-test.json")); swaggerDocFile2 = new File(basePath.resolve("api-docs-3.5.0-test.json")); doc1 = new SwaggerDoc(FileUtils.readFileToString(swaggerDocFile1, StandardCharsets.UTF_8), "3.4.2"); doc2 = new SwaggerDoc(FileUtils.readFileToString(swaggerDocFile2, StandardCharsets.UTF_8), "3.5.0"); }
From source file:org.eclipse.orion.server.cf.commands.StopAppCommand.java
public ServerStatus _doIt() { try {//from w w w . j av a2 s . c o m URI targetURI = URIUtil.toURI(target.getUrl()); String appUrl = this.app.getAppJSON().getString("url"); URI appURI = targetURI.resolve(appUrl); PutMethod stopMethod = new PutMethod(appURI.toString()); HttpUtil.configureHttpMethod(stopMethod, target); stopMethod.setQueryString("inline-relations-depth=1"); JSONObject stopComand = new JSONObject(); stopComand.put("console", true); stopComand.put("state", "STOPPED"); StringRequestEntity requestEntity = new StringRequestEntity(stopComand.toString(), CFProtocolConstants.JSON_CONTENT_TYPE, "UTF-8"); stopMethod.setRequestEntity(requestEntity); return HttpUtil.executeMethod(stopMethod); } 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.eclipse.orion.server.cf.commands.LoginCommand.java
public IStatus doIt() { try {//from ww w .j a v a2s . c o m URI infoURI = URIUtil.toURI(target.getUrl()); infoURI = infoURI.resolve("/v2/info"); GetMethod getMethod = new GetMethod(infoURI.toString()); getMethod.addRequestHeader(new Header("Accept", "application/json")); getMethod.addRequestHeader(new Header("Content-Type", "application/json")); String response; try { CFActivator.getDefault().getHttpClient().executeMethod(getMethod); response = getMethod.getResponseBodyAsString(); } finally { getMethod.releaseConnection(); } JSONObject result = new JSONObject(response); // login String authorizationEndpoint = result.getString("authorization_endpoint"); URI loginURI = new URI(authorizationEndpoint); loginURI = URIUtil.append(loginURI, "/oauth/token"); PostMethod postMethod = new PostMethod(loginURI.toString()); postMethod.addRequestHeader(new Header("Accept", "application/json")); postMethod.addRequestHeader(new Header("Content-Type", "application/x-www-form-urlencoded")); postMethod.addRequestHeader(new Header("Authorization", "Basic Y2Y6")); postMethod.addParameter("grant_type", "password"); postMethod.addParameter("password", this.password); postMethod.addParameter("username", this.username); postMethod.addParameter("scope", ""); try { int code = CFActivator.getDefault().getHttpClient().executeMethod(postMethod); response = postMethod.getResponseBodyAsString(); if (code != HttpServletResponse.SC_OK) { try { result = new JSONObject(response); return new ServerStatus(Status.ERROR, code, "", result, null); } catch (Exception e) { result = null; return new ServerStatus(Status.ERROR, code, "Unexpected error", null); } } } finally { postMethod.releaseConnection(); } target.getCloud().setAccessToken(new JSONObject(response)); } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new Status(IStatus.ERROR, CFActivator.PI_CF, msg, e); } return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK); }
From source file:org.eclipse.orion.server.cf.commands.GetAppByGuidCommand.java
public ServerStatus _doIt() { try {/*w w w . ja va2 s. c o m*/ URI targetURI = URIUtil.toURI(getCloud().getUrl()); // Get the app URI appsURI = targetURI.resolve("/v2/apps/" + appGuid); GetMethod getAppsMethod = new GetMethod(appsURI.toString()); HttpUtil.configureHttpMethod(getAppsMethod, getCloud()); ServerStatus getStatus = HttpUtil.executeMethod(getAppsMethod); if (!getStatus.isOK()) return getStatus; JSONObject app = getStatus.getJsonData(); // if (!apps.has("resources") || apps.getJSONArray("resources").length() == 0) // return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "Application not found", null); // Get more details about the app JSONObject appJSON = app.getJSONObject("metadata"); String summaryAppUrl = appJSON.getString("url") + "/summary"; URI summaryAppURI = targetURI.resolve(summaryAppUrl); GetMethod getSummaryMethod = new GetMethod(summaryAppURI.toString()); HttpUtil.configureHttpMethod(getSummaryMethod, getCloud()); getStatus = HttpUtil.executeMethod(getSummaryMethod); if (!getStatus.isOK()) return getStatus; JSONObject summaryJSON = getStatus.getJsonData(); this.app = new App(); this.app.setAppJSON(appJSON); this.app.setSummaryJSON(summaryJSON); this.app.setGuid(appJSON.getString("guid")); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, this.app.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:org.nabucco.testautomation.engine.proxy.web.component.captcha.ReadCaptchaCommand.java
/** * {@inheritDoc}//from ww w .j a v a2s .com */ @Override public PropertyList executeCallback(Metadata metadata, PropertyList properties) throws WebComponentException { String captchaId = this.getComponentLocator(metadata); try { this.waitForElement(captchaId); captchaId += SRC_ATTRIBUTE; String imageLocation = this.getSelenium().getAttribute(captchaId); URI uri = new URI(imageLocation); if (!uri.isAbsolute()) { URI currentLocation = new URI(this.getSelenium().getLocation()); uri = currentLocation.resolve(uri); } URL url = uri.toURL(); this.start(); this.getSelenium().openWindow(url.toString(), CAPTCHA_WINDOW); this.getSelenium().waitForPopUp(CAPTCHA_WINDOW, this.getTimeout()); this.getSelenium().selectWindow(CAPTCHA_WINDOW); this.imageData = decode(this.getSelenium().captureEntirePageScreenshotToString("background=#FFFFFF")); this.getSelenium().close(); this.getSelenium().selectWindow(null); this.stop(); return null; } catch (IOException ex) { this.stop(); this.setException(ex); throw new WebComponentException("Error during captcha identification: " + ex.getMessage()); } catch (URISyntaxException ex) { this.stop(); this.setException(ex); throw new WebComponentException("Error locating WebCaptcha: " + ex.getMessage()); } }
From source file:uk.ac.ebi.eva.pipeline.jobs.steps.PopulationStatisticsLoaderStep.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { ObjectMap variantOptions = jobOptions.getVariantOptions(); ObjectMap pipelineOptions = jobOptions.getPipelineOptions(); VariantStorageManager variantStorageManager = StorageManagerFactory.getVariantStorageManager(); VariantSource variantSource = variantOptions.get(VariantStorageManager.VARIANT_SOURCE, VariantSource.class); VariantDBAdaptor dbAdaptor = variantStorageManager .getDBAdaptor(variantOptions.getString(VariantStorageManager.DB_NAME), variantOptions); URI outdirUri = URLHelper.createUri(pipelineOptions.getString("output.dir.statistics")); URI statsOutputUri = outdirUri.resolve(VariantStorageManager.buildFilename(variantSource)); VariantStatisticsManager variantStatisticsManager = new VariantStatisticsManager(); QueryOptions statsOptions = new QueryOptions(variantOptions); // actual stats load variantStatisticsManager.loadStats(dbAdaptor, statsOutputUri, statsOptions); return RepeatStatus.FINISHED; }
From source file:org.eclipse.orion.server.cf.commands.UpdateApplicationCommand.java
@Override protected ServerStatus _doIt() { try {/*from w w w .j a v a 2 s .c o m*/ /* get application URL */ URI targetURI = URIUtil.toURI(target.getUrl()); URI appURI = targetURI.resolve(application.getAppJSON().getString(CFProtocolConstants.V2_KEY_URL)); PutMethod updateApplicationMethod = new PutMethod(appURI.toString()); HttpUtil.configureHttpMethod(updateApplicationMethod, target); updateApplicationMethod.setQueryString("async=true&inline-relations-depth=1"); //$NON-NLS-1$ /* set request body */ JSONObject updateAppRequest = new JSONObject(); updateAppRequest.put(CFProtocolConstants.V2_KEY_NAME, appName); updateAppRequest.put(CFProtocolConstants.V2_KEY_INSTANCES, appInstances); updateAppRequest.put(CFProtocolConstants.V2_KEY_COMMAND, appCommand); updateAppRequest.put(CFProtocolConstants.V2_KEY_MEMORY, appMemory); if (env != null) updateAppRequest.put(CFProtocolConstants.V2_KEY_ENVIRONMENT_JSON, env); if (buildPack != null) updateAppRequest.put(CFProtocolConstants.V2_KEY_BUILDPACK, buildPack); updateApplicationMethod.setRequestEntity( new StringRequestEntity(updateAppRequest.toString(), "application/json", "utf-8")); //$NON-NLS-1$ //$NON-NLS-2$ ServerStatus status = HttpUtil.executeMethod(updateApplicationMethod); if (!status.isOK()) return status; 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.orbeon.oxf.util.NetUtils.java
/** * Resolve a URI against a base URI. (Be sure to pay attention to the order or parameters.) * * @param href URI to resolve (accept human-readable URI) * @param base URI base (accept human-readable URI) * @return resolved URI/*from ww w. j a va 2 s .co m*/ */ public static String resolveURI(String href, String base) { final String resolvedURIString; if (base != null) { final URI baseURI; try { baseURI = new URI(encodeHRRI(base, true)); } catch (URISyntaxException e) { throw new OXFException(e); } resolvedURIString = baseURI.resolve(encodeHRRI(href, true)).normalize().toString();// normalize to remove "..", etc. } else { resolvedURIString = encodeHRRI(href, true); } return resolvedURIString; }
From source file:org.chtijbug.drools.platform.rules.config.RuntimeSiteTopology.java
public WebClient webClient(String envName, String resourcePath) { try {/*w w w .ja va 2s. com*/ URI uri = environments.get(envName).getUrl().toURI(); URI baseUri = uri.resolve("/"); JacksonJaxbJsonProvider jsonProvider = new JacksonJaxbJsonProvider(); WebClient client = WebClient.create(baseUri.toString(), asList(jsonProvider)) .path(uri.getPath().concat(resourcePath)); //_____ Adding no timeout feature for long running process ClientConfiguration config = WebClient.getConfig(client); HTTPConduit http = (HTTPConduit) config.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); /* connection timeout for requesting the rule package binaries */ httpClientPolicy.setConnectionTimeout(0L); /* Reception timeout */ httpClientPolicy.setReceiveTimeout(0L); http.setClient(httpClientPolicy); return client; } catch (URISyntaxException e) { throw propagate(e); } }