Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
Doc: corrected typos, indention, and added small bit of content
Browse files Browse the repository at this point in the history
  • Loading branch information
nemonik committed Jul 7, 2015
1 parent b594bbf commit d2851b0
Showing 1 changed file with 55 additions and 55 deletions.
110 changes: 55 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ be modified to support follow-on releases.

A [Heroku hosted instance][heroku instance] of the validator is available for
you to use, or you can [clone, build, and run an instance your own box](#building).
Optionally, you can also create and run a Docker container using the project's Dockerfile.
Optionally, you can also create and run a Docker container using the project's Dockerfile.

## <a name="versioning"></a>Versioning

Expand Down Expand Up @@ -55,80 +55,80 @@ individual, isolated classloaders:
stixSchemas = new HashMap<Version, Object>();
for (Version version : versions) {
try {
try {
ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
Resource[] resources = patternResolver
.getResources("classpath:reflection-libs/v" + version
+ "/**/*.jar");
Resource[] resources = patternResolver
.getResources("classpath:reflection-libs/v" + version
+ "/**/*.jar");
ArrayList<URL> urls = new ArrayList<URL>();
ArrayList<URL> urls = new ArrayList<URL>();
// work around for URLClassLoader's inability to retrieve
// classes from Jars contained within Jars as resources
for (Resource resource : resources) {
ReadableByteChannel readableByteChannel = Channels
.newChannel(resource.getURL().openStream());
File tempFile = File.createTempFile("validator-", null);
FileOutputStream fileOutputStream = new FileOutputStream(
tempFile);
fileOutputStream.getChannel().transferFrom(
readableByteChannel, 0, Long.MAX_VALUE);
fileOutputStream.close();
urls.add(tempFile.toURI().toURL());
}
// work around for URLClassLoader's inability to retrieve
// classes from Jars contained within Jars as resources
for (Resource resource : resources) {
ReadableByteChannel readableByteChannel = Channels
.newChannel(resource.getURL().openStream());
File tempFile = File.createTempFile("validator-", null);
FileOutputStream fileOutputStream = new FileOutputStream(
tempFile);
fileOutputStream.getChannel().transferFrom(
readableByteChannel, 0, Long.MAX_VALUE);
fileOutputStream.close();
urls.add(tempFile.toURI().toURL());
}
@SuppressWarnings({ "resource" })
ClassLoader classLoader = new URLClassLoader(
urls.toArray(new URL[urls.size()]));
@SuppressWarnings({ "resource" })
ClassLoader classLoader = new URLClassLoader(
urls.toArray(new URL[urls.size()]));
Class<?> cls = classLoader
.loadClass("org.mitre.stix.STIXSchema");
Class<?> cls = classLoader
.loadClass("org.mitre.stix.STIXSchema");
@SuppressWarnings("rawtypes")
Constructor[] constructors = cls.getDeclaredConstructors();
constructors[0].setAccessible(true);
Object instance = constructors[0].newInstance();
@SuppressWarnings("rawtypes")
Constructor[] constructors = cls.getDeclaredConstructors();
constructors[0].setAccessible(true);
Object instance = constructors[0].newInstance();
Method setValidationErrorHandlerMethod = instance.getClass()
.getMethod("setValidationErrorHandler",
ErrorHandler.class);
Method setValidationErrorHandlerMethod = instance.getClass()
.getMethod("setValidationErrorHandler",
ErrorHandler.class);
setValidationErrorHandlerMethod.invoke(instance,
new Object[] { null });
setValidationErrorHandlerMethod.invoke(instance,
new Object[] { null });
System.out.println("Created STIXSchema for v " + version
+ " instance");
System.out.println("Created STIXSchema for v " + version
+ " instance");
stixSchemas.put(version, instance);
stixSchemas.put(version, instance);
} catch (ClassNotFoundException | SecurityException
| IllegalAccessException | IllegalArgumentException
| InvocationTargetException | IOException
| InstantiationException | NoSuchMethodException e) {
} catch (ClassNotFoundException | SecurityException
| IllegalAccessException | IllegalArgumentException
| InvocationTargetException | IOException
| InstantiationException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
throw new RuntimeException(e);
}
```

to permit the the validator's microservice to validate documents across the most
recent release of the STIX schema version:

```
for (Version knownVersion : stixSchemas.keySet()) {
if (lookForVersion.equals(knownVersion)) {
Object obj = stixSchemas.get(knownVersion);
if (lookForVersion.equals(knownVersion)) {
Object obj = stixSchemas.get(knownVersion);
Method validateMethod;
try {
validateMethod = obj.getClass().getMethod("validate",
String.class);
validates = (boolean) validateMethod.invoke(obj,
xmlText);
break;
Method validateMethod;
try {
validateMethod = obj.getClass().getMethod("validate",
String.class);
validates = (boolean) validateMethod.invoke(obj,
xmlText);
break;
} catch (InvocationTargetException e) {
} catch (InvocationTargetException e) {
```

Expand Down Expand Up @@ -187,11 +187,11 @@ by setting an environmental variable like so:
Alternatively, if you have Docker installed, from the root of the project run
the following to create a container image for this Dockerfile via:

docker build -t stix/validator .
docker build -rm -t stix/validator .

Then create a container using the image you just created via:

docker run -t -i -p 8080:8080 stix/valiator
docker run -p 8080:8080 -it --rm --name validator stix/validator

If you're using boot2docker, you will need to access via VM’s host only interface IP
address:
Expand Down

0 comments on commit d2851b0

Please sign in to comment.