Example usage for java.net URISyntaxException getMessage

List of usage examples for java.net URISyntaxException getMessage

Introduction

In this page you can find the example usage for java.net URISyntaxException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns a string describing the parse error.

Usage

From source file:com.izforge.izpack.util.Librarian.java

/**
 * Attempts  to load a library from the classpath.
 *
 * @param name   the library name//from w w  w .java 2  s .co  m
 * @param client the native library client
 * @return <tt>true</tt> if the library was loaded successfully, otherwise <tt>false</tt>
 */
private boolean loadFromClassPath(String name, NativeLibraryClient client) {
    boolean result = false;
    URL url = getResourcePath(name);
    if (url != null) {
        String protocol = url.getProtocol();
        if (protocol.equalsIgnoreCase(FILE_PROTOCOL)) {
            // its a local file
            try {
                String path = new File(url.toURI()).getPath();
                result = load(path, client);
            } catch (URISyntaxException exception) {
                logger.log(Level.WARNING, "Failed to load library: " + name + ": " + exception.getMessage(),
                        exception);
            }
        } else if (protocol.equalsIgnoreCase(JAR_PROTOCOL)) {
            // its a jar file. Extract and load it from 'java.io.tmpdir'
            result = loadJarLibrary(name, url, client);
        }
    }
    return result;
}

From source file:org.apache.droids.protocol.http.HttpProtocol.java

@Override
public boolean isAllowed(URI uri) throws IOException {
    if (forceAllow) {
        return forceAllow;
    }/*from w  ww. j ava  2 s .  c  om*/

    URI baseURI;
    try {
        baseURI = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), "/", null, null);
    } catch (URISyntaxException ex) {
        LOG.error("Unable to determine base URI for " + uri);
        return false;
    }

    NoRobotClient nrc = new NoRobotClient(contentLoader, userAgent);
    try {
        nrc.parse(baseURI);
    } catch (NoRobotException ex) {
        LOG.error("Failure parsing robots.txt: " + ex.getMessage());
        return false;
    }
    boolean test = nrc.isUrlAllowed(uri);
    if (LOG.isInfoEnabled()) {
        LOG.info(uri + " is " + (test ? "allowed" : "denied"));
    }
    return test;
}

From source file:com.collaborne.jsonschema.validator.plugin.ValidateMojo.java

@VisibleForTesting
protected ListProcessingReport validate(JsonNode node, URITranslator uriTranslator, URIManager uriManager,
        JsonSchemaFactory factory) throws ProcessingException {
    ListProcessingReport report = new ListProcessingReport();

    // Determine the schema to be applied to it
    if (!node.hasNonNull("$schema")) {
        ProcessingMessage processingMessage = new ProcessingMessage();
        processingMessage.setMessage("Missing $schema");

        if (requireSchema) {
            report.error(processingMessage);
        } else {//from  w w  w. j a v  a2  s.co  m
            report.warn(processingMessage);
        }
        return report;
    }

    // Load the schema
    String dollarSchema = node.get("$schema").textValue();
    URI schemaUri;
    try {
        schemaUri = new URI(dollarSchema);
    } catch (URISyntaxException e) {
        ProcessingMessage processingMessage = new ProcessingMessage();
        processingMessage.setMessage("Invalid $schema URI '" + dollarSchema + "': " + e.getMessage());
        report.error(processingMessage);
        return report;
    }

    JsonSchema schema = loadedSchemas.get(schemaUri);
    if (schema == null) {
        // Schema we have not seen so far, load and validate it.
        URI realSchemaUri = uriTranslator.translate(schemaUri);
        JsonNode schemaNode = uriManager.getContent(realSchemaUri);

        SyntaxValidator syntaxValidator = factory.getSyntaxValidator();
        syntaxValidator.validateSchema(schemaNode);

        schema = factory.getJsonSchema(schemaNode);
        loadedSchemas.put(schemaUri, schema);
    }

    ProcessingReport validationReport = schema.validate(node, deepCheck);
    report.mergeWith(validationReport);
    return report;
}

From source file:se.lu.nateko.edca.svc.GetCapabilities.java

/**
 * Method run in a separate worker thread when GetCapabilities.execute() is called.
 * Takes the server info from the ServerConnection supplied and stores it as a URI.
 * @param srvs   An array of ServerConnection objects from which to form the URI. May only contain 1.
 *///from www.j av  a2s . com
@Override
protected GetCapabilities doInBackground(ServerConnection... srvs) {
    Log.d(TAG, "doInBackground(ServerConnection...) called.");

    mServerConnection = srvs[0]; // Stores the ServerConnection info.

    /* Try to form an URI from the supplied ServerConnection info. */
    String uriString = mServerConnection.getAddress()
            + "/wms?service=wms&version=1.1.0&request=GetCapabilities";
    try {
        mServerURI = new URI(uriString);
    } catch (URISyntaxException e) {
        Log.e(TAG, e.getMessage() + ": " + uriString);
    }

    try { // Get or wait for exclusive access to the HttpClient.
        mHttpClient = mService.getHttpClient();
    } catch (InterruptedException e) {
        Log.e(TAG, "Thread " + Thread.currentThread().getId() + ": " + e.toString());
    }

    mHasResponse = getCapabilitiesRequest(); // Make the GetCapabilities request to the server and record the success state.
    mService.unlockHttpClient(); // Release the lock on the HttpClient, allowing new connections to be made.
    Log.v(TAG, "GetCapabilities request succeeded: " + String.valueOf(mHasResponse));
    return this;
}

From source file:org.commonjava.maven.atlas.graph.jackson.ProjectRelationshipDeserializer.java

@Override
public T deserialize(final JsonParser jp, final DeserializationContext ctx)
        throws JsonProcessingException, IOException {
    Map<String, Object> ast = new HashMap<String, Object>();
    Map<String, JsonLocation> locations = new HashMap<String, JsonLocation>();

    JsonToken token = jp.getCurrentToken();
    String currentField = null;/*from ww w .  j  a va2 s .c  o m*/
    List<String> currentArry = null;

    Logger logger = LoggerFactory.getLogger(getClass());
    do {
        //                logger.info( "Token: {}", token );
        switch (token) {
        case START_ARRAY: {
            //                        logger.info( "Starting array for field: {}", currentField );
            currentArry = new ArrayList<String>();
            break;
        }
        case END_ARRAY:
            //                        logger.info( "Ending array for field: {}", currentField );
            locations.put(currentField, jp.getCurrentLocation());
            ast.put(currentField, currentArry);
            currentArry = null;
            break;
        case FIELD_NAME:
            currentField = jp.getCurrentName();
            break;
        case VALUE_STRING:
            if (currentArry != null) {
                currentArry.add(jp.getText());
            } else {
                locations.put(currentField, jp.getCurrentLocation());
                ast.put(currentField, jp.getText());
            }
            break;
        case VALUE_NUMBER_INT:
            locations.put(currentField, jp.getCurrentLocation());
            ast.put(currentField, jp.getIntValue());
            break;
        case VALUE_NUMBER_FLOAT:
            locations.put(currentField, jp.getCurrentLocation());
            ast.put(currentField, jp.getFloatValue());
            break;
        case VALUE_TRUE:
            locations.put(currentField, jp.getCurrentLocation());
            ast.put(currentField, Boolean.TRUE);
            break;
        case VALUE_FALSE:
            locations.put(currentField, jp.getCurrentLocation());
            ast.put(currentField, Boolean.FALSE);
            break;
        }

        token = jp.nextToken();
    } while (token != JsonToken.END_OBJECT);

    StringBuilder sb = new StringBuilder();
    sb.append("AST is:");
    for (String field : ast.keySet()) {
        Object value = ast.get(field);
        sb.append("\n  ").append(field).append(" = ");
        if (value == null) {
            sb.append("null");
        } else {
            sb.append(value).append("  (type: ").append(value.getClass().getSimpleName()).append(")");
        }
    }

    logger.debug(sb.toString());

    final RelationshipType type = RelationshipType.getType((String) ast.get(RELATIONSHIP_TYPE));

    final String uri = (String) ast.get(POM_LOCATION_URI);
    URI pomLocation;
    if (uri == null) {
        pomLocation = RelationshipUtils.POM_ROOT_URI;
    } else {
        try {
            pomLocation = new URI(uri);
        } catch (final URISyntaxException e) {
            throw new JsonParseException("Invalid " + POM_LOCATION_URI + ": '" + uri + "': " + e.getMessage(),
                    locations.get(POM_LOCATION_URI), e);
        }
    }

    Collection<URI> sources = new HashSet<URI>();
    List<String> srcs = (List<String>) ast.get(SOURCE_URIS);
    if (srcs != null) {
        for (String u : srcs) {
            try {
                sources.add(new URI(u));
            } catch (URISyntaxException e) {
                throw new JsonParseException("Failed to parse source URI: " + u, locations.get(SOURCE_URIS));
            }
        }
    }

    String decl = (String) ast.get(DECLARING_REF);
    final ProjectVersionRef declaring = SimpleProjectVersionRef.parse(decl);

    String tgt = (String) ast.get(TARGET_REF);
    Integer index = (Integer) ast.get(INDEX);
    if (index == null) {
        index = 0;
    }

    // handle null implicitly by comparing to true.
    boolean managed = Boolean.TRUE.equals(ast.get(MANAGED));
    boolean inherited = Boolean.TRUE.equals(ast.get(INHERITED));
    boolean mixin = Boolean.TRUE.equals(ast.get(MIXIN));
    boolean optional = Boolean.TRUE.equals(ast.get(OPTIONAL));

    ProjectRelationship<?, ?> rel = null;
    switch (type) {
    case DEPENDENCY: {
        final ArtifactRef target = SimpleArtifactRef.parse(tgt);

        String scp = (String) ast.get(SCOPE);
        final DependencyScope scope;
        if (scp == null) {
            scope = DependencyScope.compile;
        } else {
            scope = DependencyScope.getScope(scp);
        }

        rel = new SimpleDependencyRelationship(sources, pomLocation, declaring, target, scope, index, managed,
                inherited, optional);
        break;
    }
    case EXTENSION: {
        final ProjectVersionRef target = SimpleProjectVersionRef.parse(tgt);

        rel = new SimpleExtensionRelationship(sources, pomLocation, declaring, target, index, inherited);
        break;
    }
    case PARENT: {
        final ProjectVersionRef target = SimpleProjectVersionRef.parse(tgt);

        rel = new SimpleParentRelationship(sources, declaring, target);
        break;
    }
    case PLUGIN: {
        final ProjectVersionRef target = SimpleProjectVersionRef.parse(tgt);

        Boolean report = (Boolean) ast.get(REPORTING);
        rel = new SimplePluginRelationship(sources, pomLocation, declaring, target, index, managed,
                Boolean.TRUE.equals(report), inherited);
        break;
    }
    case PLUGIN_DEP: {
        String plug = (String) ast.get(PLUGIN_REF);
        if (plug == null) {
            throw new JsonParseException(
                    "No plugin reference (field: " + PLUGIN_REF + ") found in plugin-dependency relationship!",
                    jp.getCurrentLocation());
        }

        final ProjectRef plugin = SimpleProjectRef.parse(plug);
        final ArtifactRef target = SimpleArtifactRef.parse(tgt);

        rel = new SimplePluginDependencyRelationship(sources, pomLocation, declaring, plugin, target, index,
                managed, inherited);
        break;
    }
    case BOM: {
        final ProjectVersionRef target = SimpleProjectVersionRef.parse(tgt);

        rel = new SimpleBomRelationship(sources, pomLocation, declaring, target, index, inherited, mixin);
        break;
    }
    }

    return (T) rel;
}

From source file:info.rmapproject.core.model.impl.openrdf.ORMapDiscoTest.java

/**
 * Test method for {@link info.rmapproject.core.model.impl.openrdf.ORMapDiSCO#getTypeStatement()}.
 * @throws RMapDefectiveArgumentException 
 * @throws RMapException //from   w w w .  j a va 2s .c  om
 */
@Test
public void testGetTypeStatement() throws RMapException, RMapDefectiveArgumentException {
    List<java.net.URI> resourceList = new ArrayList<java.net.URI>();
    try {
        resourceList.add(new java.net.URI("http://rmap-info.org"));
        resourceList.add(new java.net.URI("https://rmap-project.atlassian.net/wiki/display/RMAPPS/RMap+Wiki"));
        RMapIri author = ORAdapter.openRdfIri2RMapIri(creatorIRI);
        ORMapDiSCO disco = new ORMapDiSCO(author, resourceList);
        Statement stmt = disco.getTypeStatement();
        assertEquals(disco.getId().getStringValue(), stmt.getSubject().stringValue());
        assertEquals(RDF.TYPE, stmt.getPredicate());
        assertEquals(RMAP.DISCO, stmt.getObject());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:info.rmapproject.core.model.impl.openrdf.ORMapDiscoTest.java

/**
 * Test method for {@link info.rmapproject.core.model.impl.openrdf.ORMapDiSCO#getDiscoContext()}.
 * @throws RMapDefectiveArgumentException 
 * @throws RMapException /*from  w  ww. ja v a  2  s.c o m*/
 */
@Test
public void testGetDiscoContext() throws RMapException, RMapDefectiveArgumentException {
    List<java.net.URI> resourceList = new ArrayList<java.net.URI>();
    try {
        resourceList.add(new java.net.URI("http://rmap-info.org"));
        resourceList.add(new java.net.URI("https://rmap-project.atlassian.net/wiki/display/RMAPPS/RMap+Wiki"));
        RMapIri author = ORAdapter.openRdfIri2RMapIri(creatorIRI);
        ORMapDiSCO disco = new ORMapDiSCO(author, resourceList);
        IRI context = disco.getDiscoContext();
        Model model = new LinkedHashModel();
        for (Statement stm : model) {
            assertEquals(context, stm.getContext());
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:info.rmapproject.core.model.impl.openrdf.ORMapDiscoTest.java

/**
 * Test method for {@link info.rmapproject.core.model.impl.openrdf.ORMapDiSCO#setDescription(RMapValue)}.
 * @throws RMapDefectiveArgumentException 
 * @throws RMapException /* w w  w .  j av  a 2 s.c  om*/
 */
@Test
public void testSetDescription() throws RMapException, RMapDefectiveArgumentException {
    List<java.net.URI> resourceList = new ArrayList<java.net.URI>();
    try {
        resourceList.add(new java.net.URI("http://rmap-info.org"));
        resourceList.add(new java.net.URI("https://rmap-project.atlassian.net/wiki/display/RMAPPS/RMap+Wiki"));
        RMapIri author = ORAdapter.openRdfIri2RMapIri(creatorIRI);
        ORMapDiSCO disco = new ORMapDiSCO(author, resourceList);
        Literal desc = vf.createLiteral("this is a description");
        RMapValue rdesc = ORAdapter.openRdfValue2RMapValue(desc);
        disco.setDescription(rdesc);
        RMapValue gDesc = disco.getDescription();
        assertEquals(rdesc.getStringValue(), gDesc.getStringValue());
        Statement descSt = disco.getDescriptonStatement();
        assertEquals(desc, descSt.getObject());
    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:info.rmapproject.core.model.impl.openrdf.ORMapDiscoTest.java

/**
 * Test method for {@link info.rmapproject.core.model.impl.openrdf.ORMapDiSCO#setCreator(RMapIri)}.
 * @throws RMapDefectiveArgumentException 
 * @throws RMapException /*from ww w  . ja va2  s .c o  m*/
 */
@Test
public void testSetCreator() throws RMapException, RMapDefectiveArgumentException {
    List<java.net.URI> resourceList = new ArrayList<java.net.URI>();
    try {
        resourceList.add(new java.net.URI("http://rmap-info.org"));
        resourceList.add(new java.net.URI("https://rmap-project.atlassian.net/wiki/display/RMAPPS/RMap+Wiki"));
        RMapIri author = ORAdapter.openRdfIri2RMapIri(creatorIRI);
        ORMapDiSCO disco = new ORMapDiSCO(author, resourceList);
        assertEquals(author.toString(), disco.getCreator().getStringValue());
        try {
            RMapIri author2 = ORAdapter.openRdfIri2RMapIri(creatorIRI2);
            disco.setCreator(author2);
            assertEquals(author2.toString(), disco.getCreator().getStringValue());
        } catch (RMapException r) {
            fail(r.getMessage());
        }

    } catch (URISyntaxException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }

}