Search in sources :

Example 1 with FileNotFoundException

use of java.io.FileNotFoundException in project jetty.project by eclipse.

the class SslConnectionFactoryTest method before.

@Before
public void before() throws Exception {
    String keystorePath = "src/test/resources/keystore";
    File keystoreFile = new File(keystorePath);
    if (!keystoreFile.exists())
        throw new FileNotFoundException(keystoreFile.getAbsolutePath());
    _server = new Server();
    HttpConfiguration http_config = new HttpConfiguration();
    http_config.setSecureScheme("https");
    http_config.setSecurePort(8443);
    http_config.setOutputBufferSize(32768);
    HttpConfiguration https_config = new HttpConfiguration(http_config);
    https_config.addCustomizer(new SecureRequestCustomizer());
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystoreFile.getAbsolutePath());
    sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    ServerConnector https = _connector = new ServerConnector(_server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(https_config));
    https.setPort(0);
    https.setIdleTimeout(30000);
    _server.addConnector(https);
    _server.setHandler(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            response.setStatus(200);
            response.getWriter().write("url=" + request.getRequestURI() + "\nhost=" + request.getServerName());
            response.flushBuffer();
        }
    });
    _server.start();
    _port = https.getLocalPort();
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) FileNotFoundException(java.io.FileNotFoundException) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) IOException(java.io.IOException) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) File(java.io.File) Before(org.junit.Before)

Example 2 with FileNotFoundException

use of java.io.FileNotFoundException in project buck by facebook.

the class GenStringSourceMapStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) {
    // Read the R.txt file that was generated by aapt during GenRDotTxtUtil.
    // This file contains all the resource names and the integer id that aapt assigned.
    Path rDotTxtPath = rDotTxtDir.resolve("R.txt");
    try {
        CompileStringsStep.buildResourceNameToIdMap(filesystem, rDotTxtPath, stringResourceNameToIdMap, pluralsResourceNameToIdMap, arrayResourceNameToIdMap);
    } catch (FileNotFoundException ex) {
        context.logError(ex, "The '%s' file is not present.", rDotTxtPath);
        return StepExecutionResult.ERROR;
    } catch (IOException ex) {
        context.logError(ex, "Failure parsing R.txt file.");
        return StepExecutionResult.ERROR;
    }
    Map<String, Map<String, NativeResourceInfo>> nativeStrings = parseStringFiles(context);
    // write nativeStrings out to a file
    Path outputPath = destinationPath.resolve("strings.json");
    try {
        ObjectMapper mapper = ObjectMappers.newDefaultInstance();
        mapper.writeValue(filesystem.getPathForRelativePath(outputPath).toFile(), nativeStrings);
    } catch (IOException ex) {
        context.logError(ex, "Failed when trying to save the output file: '%s'", outputPath.toString());
        return StepExecutionResult.ERROR;
    }
    return StepExecutionResult.SUCCESS;
}
Also used : Path(java.nio.file.Path) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with FileNotFoundException

use of java.io.FileNotFoundException in project buck by facebook.

the class AppleSimulatorDiscovery method discoverAppleSimulatorProfile.

/**
   * Given a simulators, looks up metadata on the supported architectures
   * and product families for that simulator (if present).
   */
public static Optional<AppleSimulatorProfile> discoverAppleSimulatorProfile(AppleSimulator appleSimulator, Path iphonesimulatorPlatformRoot) throws IOException {
    Path simulatorProfilePlistPath = iphonesimulatorPlatformRoot.resolve(String.format("Developer/Library/CoreSimulator/Profiles/DeviceTypes/%s.simdevicetype/" + "Contents/Resources/profile.plist", appleSimulator.getName()));
    LOG.debug("Parsing simulator profile plist %s", simulatorProfilePlistPath);
    try (InputStream inputStream = Files.newInputStream(simulatorProfilePlistPath)) {
        // This might return Optional.empty() if the input could not be parsed.
        return AppleSimulatorProfileParsing.parseProfilePlistStream(inputStream);
    } catch (FileNotFoundException | NoSuchFileException e) {
        LOG.warn(e, "Could not open simulator profile %s, ignoring", simulatorProfilePlistPath);
        return Optional.empty();
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) NoSuchFileException(java.nio.file.NoSuchFileException)

Example 4 with FileNotFoundException

use of java.io.FileNotFoundException in project elasticsearch by elastic.

the class IndexFolderUpgrader method upgrade.

/**
     * Moves the index folder found in <code>source</code> to <code>target</code>
     */
void upgrade(final Index index, final Path source, final Path target) throws IOException {
    boolean success = false;
    try {
        Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
        success = true;
    } catch (NoSuchFileException | FileNotFoundException exception) {
        // thrown when the source is non-existent because the folder was renamed
        // by another node (shared FS) after we checked if the target exists
        logger.error((Supplier<?>) () -> new ParameterizedMessage("multiple nodes trying to upgrade [{}] in parallel, retry " + "upgrading with single node", target), exception);
        throw exception;
    } finally {
        if (success) {
            logger.info("{} moved from [{}] to [{}]", index, source, target);
            logger.trace("{} syncing directory [{}]", index, target);
            IOUtils.fsync(target, true);
        }
    }
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException) Supplier(org.apache.logging.log4j.util.Supplier) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Example 5 with FileNotFoundException

use of java.io.FileNotFoundException in project elasticsearch by elastic.

the class BytesRestResponseTests method testErrorToAndFromXContent.

public void testErrorToAndFromXContent() throws IOException {
    final boolean detailed = randomBoolean();
    Exception original;
    ElasticsearchException cause = null;
    String reason;
    String type = "exception";
    RestStatus status = RestStatus.INTERNAL_SERVER_ERROR;
    boolean addHeadersOrMetadata = false;
    switch(randomIntBetween(0, 5)) {
        case 0:
            original = new ElasticsearchException("ElasticsearchException without cause");
            if (detailed) {
                addHeadersOrMetadata = randomBoolean();
                reason = "ElasticsearchException without cause";
            } else {
                reason = "ElasticsearchException[ElasticsearchException without cause]";
            }
            break;
        case 1:
            original = new ElasticsearchException("ElasticsearchException with a cause", new FileNotFoundException("missing"));
            if (detailed) {
                addHeadersOrMetadata = randomBoolean();
                type = "exception";
                reason = "ElasticsearchException with a cause";
                cause = new ElasticsearchException("Elasticsearch exception [type=file_not_found_exception, reason=missing]");
            } else {
                reason = "ElasticsearchException[ElasticsearchException with a cause]";
            }
            break;
        case 2:
            original = new ResourceNotFoundException("ElasticsearchException with custom status");
            status = RestStatus.NOT_FOUND;
            if (detailed) {
                addHeadersOrMetadata = randomBoolean();
                type = "resource_not_found_exception";
                reason = "ElasticsearchException with custom status";
            } else {
                reason = "ResourceNotFoundException[ElasticsearchException with custom status]";
            }
            break;
        case 3:
            TransportAddress address = buildNewFakeTransportAddress();
            original = new RemoteTransportException("remote", address, "action", new ResourceAlreadyExistsException("ElasticsearchWrapperException with a cause that has a custom status"));
            status = RestStatus.BAD_REQUEST;
            if (detailed) {
                type = "resource_already_exists_exception";
                reason = "ElasticsearchWrapperException with a cause that has a custom status";
            } else {
                reason = "RemoteTransportException[[remote][" + address.toString() + "][action]]";
            }
            break;
        case 4:
            original = new RemoteTransportException("ElasticsearchWrapperException with a cause that has a special treatment", new IllegalArgumentException("wrong"));
            status = RestStatus.BAD_REQUEST;
            if (detailed) {
                type = "illegal_argument_exception";
                reason = "wrong";
            } else {
                reason = "RemoteTransportException[[ElasticsearchWrapperException with a cause that has a special treatment]]";
            }
            break;
        case 5:
            status = randomFrom(RestStatus.values());
            original = new ElasticsearchStatusException("ElasticsearchStatusException with random status", status);
            if (detailed) {
                addHeadersOrMetadata = randomBoolean();
                type = "status_exception";
                reason = "ElasticsearchStatusException with random status";
            } else {
                reason = "ElasticsearchStatusException[ElasticsearchStatusException with random status]";
            }
            break;
        default:
            throw new UnsupportedOperationException("Failed to generate random exception");
    }
    String message = "Elasticsearch exception [type=" + type + ", reason=" + reason + "]";
    ElasticsearchStatusException expected = new ElasticsearchStatusException(message, status, cause);
    if (addHeadersOrMetadata) {
        ElasticsearchException originalException = ((ElasticsearchException) original);
        if (randomBoolean()) {
            originalException.addHeader("foo", "bar", "baz");
            expected.addHeader("foo", "bar", "baz");
        }
        if (randomBoolean()) {
            originalException.addMetadata("es.metadata_0", "0");
            expected.addMetadata("es.metadata_0", "0");
        }
        if (randomBoolean()) {
            String resourceType = randomAsciiOfLength(5);
            String resourceId = randomAsciiOfLength(5);
            originalException.setResources(resourceType, resourceId);
            expected.setResources(resourceType, resourceId);
        }
        if (randomBoolean()) {
            originalException.setIndex("_index");
            expected.setIndex("_index");
        }
    }
    final XContentType xContentType = randomFrom(XContentType.values());
    Map<String, String> params = Collections.singletonMap("format", xContentType.mediaType());
    RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();
    RestChannel channel = detailed ? new DetailedExceptionRestChannel(request) : new SimpleExceptionRestChannel(request);
    BytesRestResponse response = new BytesRestResponse(channel, original);
    ElasticsearchException parsedError;
    try (XContentParser parser = createParser(xContentType.xContent(), response.content())) {
        parsedError = BytesRestResponse.errorFromXContent(parser);
        assertNull(parser.nextToken());
    }
    assertEquals(expected.status(), parsedError.status());
    assertDeepEquals(expected, parsedError);
}
Also used : RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) TransportAddress(org.elasticsearch.common.transport.TransportAddress) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) FileNotFoundException(java.io.FileNotFoundException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ElasticsearchException(org.elasticsearch.ElasticsearchException) Matchers.containsString(org.hamcrest.Matchers.containsString) ElasticsearchException(org.elasticsearch.ElasticsearchException) ParsingException(org.elasticsearch.common.ParsingException) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) RemoteTransportException(org.elasticsearch.transport.RemoteTransportException) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) XContentType(org.elasticsearch.common.xcontent.XContentType) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)7047 IOException (java.io.IOException)3959 File (java.io.File)2964 FileInputStream (java.io.FileInputStream)1841 InputStream (java.io.InputStream)1149 FileOutputStream (java.io.FileOutputStream)1134 BufferedReader (java.io.BufferedReader)628 FileReader (java.io.FileReader)549 ArrayList (java.util.ArrayList)547 InputStreamReader (java.io.InputStreamReader)404 Test (org.junit.Test)366 URL (java.net.URL)335 Path (org.apache.hadoop.fs.Path)301 BufferedInputStream (java.io.BufferedInputStream)285 Properties (java.util.Properties)272 OutputStream (java.io.OutputStream)263 HashMap (java.util.HashMap)228 PrintWriter (java.io.PrintWriter)206 UnsupportedEncodingException (java.io.UnsupportedEncodingException)205 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)200