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();
}
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;
}
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();
}
}
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);
}
}
}
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);
}
Aggregations