Example usage for java.net MalformedURLException getMessage

List of usage examples for java.net MalformedURLException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.carvoyant.modularinput.Program.java

private JSONObject getRefreshToken(EventWriter ew, String clientId, String clientSecret, String refreshToken) {
    JSONObject tokenJson = null;/*from   w w  w .  ja  v  a2  s.co m*/
    HttpsURLConnection getTokenConnection = null;

    try {
        BufferedReader tokenResponseReader = null;
        URL url = new URL("https://api.carvoyant.com/oauth/token");
        //         URL url = new URL("https://sandbox-api.carvoyant.com/sandbox/oauth/token");
        getTokenConnection = (HttpsURLConnection) url.openConnection();
        getTokenConnection.setReadTimeout(30000);
        getTokenConnection.setConnectTimeout(30000);
        getTokenConnection.setRequestMethod("POST");
        getTokenConnection.setDoInput(true);
        getTokenConnection.setDoOutput(true);

        List<SimpleEntry> getTokenParams = new ArrayList<SimpleEntry>();
        getTokenParams.add(new SimpleEntry("client_id", clientId));
        getTokenParams.add(new SimpleEntry("client_secret", clientSecret));
        getTokenParams.add(new SimpleEntry("grant_type", "refresh_token"));
        getTokenParams.add(new SimpleEntry("refresh_token", refreshToken));

        String userpass = clientId + ":" + clientSecret;
        String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());

        getTokenConnection.setRequestProperty("Authorization", basicAuth);

        OutputStream os = getTokenConnection.getOutputStream();
        os.write(getQuery(getTokenParams).getBytes("UTF-8"));
        os.close();

        if (getTokenConnection.getResponseCode() < 400) {
            tokenResponseReader = new BufferedReader(
                    new InputStreamReader(getTokenConnection.getInputStream()));
            String inputLine;
            StringBuffer sb = new StringBuffer();
            while ((inputLine = tokenResponseReader.readLine()) != null) {
                sb.append(inputLine);
            }

            tokenJson = new JSONObject(sb.toString());
            ew.synchronizedLog(EventWriter.INFO, "Refreshed Carvoyant access token.");
        } else {
            tokenResponseReader = new BufferedReader(
                    new InputStreamReader(getTokenConnection.getErrorStream()));
            StringBuffer sb = new StringBuffer();
            String inputLine;
            while ((inputLine = tokenResponseReader.readLine()) != null) {
                sb.append(inputLine);
            }
            ew.synchronizedLog(EventWriter.ERROR, "Carvoyant Refresh Token Error. CLIENT_ID:" + clientId
                    + ", REFRESH_TOKEN:" + refreshToken + ",ERROR_MSG: " + sb.toString());
        }

        getTokenConnection.disconnect();
    } catch (MalformedURLException mue) {
        ew.synchronizedLog(EventWriter.ERROR, "Carvoyant Refresh Token Error: " + mue.getMessage());
    } catch (IOException ioe) {
        ew.synchronizedLog(EventWriter.ERROR, "Carvoyant Refresh Token Error: " + ioe.getMessage());
    } finally {
        if (null != getTokenConnection) {
            getTokenConnection.disconnect();
        }
    }

    return tokenJson;
}

From source file:it.imtech.configuration.StartWizard.java

/**
 * Retrieve online configuration filepath
 *
 * @throws MalformedURLException//ww w.j  av  a2 s.  c o  m
 * @throws ConfigurationException
 */
private XMLConfiguration setConfigurationPaths(XMLConfiguration internalConf, ResourceBundle bundle) {
    XMLConfiguration configuration = null;

    try {
        String text = Utility.getBundleString("setconf", bundle);
        String title = Utility.getBundleString("setconf2", bundle);

        internalConf.setAutoSave(true);

        String n = internalConf.getString("configurl[@path]");

        if (n.isEmpty()) {
            String s = (String) JOptionPane.showInputDialog(new Frame(), text, title, JOptionPane.PLAIN_MESSAGE,
                    null, null, "http://phaidrastatic.cab.unipd.it/xml/config.xml");

            //If a string was returned, say so.
            if ((s != null) && (s.length() > 0)) {
                internalConf.setProperty("configurl[@path]", s);
                Globals.URL_CONFIG = new URL(s);
            } else {
                logger.info("File di configurazione non settato");
            }
        } else {
            if (Globals.ONLINE) {
                Globals.URL_CONFIG = new URL(n);
            }
        }

        if (Globals.URL_CONFIG != null) {
            if (Globals.DEBUG)
                configuration = new XMLConfiguration(new File(Globals.JRPATH + Globals.DEBUG_XML));
            else
                configuration = new XMLConfiguration(Globals.URL_CONFIG);
        } else {
            if (!Globals.ONLINE) {
                configuration = new XMLConfiguration(
                        new File(Globals.USER_DIR + Utility.getSep() + Globals.FOLD_XML + "config.xml"));
            }
        }
    } catch (final MalformedURLException ex) {
        logger.error(ex.getMessage());
        JOptionPane.showMessageDialog(new Frame(), Utility.getBundleString("exc_conf_1", bundle));
    } catch (final ConfigurationException ex) {
        logger.error(ex.getMessage());
        JOptionPane.showMessageDialog(new Frame(), Utility.getBundleString("exc_conf_2", bundle));
    }

    return configuration;
}

From source file:org.apache.cxf.fediz.service.idp.beans.STSClientAction.java

private void processWsdlLocation(RequestContext context) {
    if (!isPortSet) {
        try {/*from  w w  w  . j a  va2 s . c  om*/
            URL url = new URL(this.wsdlLocation);
            URL updatedUrl = new URL(url.getProtocol(), url.getHost(),
                    WebUtils.getHttpServletRequest(context).getLocalPort(), url.getFile());

            setSTSWsdlUrl(updatedUrl.toString());
            LOG.info("STS WSDL URL updated to {}", updatedUrl.toString());
        } catch (MalformedURLException e) {
            LOG.error("Invalid Url '{}': {}", this.wsdlLocation, e.getMessage());
        }
    }
}

From source file:org.commonjava.couch.change.CouchChangeListener.java

@Override
public void run() {
    final CouchDocChangeDeserializer docDeserializer = new CouchDocChangeDeserializer();

    all: while (!Thread.interrupted()) {
        HttpGet get;// w  w  w .j a  va  2 s.  com
        try {
            final String url = buildUrl(config.getDatabaseUrl(), metadata.getUrlParameters(), CHANGES_SERVICE);

            get = new HttpGet(url);
        } catch (final MalformedURLException e) {
            logger.error("Failed to construct changes URL for db: %s. Reason: %s", e, config.getDatabaseUrl(),
                    e.getMessage());
            break;
        }

        String encoding = null;
        try {
            // logger.info( "requesting changes..." );

            final HttpResponse response = http.executeHttpWithResponse(get, "Failed to open changes stream.");

            if (response.getEntity() == null) {
                logger.error("Changes stream did not return a response body.");
            } else {
                final Header encodingHeader = response.getEntity().getContentEncoding();
                if (encodingHeader == null) {
                    encoding = "UTF-8";
                } else {
                    encoding = encodingHeader.getValue();
                }

                final InputStream stream = response.getEntity().getContent();

                running = true;
                synchronized (internalLock) {
                    internalLock.notifyAll();
                }

                final CouchDocChangeList changes = serializer.fromJson(stream, encoding,
                        CouchDocChangeList.class, docDeserializer);

                for (final CouchDocChange change : changes) {
                    logger.info("Processing change: %s", change.getId());

                    if (!change.getId().equals(CHANGE_LISTENER_DOCID)) {
                        metadata.setLastProcessedSequenceId(change.getSequence());
                        dispatcher.documentChanged(change);
                    }
                }
            }
        } catch (final CouchDBException e) {
            logger.error("Failed to read changes stream for db: %s. Reason: %s", e, config.getDatabaseUrl(),
                    e.getMessage());
            break;
        } catch (final UnsupportedEncodingException e) {
            logger.error("Invalid content encoding for changes response: %s. Reason: %s", e, encoding,
                    e.getMessage());
            break;
        } catch (final IOException e) {
            logger.error("Error reading changes response content. Reason: %s", e, e.getMessage());
            break;
        } finally {
            http.cleanup(get);
        }

        try {
            Thread.sleep(2000);
        } catch (final InterruptedException e) {
            break all;
        }
    }

    synchronized (internalLock) {
        internalLock.notifyAll();
    }
}

From source file:FullThreadDump.java

/**
 * Connect to a JMX agent of a given URL.
 *//*w w w  .java  2s .c  o m*/
private void connect(String urlPath) {
    try {
        JMXServiceURL url = new JMXServiceURL("rmi", "", 0, urlPath);
        this.jmxc = JMXConnectorFactory.connect(url);
        this.server = jmxc.getMBeanServerConnection();
    } catch (MalformedURLException e) {
        // should not reach here
    } catch (IOException e) {
        System.err.println("\nCommunication error: " + e.getMessage());
        System.exit(1);
    }
}

From source file:org.gbif.pubindex.service.impl.JournalServiceImpl.java

@Override
public SyndFeed readFeed(Journal j) {
    SyndFeed feed = null;/*from  w  ww.ja  va 2 s. co m*/
    if (j == null)
        return null;

    LOG.debug("Reading latest rss feed for journal {}", j.getId());
    if (StringUtils.isBlank(j.getFeedUrl())) {
        LOG.warn("Journal {} has no rss feed configured", j.getId());
        return null;
    }
    InputStream stream = null;
    try {
        // use http client to handle redirects and network failures gracefully
        HttpGet get = new HttpGet(j.getFeedUrl());
        // http header
        get.addHeader("User-Agent", "GBIF-PubIndex/1.0");

        HttpResponse response = client.execute(get);
        LOG.debug("Feed http status: {} {}", response.getStatusLine().getStatusCode(),
                response.getStatusLine().getReasonPhrase());
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            stream = entity.getContent();
            SyndFeedInput input = new SyndFeedInput();
            feed = input.build(new XmlReader(stream, entity.getContentType().getValue()));
            j.setError(null);
            LOG.info("Current feed for journal " + j.getId() + " published on {} contains {} articles",
                    feed.getPublishedDate(), feed.getEntries().size());
            // update journal, find new properties we dont yet have
            updateJournalFromFeed(j, feed);
        } else {
            LOG.warn("Journal {} feed {} has no content", j.getId(), j.getFeedUrl());
            j.setError("Journal feed has no content");
        }
    } catch (MalformedURLException e) {
        LOG.warn("Journal {} has invalid feed URL {}", j.getId(), j.getFeedUrl());
        j.setError(ErrorUtils.getErrorMessage(e));
    } catch (FeedException e) {
        LOG.warn("Feed for journal {} cannot be parsed {}", j.getId(), e.getMessage());
        j.setError(ErrorUtils.getErrorMessage(e));
    } catch (IOException e) {
        LOG.warn("Cant read feed for journal {} : {}", j.getId(), e.getMessage());
        j.setError(ErrorUtils.getErrorMessage(e));
    } catch (Exception e) {
        LOG.warn("Unkown exception while reading feed for journal {} : {}", j.getId(), e.getMessage());
        j.setError(ErrorUtils.getErrorMessage(e));
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            }
        }
    }

    // mark as harvested
    j.setLastHarvest(new Date());
    // update postgres
    mapper.update(j);

    return feed;
}

From source file:eclserver.threads.EmergencyNotifyPush.java

private int userCallPush(String pushId, URL testURL) {
    int respCode = 0;
    try {//from w  w w .jav  a2s.  c  o  m

        pushPayload = getJsonString(machineName, confirmURL);

        conn = (HttpURLConnection) testURL.openConnection();
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("X-RIM-PUSH-ID", pushId);
        conn.setRequestProperty("X-RIM-Push-Reliability-Mode", "TRANSPORT");

        out = conn.getOutputStream();
        out.write(pushPayload.getBytes());

        respCode = conn.getResponseCode();

        if (respCode != HttpURLConnection.HTTP_OK) {
            String serverMessage = conn.getResponseMessage();
            enPanel.printToResults("HTTP-" + respCode + ": " + serverMessage);
        }

        System.out.println("Response Code " + conn.getResponseCode());

    } catch (MalformedURLException ex) {
        System.out.println("Malformed URL Exception in EmergencyNotifyPush: " + ex.getMessage());
        //    enPanel.printToResults("\nMalformed URL Exception in EmergencyNotifyPush" + ex.getMessage());

    } catch (UnknownHostException ex) {
        System.out.println("UnknownHostException Exception in EmergencyNotifyPush: " + ex.getMessage());
        //     enPanel.printToResults("\nUnknownHostException: " + ex.getMessage() );

    } catch (ConnectException ex) {
        // Unable to connect to the MDS
        System.out.println("ConnectException Exception in EmergencyNotifyPush: " + ex.getMessage());
        //    enPanel.printToResults("\nConnectException: " + ex.getMessage() );

    } catch (Exception ex) {
        System.out.println("Exception in EmergencyNotifyPush: " + ex.getMessage());
    } finally {
        if (ins != null) {
            try {
                ins.close();
            } catch (Exception ex) {
                System.out.println("Error in EmergencyNotifyPush finally: " + ex.getMessage());

            }
            ins = null;
        }

        if (conn != null) {
            conn.disconnect();
            conn = null;
        }
    }

    return respCode;
}

From source file:com.fluidops.iwb.deepzoom.ImageLoader.java

/**
 * Loads an image from a URL to a local file
 * @param url - The URL from which to obtain the image
 * @param file - The file to store the image to
 * @return/*from w  ww  .  ja v  a 2  s  . c om*/
 */

public boolean loadImage(String url, File file) {
    URL u;
    InputStream is = null;
    BufferedInputStream dis = null;
    int b;
    try {
        try {
            u = new URL(url);
        } catch (MalformedURLException e) {
            // this is the case if we work with relative URLs (in eCM)
            // just prepend the base URL#
            u = new URL(serverURL + url);
        }

        try {
            is = u.openStream();
        } catch (IOException e) {
            System.out.println("File could not be found: " + url);

            // quick fix: 200px-Image n/a, try smaller pic (for Wikipedia images)
            url = url.replace("200px", "94px");
            u = new URL(url);
            try {
                is = u.openStream();
            } catch (IOException e2) {
                System.out.println("also smaller image not available");
                return false;
            }
        }
        dis = new BufferedInputStream(is);
        BufferedOutputStream out = null;
        try {
            out = new BufferedOutputStream(new FileOutputStream(file));
            while ((b = dis.read()) != -1) {
                out.write(b);
            }
            out.flush();
        } finally {
            IOUtils.closeQuietly(out);
        }
    } catch (MalformedURLException mue) {
        logger.error(mue.getMessage(), mue);
        return false;

    } catch (IOException ioe) {
        logger.error(ioe.getMessage(), ioe);
        return false;
    } finally {
        IOUtils.closeQuietly(dis);
    }
    return true;
}

From source file:eclserver.threads.EmergencyCallPush.java

private int userCallPush(String pushId, URL testURL) {
    int respCode = 0;
    try {/*  w  ww.j  a v a2 s  . c o m*/

        pushPayload = getJsonString(machineName, confirmURL);

        conn = (HttpURLConnection) testURL.openConnection();
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("X-RIM-PUSH-ID", pushId);
        conn.setRequestProperty("X-RIM-Push-Reliability-Mode", "TRANSPORT");

        out = conn.getOutputStream();
        out.write(pushPayload.getBytes());

        respCode = conn.getResponseCode();

        if (respCode != HttpURLConnection.HTTP_OK) {
            String serverMessage = conn.getResponseMessage();
            ecPanel.printToResults("HTTP-" + respCode + ": " + serverMessage);
        }

        System.out.println("Response Code " + conn.getResponseCode());

    } catch (MalformedURLException ex) {
        System.out.println("Malformed URL Exception in EmergencyCallPush: " + ex.getMessage());
        //   ecPanel.printToResults("\nMalformed URL Exception in EmergencyCallPush" + ex.getMessage());

    } catch (UnknownHostException ex) {
        System.out.println("UnknownHostException Exception in EmergencyCallPush: " + ex.getMessage());
        //   ecPanel.printToResults("\nUnknownHostException: " + ex.getMessage() );

    } catch (ConnectException ex) {
        // Unable to connect to the MDS
        System.out.println("ConnectException Exception in EmergencyCallPush: " + ex.getMessage());
        //   ecPanel.printToResults("\nConnectException: " + ex.getMessage() );

    } catch (Exception ex) {
        System.out.println("Exception in EmergencyCallPush: " + ex.getMessage());
    } finally {
        if (ins != null) {
            try {
                ins.close();
            } catch (Exception ex) {
                System.out.println("Error in push finally: " + ex.getMessage());

            }
            ins = null;
        }

        if (conn != null) {
            conn.disconnect();
            conn = null;
        }
    }

    return respCode;
}