Example usage for java.net MalformedURLException printStackTrace

List of usage examples for java.net MalformedURLException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:com.mindquarry.search.serializer.IndexPostSerializer.java

@Override
public void endDocument() throws SAXException {
    super.endDocument();

    Node node = this.res.getNode();
    Element root = (Element) ((Document) node).getFirstChild();
    String action = root.getAttribute("action"); //$NON-NLS-1$

    NodeList children = root.getChildNodes();

    if (true) { // should resolve the action and find out wether it is a
        // cycle through all children of the root element
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            // for every child element...
            if (child instanceof Element) {

                // block source which can be posted by creating a new
                // servlet request
                URL url = null;//from w w  w. j a v a2 s.com
                try {
                    url = new URL(action);
                } catch (MalformedURLException e1) {
                    e1.printStackTrace();
                }
                HttpClient client = new HttpClient();
                client.getState().setCredentials(
                        new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM),
                        new UsernamePasswordCredentials(login, password));

                PostMethod pMethod = new PostMethod(action);
                pMethod.setDoAuthentication(true);
                pMethod.addRequestHeader("accept", "text/xml"); //$NON-NLS-1$ //$NON-NLS-2$

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                TransformerFactory tf = TransformerFactory.newInstance();
                try {
                    tf.newTransformer().transform(new DOMSource(child), new StreamResult(baos));
                    pMethod.setRequestEntity(new ByteArrayRequestEntity(baos.toByteArray()));
                    client.executeMethod(pMethod);
                } catch (TransformerConfigurationException e) {
                    getLogger().error("Failed to configure transformer prior to posting", e);
                } catch (TransformerException e) {
                    getLogger().error("Failed to transform prior to posting", e);
                } catch (HttpException e) {
                    getLogger().error("Failed to post", e);
                } catch (IOException e) {
                    getLogger().error("Something went wrong", e);
                }
            }
        }
    }
}

From source file:ca.simplegames.micro.extensions.i18n.I18NExtension.java

public Extension register(String name, SiteContext site, Map<String, Object> locales) throws Exception {
    Assert.notNull(name, "The name of the extension must not be null!");
    this.name = StringUtils.defaultIfBlank(name, "i18N");

    if (locales != null) {
        Map interceptConfig = (Map<String, Object>) locales.get("intercept");

        if (interceptConfig != null) {
            intercept = StringUtils.defaultString((String) interceptConfig.get("parameter_name"), "lang");
            scopesSrc = StringUtils.defaultString((String) interceptConfig.get("scope"), "context");
            scopes = StringUtils.split(scopesSrc, ",");
        }/*from  w  w  w.jav  a  2s . co m*/

        defaultEncoding = StringUtils.defaultString((String) locales.get("default_encoding"), Globals.UTF8);
        fallbackToSystemLocale = locales.get("fallback_to_system_locale") != null
                ? (Boolean) locales.get("fallback_to_system_locale")
                : true;

        resourceCacheRefreshInterval = Integer
                .parseInt(StringUtils.defaultString((locales.get("resource_cache")).toString(), "10"));

        List<String> paths = (List<String>) locales.get("base_names");
        if (paths != null && !paths.isEmpty()) {
            List<String> absPaths = new ArrayList<String>();

            for (String path : paths) {
                File realPath = new File(path);
                if (!realPath.exists()) {
                    realPath = new File(site.getWebInfPath().getAbsolutePath(), path);
                }

                try {
                    absPaths.add(realPath.toURI().toURL().toString());
                    //absPaths.add(pathConfig.getValue());
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
            }
            resourceBasePaths = absPaths.toArray(new String[absPaths.size()]);
        } else {
            resourceBasePaths = new String[] { "config/locales/messages" };
        }

        //Configure the i18n
        messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setDefaultEncoding(defaultEncoding);
        messageSource.setFallbackToSystemLocale(fallbackToSystemLocale);
        messageSource.setCacheSeconds(resourceCacheRefreshInterval);
        messageSource.setBasenames(resourceBasePaths);

        Filter i18N = new I18NFilter(this);
        final FilterManager filterManager = site.getFilterManager();

        filterManager.addFilter(i18N);
        // now make sure the i18N filter is always first (if present)
        Collections.swap(filterManager.getBeforeFilters(), 0, filterManager.getBeforeFilters().size() - 1);

        infoDetails.add(String.format("  default encoding ........: %s", defaultEncoding));
        infoDetails.add(String.format("  fallback to system locale: %s", fallbackToSystemLocale));
        infoDetails.add(String.format("  cache refresh ...........: %s", resourceCacheRefreshInterval));
        infoDetails.add(String.format("  resource bundle .........: %s", Arrays.toString(resourceBasePaths)));
        infoDetails.add(String.format("  Listening for ...........: '%s'", intercept));
        infoDetails.add(String.format("       in scope(s) ........: %s", scopesSrc));
    }

    return this;
}

From source file:com.testmax.util.HttpUtil.java

public int postFormdata(String myurl, String param, String xml) {

    HttpURLConnection httpConn = null;
    URL url;// w  ww  . ja va 2  s  .c o m
    int rest = -1;
    try {
        url = new URL(myurl);

        httpConn = (HttpURLConnection) url.openConnection();
        httpConn.setRequestProperty("content-type", "text/xml; charset=utf-8");
        httpConn.setDoOutput(true);

        OutputStream os = httpConn.getOutputStream();
        BufferedWriter osw = new BufferedWriter(new OutputStreamWriter(os));

        osw.write(xml);
        osw.flush();
        osw.close();
        rest = httpConn.getResponseCode();

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return rest;

}

From source file:com.google.zxing.client.android.result.ClickVURIResultHandler.java

public void registerClickV(String uri) {

    String host = "http://lit-taiga-5566.herokuapp.com/";
    String query = null, path = null;
    String telId = getTelNumber() == null ? getMacAddress() : getTelNumber();

    try {/*from   ww w  .j av a 2 s. c  o m*/
        URL url = new URL(uri.replaceAll("clickv://", host));
        query = url.getQuery();
        path = url.getProtocol() + "://" + url.getHost() + "/" + url.getPath();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    Toast.makeText(getActivity(), "???  :: " + query, Toast.LENGTH_SHORT).show();

    try {

        new ServerConnenctionTask().execute(path, query, telId);

        Toast.makeText(getActivity(), "" + uri, Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getActivity(), "?." + uri, Toast.LENGTH_SHORT).show();
    }

}

From source file:au.edu.usq.fascinator.harvester.feed.FeedHarvester.java

public void init(File jsonFile) throws PluginException {
    try {// ww w . ja v  a2  s  . c o  m
        config = new JsonConfig(jsonFile);
    } catch (IOException ioe) {
        throw new HarvesterException(ioe);
    }
    // Load the list of requested URLs
    List<Object> urlList = config.getList("harvester/feed-harvester/urls");
    // Load the cache location
    cacheDirectory = config.get("harvester/feed-harvester/cache", "");
    FeedHarvester.setTemplate(config.get("harvester/feed-harvester/template", ""));
    feeds = new HashSet<FeedReader>();

    // Now iterate through the urls and create FeedReaders
    for (Object feed : urlList) {
        try {
            FeedReader reader = new FeedReader((String) feed, cacheDirectory);
            reader.addFeedReaderStateChangeListener(this);
            feeds.add(reader);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (java.lang.ClassCastException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:edu.ucsb.nceas.metacat.lsid.LSIDDataLookup.java

public String getDocType(LSID lsid) {
    // example//from   w  w w. j a  v a  2s .  c  o  m
    //http://metacat.nceas.ucsb.edu/knb/metacat?action=getrevisionanddoctype&docid=knb-lter-gce.109.6
    // returns rev;doctype

    String _docType = null;
    String ns = lsid.getNamespace();
    String id = lsid.getObject();
    String ver = lsid.getRevision();
    InputStream docStream = null;

    ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
    String theServer = rb.getString("metacatserver");
    logger.debug("the server is " + theServer);

    String url = theServer + "?action=getrevisionanddoctype&docid=";
    url = url + ns + "." + id + "." + ver;
    try {
        URL theDoc = new URL(url);
        docStream = theDoc.openStream();

        StringTokenizer _st = new StringTokenizer(LSIDAuthorityMetaData.getStringFromInputStream(docStream),
                ";");
        _st.nextToken();
        _docType = _st.nextToken();
        docStream.close();
    } catch (MalformedURLException mue) {
        logger.error("MalformedURLException in LSIDDataLookup: " + mue);
        mue.printStackTrace();
    } catch (IOException ioe) {
        logger.error("IOException in LSIDDataLookup: " + ioe);
        ioe.printStackTrace();
    }
    return _docType;
}

From source file:es.gva.cit.gazetteer.adl.protocols.ADLThesaurus.java

/**
 * It implements the getNarrower ADL thesaurus operation
 * //from  w  ww  .  jav  a  2 s . com
 */
private void getNarrower() {
    URL urlNarrower;
    try {
        urlNarrower = new URL("http", getUrl().getHost(), getUrl().getPort(),
                getUrl().getFile() + "/get-narrower");
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    }
    Collection nodes = new HTTPGetProtocol().doQuery(urlNarrower, getNarrowerParams(), 0);
    parseGetNarrowAnswer((XMLNode) nodes.toArray()[0]);
}

From source file:com.utest.webservice.client.rest.RestClient.java

@SuppressWarnings("deprecation")
public HttpClient getClient() {
    if (client == null) {
        client = new HttpClient();
        client.getHttpConnectionManager().getParams().setConnectionTimeout(5000000);
        client.setState(clientState);//from   www.  j ava 2 s .  c o m
        // Protocol myhttps = new Protocol("https", new
        // MySSLSocketFactory(), 443);
        Protocol myhttps = null;
        if (keyStoreFile != null) {
            try {
                myhttps = new Protocol("https", new AuthSSLProtocolSocketFactory(null, null,
                        new URL("file:" + keyStoreFile), kestorepassword), 443);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        } else {
            myhttps = new Protocol("https", new MySSLSocketFactory(), 443);
        }
        Protocol.registerProtocol("https", myhttps);
    }
    return client;
}

From source file:org.cloudml.connectors.CloudFoundryConnector.java

public CloudFoundryConnector(String APIEndPoint, String login, String passwd, String organization,
        String space) {//from   ww w  . j  av a 2  s  .c o m
    try {
        URL cloudControllerUrl = URI.create(APIEndPoint).toURL();
        journal.log(Level.INFO, ">> Connecting to CloudFoundry ...");
        connectedClient = new CloudFoundryClient(new CloudCredentials(login, passwd), cloudControllerUrl,
                organization, space);
        connectedClient.login();
        defaultDomainName = connectedClient.getDefaultDomain().getName();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edu.usf.cutr.pelias.PeliasRequest.java

protected PeliasRequest(String url) {
    try {//from   ww w  . j a  va 2  s.c  om
        mUrl = new URL(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}