Example usage for java.net URISyntaxException printStackTrace

List of usage examples for java.net URISyntaxException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:it.cnr.icar.eric.server.security.authorization.RegistryAttributeFinderModule.java

/** Get the object from the specified resource id.
 *
 * @param context/*from   ww w  .  j a v  a 2  s . c  om*/
 * @param subjectAttributeId
 * @param subjectCategory
 * @return
 */
private Object getResourceObject(EvaluationCtx context, String resourceAttributeId) {

    Object obj = null;
    try {
        EvaluationResult result = context.getResourceAttribute(new URI(ObjectAttribute.identifier),
                new URI(resourceAttributeId), null);
        AttributeValue attrValue = result.getAttributeValue();
        BagAttribute bagAttr = (BagAttribute) attrValue;
        if (bagAttr.size() == 1) {
            Iterator<?> iter = bagAttr.iterator();
            ObjectAttribute objAttr = (ObjectAttribute) iter.next();
            if (objAttr != null) {
                obj = objAttr.getValue();
            }
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    return obj;
}

From source file:org.ttrssreader.net.deprecated.ApacheJSONConnector.java

protected InputStream doRequest(Map<String, String> params) {
    HttpPost post = new HttpPost();

    try {// ww  w.j a va  2 s  .com
        if (sessionId != null)
            params.put(SID, sessionId);

        // Set Address
        post.setURI(Controller.getInstance().uri());
        post.addHeader("Accept-Encoding", "gzip");

        // Add POST data
        JSONObject json = new JSONObject(params);
        StringEntity jsonData = new StringEntity(json.toString(), "UTF-8");
        jsonData.setContentType("application/json");
        post.setEntity(jsonData);

        // Add timeouts for the connection
        {
            HttpParams httpParams = post.getParams();

            // Set the timeout until a connection is established.
            int timeoutConnection = (int) (8 * Utils.SECOND);
            HttpConnectionParams.setConnectionTimeout(httpParams, timeoutConnection);

            // Set the default socket timeout (SO_TIMEOUT) which is the timeout for waiting for data.
            // use longer timeout when lazyServer-Feature is used
            int timeoutSocket = (int) ((Controller.getInstance().lazyServer()) ? 15 * Utils.MINUTE
                    : 10 * Utils.SECOND);
            HttpConnectionParams.setSoTimeout(httpParams, timeoutSocket);

            post.setParams(httpParams);
        }

        logRequest(json);

        if (client == null)
            client = HttpClientFactory.getInstance().getHttpClient(post.getParams());
        else
            client.setParams(post.getParams());

        // Add SSL-Stuff
        if (credProvider != null)
            client.setCredentialsProvider(credProvider);

    } catch (URISyntaxException e) {
        hasLastError = true;
        lastError = "Invalid URI.";
        return null;
    } catch (Exception e) {
        hasLastError = true;
        lastError = "Error creating HTTP-Connection in (old) doRequest(): " + formatException(e);
        e.printStackTrace();
        return null;
    }

    HttpResponse response;
    try {
        response = client.execute(post); // Execute the request
    } catch (ClientProtocolException e) {
        hasLastError = true;
        lastError = "ClientProtocolException in (old) doRequest(): " + formatException(e);
        return null;
    } catch (SSLPeerUnverifiedException e) {
        // Probably related: http://stackoverflow.com/questions/6035171/no-peer-cert-not-sure-which-route-to-take
        // Not doing anything here since this error should happen only when no certificate is received from the
        // server.
        Log.w(TAG, "SSLPeerUnverifiedException in (old) doRequest(): " + formatException(e));
        return null;
    } catch (SSLException e) {
        if ("No peer certificate".equals(e.getMessage())) {
            // Handle this by ignoring it, this occurrs very often when the connection is instable.
            Log.w(TAG, "SSLException in (old) doRequest(): " + formatException(e));
        } else {
            hasLastError = true;
            lastError = "SSLException in (old) doRequest(): " + formatException(e);
        }
        return null;
    } catch (InterruptedIOException e) {
        Log.w(TAG, "InterruptedIOException in (old) doRequest(): " + formatException(e));
        return null;
    } catch (SocketException e) {
        // http://stackoverflow.com/questions/693997/how-to-set-httpresponse-timeout-for-android-in-java/1565243#1565243
        Log.w(TAG, "SocketException in (old) doRequest(): " + formatException(e));
        return null;
    } catch (Exception e) {
        hasLastError = true;
        lastError = "Exception in (old) doRequest(): " + formatException(e);
        return null;
    }

    // Try to check for HTTP Status codes
    int code = response.getStatusLine().getStatusCode();
    if (code >= 400 && code < 600) {
        hasLastError = true;
        lastError = "Server returned status: " + code;
        return null;
    }

    InputStream instream = null;
    try {
        HttpEntity entity = response.getEntity();
        if (entity != null)
            instream = entity.getContent();

        // Try to decode gzipped instream, if it is not gzip we stay to normal reading
        Header contentEncoding = response.getFirstHeader("Content-Encoding");
        if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip"))
            instream = new GZIPInputStream(instream);

        // Header size = response.getFirstHeader("Api-Content-Length");
        // Log.d(TAG, "SIZE: " + size.getValue());

        if (instream == null) {
            hasLastError = true;
            lastError = "Couldn't get InputStream in (old) Method doRequest(String url) [instream was null]";
            return null;
        }
    } catch (Exception e) {
        if (instream != null)
            try {
                instream.close();
            } catch (IOException e1) {
                // Empty!
            }
        hasLastError = true;
        lastError = "Exception in (old) doRequest(): " + formatException(e);
        return null;
    }

    return instream;
}

From source file:eu.asterics.mw.services.TestResourceRegistry.java

@Test
public void testGetResource() {
    try {//from  www.j  a v  a 2s . co  m
        URI areBaseURI = ResourceRegistry.getInstance().getAREBaseURI();
        URI dataBaseURI = ResourceRegistry.resolveRelativeFilePath(areBaseURI, ResourceRegistry.DATA_FOLDER)
                .toURI();
        URI modelBaseURI = ResourceRegistry.resolveRelativeFilePath(areBaseURI, ResourceRegistry.MODELS_FOLDER)
                .toURI();

        //Test absolute file URI:
        //The given URI conform string should be taken without modification and returned as URI instance.
        String testURIString = ResourceRegistry.getInstance().getAREBaseURI().toString();
        URI actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.ANY);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(areBaseURI, actual));

        //Test http:// URL
        testURIString = "http://www.asterics-academy.net/test";
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.ANY);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(new URI(testURIString), actual));

        //Test relative resource, will be treated as a file
        //Should be found pictures subfolder directly through step1
        testURIString = "pictures/slide7.jpg";
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.DATA);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(
                ResourceRegistry.resolveRelativeFilePath(dataBaseURI, testURIString, true).toURI(), actual));

        //Should be found in pictures subfolder, through step2
        testURIString = "slide7.jpg";
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.DATA, "pictures", null);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(ResourceRegistry
                .resolveRelativeFilePath(dataBaseURI, "pictures/" + testURIString, true).toURI(), actual));

        //Should be found in pictures subfolder, through step3
        testURIString = "slide7.jpg";
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.DATA, "Pic", null);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(ResourceRegistry
                .resolveRelativeFilePath(dataBaseURI, "pictures/" + testURIString, true).toURI(), actual));

        //Should be found in pictures subfolder, through step4
        testURIString = "slide7.jpg";
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.DATA);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(ResourceRegistry
                .resolveRelativeFilePath(dataBaseURI, "pictures/" + testURIString, true).toURI(), actual));

        //Test spaces and \\ in string (also interesting to test it on Linux)
        testURIString = "symbols\\fill glass with water.png";
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.DATA);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(ResourceRegistry
                .resolveRelativeFilePath(dataBaseURI, "pictures\\" + testURIString, true).toURI(), actual));

        //Test providing componentTypeId of facetrackerLK
        testURIString = "haarcascade_frontalface_alt.xml";
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.DATA,
                "asterics.FacetrackerLK", null);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(ResourceRegistry
                .resolveRelativeFilePath(dataBaseURI, "sensor.facetrackerLK/" + testURIString, true).toURI(),
                actual));

        //Test models
        testURIString = "CameraMouse.acs";
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.MODEL, null, null);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(
                ResourceRegistry.resolveRelativeFilePath(modelBaseURI, testURIString, true).toURI(), actual));

        testURIString = "grids\\eyeX_Environment\\eyeX_Environment.acs";
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.MODEL, null, null);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(
                ResourceRegistry.resolveRelativeFilePath(modelBaseURI, testURIString, true).toURI(), actual));

        //Test absolute file path, should be returned as valid absolute URI
        if (OSUtils.isWindows()) {
            testURIString = "C:\\Program Files (x86)\\eclipse";
        } else {
            testURIString = "/var/log/messages";
        }
        actual = ResourceRegistry.getInstance().getResource(testURIString, RES_TYPE.ANY, null, null);
        assertTrue(ResourceRegistry.equalsNormalizedURIs(new File(testURIString).toURI(), actual));

        //System.out.println("testGetResource: "+arebaseURI);
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:it.cnr.icar.eric.server.security.authorization.RegistryAttributeFinderModule.java

private Object getReferenceSourceObject(EvaluationCtx context) {

    Object obj = null;/*from  w w w.  jav a  2 s.c  om*/
    try {
        EvaluationResult result = context.getActionAttribute(new URI(AnyURIAttribute.identifier),
                new URI(AuthorizationServiceImpl.ACTION_ATTRIBUTE_REFERENCE_SOURCE), null);
        AttributeValue attrValue = result.getAttributeValue();
        BagAttribute bagAttr = (BagAttribute) attrValue;
        if (bagAttr.size() == 1) {
            Iterator<?> iter = bagAttr.iterator();
            AnyURIAttribute attr = (AnyURIAttribute) iter.next();
            if (attr != null) {
                String refSourceId = attr.getValue().toString();

                ServerRequestContext requestContext = AuthorizationServiceImpl.getRequestContext(context);
                obj = AuthorizationServiceImpl.getInstance().getRegistryObject(requestContext, refSourceId,
                        false);
            }
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (RegistryException e) {
        e.printStackTrace();
    }

    return obj;
}

From source file:org.kalypso.core.catalog.DynamicCatalog.java

/**
 * @return true results of resolve/* ww  w  .  j  a v  a  2s  .  com*/
 */
private List<String> internResolveDelegate(final String hrefCatalog, final String systemID,
        final String publicID, List<String> collector, final boolean doCollectURN, final boolean supportPattern,
        final boolean resolveContext) {
    final String uriToCatalog = resolveLocal(hrefCatalog, hrefCatalog, true, true);
    final URI catalogURI;
    try {
        final URL url = new URL(uriToCatalog);
        catalogURI = url.toURI();
        final ICatalog catalog = m_manager.getCatalog(catalogURI);
        if (catalog instanceof DynamicCatalog) {
            final DynamicCatalog dynCatalog = (DynamicCatalog) catalog;
            collector = dynCatalog.internResolve(systemID, publicID, collector, doCollectURN, supportPattern,
                    false, resolveContext);
        } else if (catalog == null) {
            java.lang.System.out.println("oups"); //$NON-NLS-1$
        } else {
            if (doCollectURN) {
                final String uriFromSystemID = catalog.resolve(systemID, null);
                if (systemID != null && !systemID.equals(uriFromSystemID))
                    collector.add(systemID);
                final String uriFromPublicID = catalog.resolve(null, publicID);
                if (publicID != null && !publicID.equals(uriFromPublicID))
                    collector.add(publicID);
            } else {
                final String uri = catalog.resolve(systemID, publicID);
                collector.add(uri);
            }
        }

    } catch (final URISyntaxException e) {
        // invalid catalog entry
        e.printStackTrace();
    } catch (final MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return collector;
}

From source file:it.cnr.icar.eric.server.security.authorization.RegistryAttributeFinderModule.java

/**
 * Handles subject attributes as defined ebRIM.
 *///www . j  a va2  s.  c om
private EvaluationResult handleRegistrySubjectAttribute(URI attributeId, URI type, URI subjectCategory,
        EvaluationCtx context) {
    EvaluationResult res = null;

    String attributeIdStr = attributeId.toString();
    Object user = getSubjectObject(context, AuthorizationServiceImpl.SUBJECT_ATTRIBUTE_USER, subjectCategory);

    try {
        ServerRequestContext requestContext = AuthorizationServiceImpl.getRequestContext(context);

        // First check if attribute is role or group which are special cases since
        // they are not actual attributes in ebRIM.
        if (attributeIdStr.equals(AuthorizationServiceImpl.SUBJECT_ATTRIBUTE_ROLES)) {
            Set<AttributeValue> nodePaths = getClassificationNodePaths(requestContext, user,
                    BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_ID_SubjectRole);
            res = makeBag(nodePaths, new URI(StringAttribute.identifier));
        } else if (attributeIdStr.equals(AuthorizationServiceImpl.SUBJECT_ATTRIBUTE_GROUPS)) {
            Set<AttributeValue> nodePaths = getClassificationNodePaths(requestContext, user,
                    BindingUtility.CANONICAL_CLASSIFICATION_SCHEME_ID_SubjectGroup);
            res = makeBag(nodePaths, new URI(StringAttribute.identifier));
        } else {
            // Not a role or group attribute
            // See if it is a RegistryObject attribute defined by ebRIM.
            res = handleRegistryObjectAttribute(user, getAttributeStackFromAttributeId(attributeId), type,
                    context);
        }
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (RegistryException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return res;
}

From source file:cn.devit.app.ip_messenger.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    System.out.println("activity result:" + requestCode + ":" + resultCode);
    if (resultCode == RESULT_OK) {
        System.out.println("request code:" + requestCode);
        switch (requestCode) {
        case PICKFILE_RESULT_CODE:

        default:// w w  w.  ja v  a  2s  .  c om
            File file;
            try {
                file = new File(new URI(data.getDataString()));
                attaches.add(file);
                System.out.println("attach url:" + data.getDataString());
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            break;
        }
    } else {
        System.out.println("result code is not ok.");
    }
}

From source file:org.jenkinsci.plugins.relution_publisher.configuration.global.Store.java

/**
 * Gets the host component of the store's {@link #getUrl() URL}.
 *//*  w w  w  . j a v a2  s  . co m*/
public String getHostName() {

    try {
        final URI uri = new URI(this.mUrl);
        return uri.getHost();

    } catch (final URISyntaxException e) {
        e.printStackTrace();
    }
    return this.mUrl;
}

From source file:abfab3d.io.input.ModelLoader.java

public void setSource(String uri) {
    if (uri == null)
        throw new IllegalArgumentException("Source cannot be null");

    String path = null;//  w ww  .j  a va  2  s .c  o  m
    m_vhash = null;

    if (uriMapper != null) {
        uri = uriMapper.mapURI(uri);
    }

    printf("Model Loader: %s\n", uri);
    // TODO: How to deal with not wanting to cache user uploaded files(put in temp dir) versus local usage
    if (uri.startsWith("http")) {

        URIToFileCacheEntry entry = uriToFileCache.get(uri);

        if (entry != null) {
            m_path = entry.filename;
            if (DEBUG)
                printf("Found cached file for: %s its: %s\n", uri, uri);
            File f = new File(m_path);
            if (f.exists()) {
                mp_source.setValue(m_path);
                return;
            }
            if (DEBUG)
                printf("File gone for url: %s\n", uri);
        }

        if (DEBUG)
            printf("Downloading url: %s\n", uri);
        try {
            path = URIUtils.downloadURI("ModelLoader", uri);
            uriToFileCache.put(uri, new URIToFileCacheEntry(uri, path));
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (URISyntaxException use) {
            use.printStackTrace();
        }
    } else {
        path = uri;
    }

    if (path == null)
        throw new IllegalArgumentException("Cannot resolve source: " + uri);

    if (FilenameUtils.getExtension(path).equalsIgnoreCase("zip")) {
        URIToFileCacheEntry entry = uriToFileCache.get(path);

        if (entry != null) {
            m_path = entry.filename;
            if (DEBUG)
                printf("Found cached file for: %s its: %s\n", uri, uri);
            File f = new File(m_path);
            if (f.exists()) {
                mp_source.setValue(m_path);
                return;
            }
            if (DEBUG)
                printf("File gone for url: %s\n", uri);
        }

        File src = new File(path);
        File dest = Files.createTempDir();
        dest.deleteOnExit();

        try {
            unzip(src, dest);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            throw new IllegalArgumentException("Cannot unzip: " + path + " to: " + dest);
        }
        path = dest.getAbsolutePath();
        uriToFileCache.put(uri, new URIToFileCacheEntry(uri, path));
        if (DEBUG)
            printf("Caching uri: %s to: %s\n", uri, path);
    }
    mp_source.setValue(path);
    m_path = path;
}