org.eclipse.core.runtime.URIUtil Java Examples
The following examples show how to use
org.eclipse.core.runtime.URIUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetInfoCommand.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Override protected ServerStatus _doIt() { try { /* get available orgs */ URI infoURI = URIUtil.toURI(getCloud().getUrl()).resolve("/v2/info"); GetMethod getInfoMethod = new GetMethod(infoURI.toString()); ServerStatus confStatus = HttpUtil.configureHttpMethod(getInfoMethod, getCloud()); /* Getting info when not authenticated should not fail */ ServerStatus status = HttpUtil.executeMethod(getInfoMethod); return status; } catch (Exception e) { String msg = NLS.bind("An error occurred when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
Example #2
Source File: UnmapRouteCommand.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Override protected ServerStatus _doIt() { try { /* unmap route from application */ URI targetURI = URIUtil.toURI(target.getUrl()); DeleteMethod unmapRouteMethod = new DeleteMethod(targetURI.resolve("/v2/apps/" + app.getGuid() + "/routes/" + route.getGuid()).toString()); //$NON-NLS-1$//$NON-NLS-2$ ServerStatus confStatus = HttpUtil.configureHttpMethod(unmapRouteMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; return HttpUtil.executeMethod(unmapRouteMethod); } 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); } }
Example #3
Source File: SiteConfigurationServlet.java From orion.server with Eclipse Public License 1.0 | 6 votes |
private boolean doGetAllSiteConfigurations(HttpServletRequest req, HttpServletResponse resp, String userName) throws ServletException { try { UserInfo user = OrionConfiguration.getMetaStore().readUser(userName); //user info stores an object where key is site id, value is site info, but we just want the values URI base = ServletResourceHandler.getURI(req); JSONArray configurations = new JSONArray(); JSONObject sites = SiteInfo.getSites(user); final String[] names = JSONObject.getNames(sites); if (names != null) { for (String siteId : names) { //add site resource location based on current request URI final JSONObject siteInfo = sites.getJSONObject(siteId); siteInfo.put(ProtocolConstants.KEY_LOCATION, URIUtil.append(base, siteId)); configurations.put(siteInfo); } } JSONObject jsonResponse = new JSONObject(); jsonResponse.put(SiteConfigurationConstants.KEY_SITE_CONFIGURATIONS, configurations); writeJSONResponse(req, resp, jsonResponse, JsonURIUnqualificationStrategy.LOCATION_ONLY); } catch (Exception e) { LogHelper.log(e); handleException(resp, "An error occurred while obtaining site configurations", e); } return true; }
Example #4
Source File: HostedSiteServlet.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Returns paths constructed by rewriting pathInfo using rules from the hosted site's mappings. * Paths are ordered from most to least specific match. * @param site The hosted site. * @param pathInfo Path to be rewritten. * @param queryString * @return The rewritten path. May be either:<ul> * <li>A path to a file in the Orion workspace, eg. <code>/ProjectA/foo/bar.txt</code></li> * <li>An absolute URL pointing to another site, eg. <code>http://foo.com/bar.txt</code></li> * </ul> * @return The rewritten paths. * @throws URISyntaxException */ private URI[] getMapped(IHostedSite site, IPath pathInfo, String queryString) throws URISyntaxException { final Map<String, List<String>> map = site.getMappings(); final IPath originalPath = pathInfo; IPath path = originalPath.removeTrailingSeparator(); List<URI> uris = new ArrayList<URI>(); String rest = null; final int count = path.segmentCount(); for (int i = 0; i <= count; i++) { List<String> base = map.get(path.toString()); if (base != null) { rest = originalPath.removeFirstSegments(count - i).toString(); for (int j = 0; j < base.size(); j++) { URI uri = (rest.equals("") || rest.equals("/")) ? new URI(base.get(j)) : URIUtil.append(new URI(base.get(j)), rest); uris.add(createUri(uri, queryString)); } } path = path.removeLastSegments(1); } if (uris.size() == 0) // No mapping for / return null; else return uris.toArray(new URI[uris.size()]); }
Example #5
Source File: InternalConfigurationType.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void notifyCheckConfigRemoved(ICheckConfiguration checkConfiguration) throws CheckstylePluginException { super.notifyCheckConfigRemoved(checkConfiguration); // remove the configuration file from the workspace metadata URL configFileURL = checkConfiguration.getResolvedConfigurationFileURL(); if (configFileURL != null) { try { File configFile = URIUtil.toFile(configFileURL.toURI()); if (configFile != null) { configFile.delete(); } } catch (URISyntaxException e) { CheckstylePluginException.rethrow(e); } } }
Example #6
Source File: ConfigurationType.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Gets the property resolver for this configuration type used to expand property values within * the checkstyle configuration. * * @param checkConfiguration * the actual check configuration * @return the property resolver * @throws IOException * error creating the property resolver * @throws URISyntaxException * if configuration file URL cannot be resolved */ protected PropertyResolver getPropertyResolver(ICheckConfiguration config, CheckstyleConfigurationFile configFile) throws IOException, URISyntaxException { MultiPropertyResolver multiResolver = new MultiPropertyResolver(); multiResolver.addPropertyResolver(new ResolvablePropertyResolver(config)); File f = URIUtil.toFile(configFile.getResolvedConfigFileURL().toURI()); if (f != null) { multiResolver.addPropertyResolver(new StandardPropertyResolver(f.toString())); } else { multiResolver.addPropertyResolver( new StandardPropertyResolver(configFile.getResolvedConfigFileURL().toString())); } multiResolver.addPropertyResolver(new ClasspathVariableResolver()); multiResolver.addPropertyResolver(new SystemPropertyResolver()); if (configFile.getAdditionalPropertiesBundleStream() != null) { ResourceBundle bundle = new PropertyResourceBundle( configFile.getAdditionalPropertiesBundleStream()); multiResolver.addPropertyResolver(new ResourceBundlePropertyResolver(bundle)); } return multiResolver; }
Example #7
Source File: CheckConfigurationFactory.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Copy the checkstyle configuration of a check configuration into another configuration. * * @param source * the source check configuration * @param target * the target check configuartion * @throws CheckstylePluginException * Error copying the configuration */ public static void copyConfiguration(ICheckConfiguration source, ICheckConfiguration target) throws CheckstylePluginException { try { // use the export function ;-) File targetFile; targetFile = URIUtil.toFile(target.getResolvedConfigurationFileURL().toURI()); File sourceFile = URIUtil.toFile(source.getResolvedConfigurationFileURL().toURI()); // copying from a file to the same file will destroy it. if (Objects.equals(targetFile, sourceFile)) { return; } exportConfiguration(targetFile, source); } catch (URISyntaxException e) { CheckstylePluginException.rethrow(e); } }
Example #8
Source File: GetServiceByNameCommand.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Override protected ServerStatus _doIt() { try { URI targetURI = URIUtil.toURI(target.getUrl()); URI servicesURI = targetURI.resolve("/v2/spaces/" + target.getSpace().getGuid() + "/services"); //$NON-NLS-0$//$NON-NLS-1$ GetMethod getServicesMethod = new GetMethod(servicesURI.toString()); NameValuePair[] params = new NameValuePair[] { // new NameValuePair("q", "label:" + serviceName), //$NON-NLS-0$ //$NON-NLS-1$ new NameValuePair("inline-relations-depth", "1") //$NON-NLS-0$ //$NON-NLS-1$ }; getServicesMethod.setQueryString(params); ServerStatus confStatus = HttpUtil.configureHttpMethod(getServicesMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; return HttpUtil.executeMethod(getServicesMethod); } 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); } }
Example #9
Source File: GetServiceCommand.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Override protected ServerStatus _doIt() { try { URI targetURI = URIUtil.toURI(target.getUrl()); URI serviceInstanceURI = targetURI.resolve("/v2/services/" + serviceGuid); //$NON-NLS-1$//$NON-NLS-2$ GetMethod getServiceMethod = new GetMethod(serviceInstanceURI.toString()); ServerStatus confStatus = HttpUtil.configureHttpMethod(getServiceMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; ServerStatus getStatus = HttpUtil.executeMethod(getServiceMethod); if (!getStatus.isOK()) return getStatus; JSONObject service = getStatus.getJsonData(); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, service); } 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); } }
Example #10
Source File: GetRouteByGuidCommand.java From orion.server with Eclipse Public License 1.0 | 6 votes |
public ServerStatus _doIt() { try { URI targetURI = URIUtil.toURI(getCloud().getUrl()); // Get the app URI appsURI = targetURI.resolve("/v2/routes/" + routeGuid); GetMethod getRoutesMethod = new GetMethod(appsURI.toString()); ServerStatus confStatus = HttpUtil.configureHttpMethod(getRoutesMethod, getCloud()); if (!confStatus.isOK()) return confStatus; ServerStatus getStatus = HttpUtil.executeMethod(getRoutesMethod); if (!getStatus.isOK()) return getStatus; JSONObject routeJSON = getStatus.getJsonData(); this.route = new Route().setCFJSON(routeJSON); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, this.route.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); } }
Example #11
Source File: AttachRouteCommand.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Override protected ServerStatus _doIt() { try { /* attach route to application */ URI targetURI = URIUtil.toURI(target.getUrl()); PutMethod attachRouteMethod = new PutMethod(targetURI.resolve("/v2/apps/" + application.getGuid() + "/routes/" + routeGUID).toString()); //$NON-NLS-1$//$NON-NLS-2$ ServerStatus confStatus = HttpUtil.configureHttpMethod(attachRouteMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; return HttpUtil.executeMethod(attachRouteMethod); } 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); } }
Example #12
Source File: DeleteRouteCommand.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Override protected ServerStatus _doIt() { try { URI targetURI = URIUtil.toURI(target.getUrl()); /* delete the route */ URI routeURI = targetURI.resolve("/v2/routes/" + route.getGuid()); //$NON-NLS-1$ DeleteMethod deleteRouteMethod = new DeleteMethod(routeURI.toString()); ServerStatus confStatus = HttpUtil.configureHttpMethod(deleteRouteMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; deleteRouteMethod.setQueryString("recursive=true"); //$NON-NLS-1$ ServerStatus status = HttpUtil.executeMethod(deleteRouteMethod); return status; } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
Example #13
Source File: DataflowProjectCreator.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
private DataflowProjectValidationStatus validateProjectLocation() { if (!customLocation || projectLocation == null) { return DataflowProjectValidationStatus.OK; } File file = URIUtil.toFile(projectLocation); if (file == null) { return DataflowProjectValidationStatus.LOCATION_NOT_LOCAL; } if (!file.exists()) { return DataflowProjectValidationStatus.NO_SUCH_LOCATION; } if (!file.isDirectory()) { return DataflowProjectValidationStatus.LOCATION_NOT_DIRECTORY; } return DataflowProjectValidationStatus.OK; }
Example #14
Source File: SearchTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Setup a project with some files that we can use for search tests. * @throws CoreException * @throws IOException * @throws SAXException */ private void createTestData() throws Exception { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/searchTest/files.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); IPath path = new Path("/xfer/import").append(getTestBaseResourceURILocation()).append(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(URIUtil.fromString(SERVER_LOCATION + path.toString()).toString()); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); doImport(source, length, location); }
Example #15
Source File: MapRouteCommand.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Override protected ServerStatus _doIt() { try { /* attach route to application */ URI targetURI = URIUtil.toURI(target.getUrl()); PutMethod attachRouteMethod = new PutMethod(targetURI.resolve("/v2/apps/" + application.getGuid() + "/routes/" + routeGUID).toString()); //$NON-NLS-1$//$NON-NLS-2$ ServerStatus confStatus = HttpUtil.configureHttpMethod(attachRouteMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; return HttpUtil.executeMethod(attachRouteMethod); } 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); } }
Example #16
Source File: CoreFilesTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Test to read the workspace.json at the /file/workspace top level, see Bug 415700. * @throws IOException * @throws SAXException * @throws URISyntaxException * @throws JSONException */ @Ignore public void testReadWorkspaceJsonTopLevelFile() throws IOException, SAXException, URISyntaxException, JSONException { if (!(OrionConfiguration.getMetaStore() instanceof SimpleMetaStore)) { // This test is only supported by a SimpleMetaStore return; } String workspaceJSONFileName = "workspace.json"; IPath projectLocation = new Path(getTestBaseResourceURILocation()); String workspaceId = projectLocation.segment(0); String uriPath = new Path(FILE_SERVLET_LOCATION).append(workspaceId).append(workspaceJSONFileName).toString(); String requestPath = URIUtil.fromString(SERVER_LOCATION + uriPath).toString(); WebRequest request = new GetMethodWebRequest(requestPath); request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1"); setAuthentication(request); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject responseObject = new JSONObject(response.getText()); assertNotNull(responseObject.get(MetadataInfo.UNIQUE_ID)); assertNotNull(responseObject.get("ProjectNames")); }
Example #17
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Test public void testImportAndUnzip() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location); //assert the file has been unzipped in the workspace assertTrue(checkFileExists(directoryPath + "/org.eclipse.e4.webide/static/js/navigate-tree/navigate-tree.js")); }
Example #18
Source File: DirectoryHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
public static void encodeChildren(IFileStore dir, URI location, JSONObject result, int depth, boolean addLocation) throws CoreException { if (depth <= 0) return; JSONArray children = new JSONArray(); //more efficient to ask for child information in bulk for certain file systems IFileInfo[] childInfos = dir.childInfos(EFS.NONE, null); for (IFileInfo childInfo : childInfos) { IFileStore childStore = dir.getChild(childInfo.getName()); String name = childInfo.getName(); if (childInfo.isDirectory()) name += "/"; //$NON-NLS-1$ URI childLocation = URIUtil.append(location, name); JSONObject childResult = ServletFileStoreHandler.toJSON(childStore, childInfo, addLocation ? childLocation : null); if (childInfo.isDirectory()) encodeChildren(childStore, childLocation, childResult, depth - 1); children.put(childResult); } try { result.put(ProtocolConstants.KEY_CHILDREN, children); } catch (JSONException e) { // cannot happen throw new RuntimeException(e); } }
Example #19
Source File: DirectoryHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
private boolean handlePost(HttpServletRequest request, HttpServletResponse response, IFileStore dir) throws JSONException, CoreException, ServletException, IOException { //setup and precondition checks JSONObject requestObject = OrionServlet.readJSONRequest(request); String name = computeName(request, requestObject); if (name.length() == 0) return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "File name not specified.", null)); IFileStore toCreate = dir.getChild(name); if (!name.equals(toCreate.getName()) || name.contains(":")) return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Bad file name: " + name, null)); int options = getCreateOptions(request); boolean destinationExists = toCreate.fetchInfo(EFS.NONE, null).exists(); if (!validateOptions(request, response, toCreate, destinationExists, options)) return true; //perform the operation if (performPost(request, response, requestObject, toCreate, options)) { //write the response URI location = URIUtil.append(getURI(request), name); JSONObject result = ServletFileStoreHandler.toJSON(toCreate, toCreate.fetchInfo(EFS.NONE, null), location); result.append("FileEncoding", System.getProperty("file.encoding")); OrionServlet.writeJSONResponse(request, response, result); response.setHeader(ProtocolConstants.HEADER_LOCATION, ServletResourceHandler.resovleOrionURI(request, location).toASCIIString()); //response code should indicate if a new resource was actually created or not response.setStatus(destinationExists ? HttpServletResponse.SC_OK : HttpServletResponse.SC_CREATED); } return true; }
Example #20
Source File: TestVMType.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static File getFakeJDKsLocation() { Bundle bundle = Platform.getBundle(JavaLanguageServerTestPlugin.PLUGIN_ID); try { URL url = FileLocator.toFileURL(bundle.getEntry(FAKE_JDK)); File file = URIUtil.toFile(URIUtil.toURI(url)); return file; } catch (IOException | URISyntaxException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); return null; } }
Example #21
Source File: TmfTraceManagerUtilityTest.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Test the {@link TmfTraceManager#getTemporaryDirPath} method. * @throws URISyntaxException * in case of URI syntax error */ @Test public void testTemporaryDirPath() throws URISyntaxException { String tempDirPath = TmfTraceManager.getTemporaryDirPath(); assertTrue(tempDirPath.endsWith(TEMP_DIR_NAME)); String property = System.getProperty("osgi.instance.area"); //$NON-NLS-1$ File dir = URIUtil.toFile(URIUtil.fromString(property)); String basePath = dir.getAbsolutePath(); assertTrue(tempDirPath.startsWith(basePath)); }
Example #22
Source File: JavaDocLocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the {@link File} of a <code>file:</code> URL. This method tries to recover from bad URLs, * e.g. the unencoded form we used to use in persistent storage. * * @param url a <code>file:</code> URL * @return the file * @since 3.9 */ public static File toFile(URL url) { try { return URIUtil.toFile(url.toURI()); } catch (URISyntaxException e) { JavaPlugin.log(e); return new File(url.getFile()); } }
Example #23
Source File: FileSystemTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
protected URI makeLocalPathAbsolute(String path) { String absolutePath = getAbsolutePath(path); try { return URIUtil.fromString(absolutePath); } catch (URISyntaxException e) { fail(e.getMessage()); return null; } }
Example #24
Source File: JavadocConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void validateURL(URL location) throws MalformedURLException, URISyntaxException { URI path= URIUtil.toURI(location); URI index = URIUtil.append(path, "index.html"); //$NON-NLS-1$ URI packagelist = URIUtil.append(path, "package-list"); //$NON-NLS-1$ URL indexURL = URIUtil.toURL(index); URL packagelistURL = URIUtil.toURL(packagelist); boolean suc= checkURLConnection(indexURL) && checkURLConnection(packagelistURL); if (suc) { showConfirmValidationDialog(indexURL); } else { MessageDialog.openWarning(fShell, fTitle, fInvalidMessage); } }
Example #25
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportWithPostZeroByteFile() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/zeroByteFile.txt"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); assertEquals(length, 0); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", "zeroByteFile.txt"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location, "text/plain"); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + "/zeroByteFile.txt")); }
Example #26
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportFileMultiPart() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); // current server implementation cannot handle binary data, thus base64-encode client.zip before import File expected = EFS.getStore(makeLocalPathAbsolute(directoryPath + "/expected.txt")).toLocalFile(EFS.NONE, null); byte[] expectedContent = Base64.encode(FileUtils.readFileToByteArray(source)); FileUtils.writeByteArrayToFile(expected, expectedContent); //start the import long length = expectedContent.length; String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", "actual.txt"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); // perform the upload doImport(expected, length, location, "multipart/mixed;boundary=foobar"); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + "/actual.txt")); //assert that actual.txt has same content as expected.txt assertTrue(checkContentEquals(expected, directoryPath + "/actual.txt")); }
Example #27
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportDBCSFilename() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import // file with DBCS character in the filename. String filename = "\u3042.txt"; File source = null; try { source = createTempFile(filename, "No content"); long length = source.length(); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", Slug.encode(filename)); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location, "text/plain"); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + File.separator + filename)); //assert that imported file has same content as original client.zip assertTrue(checkContentEquals(source, directoryPath + File.separator + filename)); } finally { // Delete the temp file FileUtils.deleteQuietly(source); } }
Example #28
Source File: TransferTest.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testImportFile() throws CoreException, IOException, SAXException, URISyntaxException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); String importPath = getImportRequestPath(directoryPath); PostMethodWebRequest request = new PostMethodWebRequest(importPath); request.setHeaderField("X-Xfer-Content-Length", Long.toString(length)); request.setHeaderField("X-Xfer-Options", "raw"); request.setHeaderField("Slug", "client.zip"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, postResponse.getResponseCode()); String location = postResponse.getHeaderField("Location"); assertNotNull(location); URI importURI = URIUtil.fromString(importPath); location = importURI.resolve(location).toString(); doImport(source, length, location); //assert the file is present in the workspace assertTrue(checkFileExists(directoryPath + "/client.zip")); //assert that imported file has same content as original client.zip assertTrue(checkContentEquals(source, directoryPath + "/client.zip")); }
Example #29
Source File: DropAdapterAssistant.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
/** * Drop a trace by importing/linking a path in a trace folder * * @param path the source path * @param traceFolder the target trace folder * @param operation the drop operation (DND.DROP_COPY | DND.DROP_LINK) * @return true if successful */ private static boolean drop(Path path, TmfTraceFolder traceFolder, int operation) { String targetName = path.lastSegment(); for (ITmfProjectModelElement element : traceFolder.getChildren()) { if (element.getName().equals(targetName)) { targetName = promptRename(element); if (targetName == null) { return false; } break; } } if (operation == DND.DROP_COPY) { importTrace(traceFolder.getResource(), path, targetName); } else { createLink(traceFolder.getResource(), path, targetName); } IResource traceResource = traceFolder.getResource().findMember(targetName); if (traceResource != null && traceResource.exists()) { try { String sourceLocation = URIUtil.toUnencodedString(path.toFile().toURI()); traceResource.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation); } catch (CoreException e) { TraceUtils.displayErrorMsg(e); } setTraceType(traceResource); } return true; }
Example #30
Source File: BuiltInFilePropertyResolver.java From eclipse-cs with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ @Override public String resolve(String property) { String value = null; if ((SAMEDIR_LOC.equals(property) || CONFIG_LOC.equals(property)) && mBuiltInConfigLocation != null) { int lastSlash = mBuiltInConfigLocation.lastIndexOf("/"); //$NON-NLS-1$ if (lastSlash > -1) { value = mBuiltInConfigLocation.substring(0, lastSlash + 1); } } if (value != null) { try { URL bundleLocatedURL = new URL(value); URL fileURL = FileLocator.toFileURL(bundleLocatedURL); value = URIUtil.toFile(fileURL.toURI()).getAbsolutePath(); } catch (IOException | URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } } return value; }