Search in sources :

Example 11 with URISyntaxException

use of java.net.URISyntaxException in project jetty.project by eclipse.

the class WebSocketServerFactory method acceptWebSocket.

@Override
public boolean acceptWebSocket(WebSocketCreator creator, HttpServletRequest request, HttpServletResponse response) throws IOException {
    ClassLoader old = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(contextClassloader);
        // Create Servlet Specific Upgrade Request/Response objects
        ServletUpgradeRequest sockreq = new ServletUpgradeRequest(request);
        ServletUpgradeResponse sockresp = new ServletUpgradeResponse(response);
        Object websocketPojo = creator.createWebSocket(sockreq, sockresp);
        // Handle response forbidden (and similar paths)
        if (sockresp.isCommitted()) {
            return false;
        }
        if (websocketPojo == null) {
            // no creation, sorry
            sockresp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Endpoint Creation Failed");
            return false;
        }
        // Allow Decorators to do their thing
        websocketPojo = getObjectFactory().decorate(websocketPojo);
        // Get the original HTTPConnection
        HttpConnection connection = (HttpConnection) request.getAttribute("org.eclipse.jetty.server.HttpConnection");
        // Send the upgrade
        EventDriver driver = eventDriverFactory.wrap(websocketPojo);
        return upgrade(connection, sockreq, sockresp, driver);
    } catch (URISyntaxException e) {
        throw new IOException("Unable to accept websocket due to mangled URI", e);
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }
}
Also used : EventDriver(org.eclipse.jetty.websocket.common.events.EventDriver) HttpConnection(org.eclipse.jetty.server.HttpConnection) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ServletUpgradeRequest(org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest) ServletUpgradeResponse(org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse)

Example 12 with URISyntaxException

use of java.net.URISyntaxException in project elasticsearch by elastic.

the class URLRepository method checkURL.

/**
     * Makes sure that the url is white listed or if it points to the local file system it matches one on of the root path in path.repo
     */
private URL checkURL(URL url) {
    String protocol = url.getProtocol();
    if (protocol == null) {
        throw new RepositoryException(getMetadata().name(), "unknown url protocol from URL [" + url + "]");
    }
    for (String supportedProtocol : supportedProtocols) {
        if (supportedProtocol.equals(protocol)) {
            try {
                if (URIPattern.match(urlWhiteList, url.toURI())) {
                    // URL matches white list - no additional processing is needed
                    return url;
                }
            } catch (URISyntaxException ex) {
                logger.warn("cannot parse the specified url [{}]", url);
                throw new RepositoryException(getMetadata().name(), "cannot parse the specified url [" + url + "]");
            }
            // We didn't match white list - try to resolve against path.repo
            URL normalizedUrl = environment.resolveRepoURL(url);
            if (normalizedUrl == null) {
                String logMessage = "The specified url [{}] doesn't start with any repository paths specified by the " + "path.repo setting or by {} setting: [{}] ";
                logger.warn(logMessage, url, ALLOWED_URLS_SETTING.getKey(), environment.repoFiles());
                String exceptionMessage = "file url [" + url + "] doesn't match any of the locations specified by path.repo or " + ALLOWED_URLS_SETTING.getKey();
                throw new RepositoryException(getMetadata().name(), exceptionMessage);
            }
            return normalizedUrl;
        }
    }
    throw new RepositoryException(getMetadata().name(), "unsupported url protocol [" + protocol + "] from URL [" + url + "]");
}
Also used : RepositoryException(org.elasticsearch.repositories.RepositoryException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL)

Example 13 with URISyntaxException

use of java.net.URISyntaxException in project elasticsearch by elastic.

the class AzureBlobContainer method move.

@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    logger.trace("move({}, {})", sourceBlobName, targetBlobName);
    try {
        String source = keyPath + sourceBlobName;
        String target = keyPath + targetBlobName;
        logger.debug("moving blob [{}] to [{}] in container {{}}", source, target, blobStore.container());
        blobStore.moveBlob(blobStore.container(), source, target);
    } catch (URISyntaxException | StorageException e) {
        logger.warn("can not move blob [{}] to [{}] in container {{}}: {}", sourceBlobName, targetBlobName, blobStore.container(), e.getMessage());
        throw new IOException(e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) StorageException(com.microsoft.azure.storage.StorageException)

Example 14 with URISyntaxException

use of java.net.URISyntaxException in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method testRemoveAndCreateContainer.

/**
     * When a user remove a container you can not immediately create it again.
     */
public void testRemoveAndCreateContainer() throws Exception {
    final String container = getContainerName().concat("-testremove");
    final AzureStorageService storageService = new AzureStorageServiceImpl(internalCluster().getDefaultSettings());
    // It could happen that we run this test really close to a previous one
    // so we might need some time to be able to create the container
    assertBusy(() -> {
        try {
            storageService.createContainer(null, LocationMode.PRIMARY_ONLY, container);
            logger.debug(" -> container created...");
        } catch (URISyntaxException e) {
            // Incorrect URL. This should never happen.
            fail();
        } catch (StorageException e) {
            // It could happen. Let's wait for a while.
            logger.debug(" -> container is being removed. Let's wait a bit...");
            fail();
        }
    }, 30, TimeUnit.SECONDS);
    storageService.removeContainer(null, LocationMode.PRIMARY_ONLY, container);
    ClusterAdminClient client = client().admin().cluster();
    logger.info("-->  creating azure repository while container is being removed");
    try {
        client.preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), container)).get();
        fail("we should get a RepositoryVerificationException");
    } catch (RepositoryVerificationException e) {
    // Fine we expect that
    }
}
Also used : AzureStorageServiceImpl(org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) URISyntaxException(java.net.URISyntaxException) AzureStorageService(org.elasticsearch.cloud.azure.storage.AzureStorageService) StorageException(com.microsoft.azure.storage.StorageException)

Example 15 with URISyntaxException

use of java.net.URISyntaxException in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method checkContainerName.

/**
     * Create repository with wrong or correct container name
     * @param container Container name we want to create
     * @param correct Is this container name correct
     */
private void checkContainerName(final String container, final boolean correct) throws Exception {
    logger.info("-->  creating azure repository with container name [{}]", container);
    // It could happen that we just removed from a previous test the same container so
    // we can not create it yet.
    assertBusy(() -> {
        try {
            PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), container).put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath()).put(Repository.CHUNK_SIZE_SETTING.getKey(), randomIntBetween(1000, 10000), ByteSizeUnit.BYTES)).get();
            client().admin().cluster().prepareDeleteRepository("test-repo").get();
            try {
                logger.info("--> remove container [{}]", container);
                cleanRepositoryFiles(container);
            } catch (StorageException | URISyntaxException e) {
            // We can ignore that as we just try to clean after the test
            }
            assertTrue(putRepositoryResponse.isAcknowledged() == correct);
        } catch (RepositoryVerificationException e) {
            if (correct) {
                logger.debug(" -> container is being removed. Let's wait a bit...");
                fail();
            }
        }
    }, 5, TimeUnit.MINUTES);
}
Also used : RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException)

Aggregations

URISyntaxException (java.net.URISyntaxException)4043 URI (java.net.URI)2496 IOException (java.io.IOException)1273 File (java.io.File)716 URL (java.net.URL)702 ArrayList (java.util.ArrayList)407 Test (org.junit.Test)274 MalformedURLException (java.net.MalformedURLException)270 InputStream (java.io.InputStream)224 HashMap (java.util.HashMap)212 Response (javax.ws.rs.core.Response)194 Test (org.testng.annotations.Test)175 Parameters (org.testng.annotations.Parameters)166 Builder (javax.ws.rs.client.Invocation.Builder)165 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)165 Map (java.util.Map)162 StorageException (com.microsoft.azure.storage.StorageException)142 Path (java.nio.file.Path)141 URIBuilder (org.apache.http.client.utils.URIBuilder)140 List (java.util.List)125