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.haulmont.cuba.core.app.filestorage.amazon.AmazonS3FileStorage.java

protected URL getAmazonUrl(FileDescriptor fileDescr) {
    // the region-specific endpoint to the target object expressed in path style
    try {//from  ww w . j  a  v  a  2 s.  c  o m
        return new URL(String.format("https://%s.s3.amazonaws.com/%s", amazonS3Config.getBucket(),
                resolveFileName(fileDescr)));
    } catch (MalformedURLException e) {
        throw new RuntimeException("Unable to parse service endpoint: " + e.getMessage());
    }
}

From source file:net.devietti.ArchConfMapServlet.java

/** Parse a URL (presumed to be pointing at an HTML page) into a Jsoup Document */
private Document getURL(String url) {
    Scanner s = null;//  www .ja v a2 s.co  m
    try {

        s = new Scanner(new URL(url).openStream(), "UTF-8");
        return Jsoup.parse(s.useDelimiter("\\A").next());

    } catch (MalformedURLException e) {
        error(e.getMessage());
    } catch (IOException e) {
        error(e.getMessage());
    } finally {
        if (s != null)
            s.close();
    }
    throw new IllegalStateException("error parsing URL " + url);
}

From source file:at.molindo.webtools.crawler.CrawlerTask.java

@Override
public void run() {
    if (Thread.currentThread() instanceof CrawlerThread == false) {
        throw new Error("not a cralwer thread");
    }/*from   ww  w  . j  a  va  2 s .co m*/

    final CrawlerResult sr = new CrawlerResult();
    sr.setUrl(_urlString);
    sr.getReferrers().add(_referrer);

    final HttpGet get = new HttpGet(_urlString);
    // get.setFollowRedirects(false);

    try {
        final long start = System.currentTimeMillis();

        final HttpResponse response = ((CrawlerThread) Thread.currentThread()).getClient().execute(get);

        sr.setStatus(response.getStatusLine().getStatusCode());
        sr.setTime((int) (System.currentTimeMillis() - start));

        final Header[] contentTypeHeader = response.getHeaders("Content-Type");
        sr.setContentType(contentTypeHeader == null || contentTypeHeader.length == 0 ? null
                : contentTypeHeader[0].getValue());

        final String encoding = response.getEntity().getContentEncoding() == null ? null
                : response.getEntity().getContentEncoding().getValue();

        final Object content = consumeContent(response.getEntity().getContent(), sr.getContentType(),
                response.getEntity().getContentLength(), encoding);

        if (sr.getStatus() / 100 == 3) {
            String redirectLocation;
            final Header[] locationHeader = response.getHeaders("location");
            if (locationHeader != null && locationHeader.length > 0) {
                redirectLocation = locationHeader[0].getValue();
                if (redirectLocation.startsWith("/")) {
                    redirectLocation = _crawler._host + redirectLocation.substring(1);
                }
                _crawler.queue(redirectLocation, new CrawlerReferrer(_urlString,
                        response.getStatusLine().getReasonPhrase() + ": " + _referrer));
            } else {
                System.err.println("redirect without location from " + _urlString);
            }
        } else if (sr.getStatus() == HttpStatus.SC_OK) {
            if (content instanceof String) {
                sr.setText((String) content);

                if (sr.getContentType().startsWith("text/html")) {
                    parseResult(sr.getText());
                }
            }
        }
    } catch (final MalformedURLException e) {
        sr.setErrorMessage(e.getMessage());
        // e.printStackTrace();
    } catch (final IOException e) {
        sr.setErrorMessage(e.getMessage());
        e.printStackTrace();
    } catch (final SAXException e) {
        sr.setErrorMessage(e.getMessage());
        // e.printStackTrace();
    } catch (final Throwable t) {
        t.printStackTrace();
    } finally {
        _crawler.report(sr);
        // response.releaseConnection();
    }

}

From source file:it.geosdi.era.server.service.implementation.ServerService.java

public StringNodeTemporalLayer refreshTemporalLayer(StringNodeTemporalLayer temporalLayer) {
    URL serverURL;//  w w  w . j  a  v a2s.  c  o  m

    try {
        serverURL = new URL(temporalLayer.getURLSERVERCAPABILITIES() + temporalLayer.getNameSpace());
        WebMapServer wms = new WebMapServer(serverURL);
        WMSCapabilities capabilities = wms.getCapabilities();
        DateFormat df = new SimpleDateFormat("dd-MM-yyyy-HH-mm");
        df.setLenient(false);

        List<StringNodeTemporalLayer> temporals = new ArrayList<StringNodeTemporalLayer>();

        for (int i = 1; i < capabilities.getLayerList().size(); i++) {
            Layer layer = capabilities.getLayerList().get(i);
            StringNodeTemporalLayer temp = new StringNodeTemporalLayer(temporalLayer.getNameSpace());
            temp.setNomeLayer(layer.getName());
            temp.setNameSpace(temporalLayer.getNameSpace());
            temp.setURLSERVER(temporalLayer.getURLSERVER());
            temp.setURLSERVERCAPABILITIES(temporalLayer.getURLSERVERCAPABILITIES());
            Date dataLayer = df.parse(layer.getTitle().substring(0, 16));
            temp.setDate(dataLayer);

            if (layer.getBoundingBoxes().values().size() != 0) {
                for (Object SRSID : layer.getBoundingBoxes().keySet()) {
                    temp.setBB(this.createBoundBox(layer.getBoundingBoxes().get(SRSID)), (String) SRSID);
                    temp.setSRSID((String) SRSID);
                }
            }
            temporals.add(temp);
        }

        Collections.sort(temporals);

        return temporals.get(0);

    } catch (MalformedURLException e) {
        logger.error(e.getMessage());
        throw new DAOException(e.getMessage());
    } catch (ServiceException e) {
        logger.error(e.getMessage());
        throw new DAOException(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
        throw new DAOException(e.getMessage());
    } catch (ParseException e) {
        logger.error(e.getMessage());
        throw new DAOException(e.getMessage());
    }
}

From source file:com.sun.portal.rssportlet.FeedHelper.java

/**
 * Get the ROME SyndFeed object for the specified feed. The object may come
 * from a cache; the data in the feed may not be read at the time
 * this method is called./* w  w w .ja v a 2 s  . c o  m*/
 *
 * The <code>RssPortletBean</code> object is used to identify the feed
 * of interest, and the timeout value to be used when managing this
 * feed's cached value.
 *
 * @param bean an <code>RssPortletBean</code> object that describes
 * the feed of interest, and the cache timeout value for the feed.
 * @return a ROME <code>SyndFeed</code> object encapsulating the
 * feed specified by the URL.
 */
public SyndFeed getFeed(SettingsBean bean, String selectedFeed) throws IOException, FeedException {
    SyndFeed feed = null;
    FeedElement feedElement = (FeedElement) feeds.get(selectedFeed);

    if (feedElement != null && !feedElement.isExpired()) {
        feed = feedElement.getFeed();
    } else {
        GetMethod httpget = null;
        try {
            SyndFeedInput input = new SyndFeedInput();

            HttpClient httpclient = new HttpClient();
            httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_TIMEOUT);
            // SO_TIMEOUT -- timeout for blocking reads
            httpclient.getHttpConnectionManager().getParams().setSoTimeout(SOCKET_TIMEOUT);

            httpget = new GetMethod(selectedFeed);

            //httpget.getParams().setParameter("http.socket.timeout", new Integer(20000));
            // Internally the parameter collections will be linked together
            // by performing the following operations: 
            // hostconfig.getParams().setDefaults(httpclient.getParams());
            // httpget.getParams().setDefaults(hostconfig.getParams());
            //httpclient.executeMethod(hostconfig, httpget);
            // Execute the method.

            int statusCode = httpclient.executeMethod(httpget);
            if (statusCode != HttpStatus.SC_OK) {
                log.info("Method failed: " + httpget.getStatusLine());
            }
            // Read the response body.
            InputSource src = new InputSource(httpget.getResponseBodyAsStream());
            // Deal with the response.
            // Use caution: ensure correct character encoding and is not binary data
            feed = input.build(src);
            //
            // only cache the feed if the cache timeout is not equal to 0
            // a cache timeout of 0 means "don't cache"
            //
            int timeout = bean.getCacheTimeout();
            if (timeout != 0) {
                putFeed(selectedFeed, feed, timeout);
            }
        } catch (MalformedURLException mfurlex) {
            log.info("MalformedURLException: " + mfurlex.getMessage());
            mfurlex.printStackTrace();
            throw new IOException("MalformedURLException: " + mfurlex.getMessage());
        } catch (HttpException httpex) {
            log.info("Fatal protocol violation: " + httpex.getMessage());
            httpex.printStackTrace();
            throw new IOException("Fatal protocol violation: " + httpex.getMessage());
        } catch (IllegalArgumentException iae) {
            log.info("IllegalArgumentException: " + iae.getMessage());
            iae.printStackTrace();
            throw new IOException("IllegalArgumentException: " + iae.getMessage());
        } catch (IOException ioe) {
            log.info("Fatal transport error: " + ioe.getMessage());
            ioe.printStackTrace();
            throw new IOException("Fatal transport error: " + ioe.getMessage());
        } catch (ParsingFeedException parsingfeedex) {
            log.info("ParsingFeedException: " + parsingfeedex.getMessage());
            parsingfeedex.printStackTrace();
            throw new FeedException("ParsingFeedException: " + parsingfeedex.getMessage());
        } catch (FeedException feedex) {
            log.info("FeedException: " + feedex.getMessage());
            feedex.printStackTrace();
            throw new FeedException("FeedException: " + feedex.getMessage());
        } catch (Exception ex) {
            log.info("Exception ERROR: " + ex.getMessage());
            ex.printStackTrace();
        } finally {
            // Release the connection.
            httpget.releaseConnection();
        }
    }
    return feed;
}

From source file:com.owly.srv.RemoteBasicStatItfImpl.java

public boolean getStatusRemoteServer(String ipSrv, int clientPort) {

    URL url = null;/*from   w ww.j ava 2s.  c om*/
    BufferedReader reader = null;
    StringBuilder stringBuilder;
    JSONObject objJSON = new JSONObject();
    JSONParser objParser = new JSONParser();
    String statusServer = "Enable";

    // Check status of remote server with healthCheck
    logger.debug("Check status of remote server with healthCheck");
    // Url to send to remote server
    // for example :
    // http://135.1.128.127:5000/healthCheck

    String urlToSend = "http://" + ipSrv + ":" + clientPort + "/healthCheck";
    logger.debug("URL for HTTP request :  " + urlToSend);

    HttpURLConnection connection;
    try {

        url = new URL(urlToSend);
        connection = (HttpURLConnection) url.openConnection();

        // just want to do an HTTP GET here
        connection.setRequestMethod("GET");

        // uncomment this if you want to write output to this url
        // connection.setDoOutput(true);

        // give it 2 second to respond
        connection.setReadTimeout(1 * 1000);
        connection.connect();

        // read the output from the server
        reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        stringBuilder = new StringBuilder();

        String line = null;
        while ((line = reader.readLine()) != null) {
            stringBuilder.append(line + "\n");
        }

        logger.debug("Response received : " + stringBuilder.toString());
        // map the response into a JSON object
        objJSON = (JSONObject) objParser.parse(stringBuilder.toString());
        // Check the response of the sever with the previous request
        String resServer = (String) objJSON.get("StatusServer");

        // If we dont receive the correct health checl we will save the
        // disable state in the database
        if (resServer.equals("OK")) {
            statusServer = "Enable";
        } else {
            statusServer = "Disable";
        }

        logger.debug("Status of the Server: " + statusServer);

    } catch (MalformedURLException e1) {
        logger.error("MalformedURLException : " + e1.getMessage());
        logger.error("Exception ::", e1);
        statusServer = "Disable";
        logger.debug("Status of the Server: " + statusServer);

    } catch (IOException e1) {
        logger.error("IOException : " + e1.toString());
        logger.error("Exception ::", e1);
        e1.printStackTrace();
        statusServer = "Disable";
        logger.debug("Status of the Server: " + statusServer);

    } catch (ParseException e1) {
        logger.error("ParseException : " + e1.toString());
        logger.error("Exception ::", e1);
        statusServer = "Disable";
        logger.debug("Status of the Server: " + statusServer);

    } finally {
        logger.debug("Save Status of Server in Database: " + statusServer);

    }

    if (statusServer.equals("Enable")) {
        return true;
    } else {
        return false;
    }

}

From source file:MultiTextureTest.java

public void init() {
    if (stoneImage == null) {
        // the path to the image for an applet
        try {//from   w ww  .j av  a  2 s.c o m
            stoneImage = new java.net.URL(getCodeBase().toString() + "/stone.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }

    if (skyImage == null) {
        // the path to the image for an applet
        try {
            skyImage = new java.net.URL(getCodeBase().toString() + "/bg.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }

    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);
    add("Center", c);

    BranchGroup scene = createSceneGraph();
    u = new SimpleUniverse(c);

    ViewingPlatform viewingPlatform = u.getViewingPlatform();
    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    viewingPlatform.setNominalViewingTransform();

    // add orbit behavior but disable translate
    OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL | OrbitBehavior.DISABLE_TRANSLATE);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    // create the gui
    choice = new Choice();
    choice.addItem("stone + light");
    choice.addItem("stone");
    choice.addItem("lightMap");
    choice.addItem("sky");
    choice.addItem("stone + sky");
    choice.addItemListener(this);
    add("North", choice);

}

From source file:com.nokia.helium.diamonds.DiamondsSessionSocket.java

/**
 * Internal method to send data to diamonds.
 * If ignore result is true, then the method will return null, else the message return by the query
 * will be returned./*  ww  w  .j  a va 2  s  .com*/
 * @param message
 * @param ignoreResult
 * @return
 * @throws DiamondsException is thrown in case of message retrieval error, connection error. 
 */
protected synchronized String sendInternal(Message message, boolean ignoreResult) throws DiamondsException {
    URL destURL = url;
    if (buildId != null) {
        try {
            destURL = new URL(url.getProtocol(), url.getHost(), url.getPort(), buildId);
        } catch (MalformedURLException e) {
            throw new DiamondsException("Error generating the url to send the message: " + e.getMessage(), e);
        }
    }
    PostMethod post = new PostMethod(destURL.toExternalForm());
    try {
        File tempFile = streamToTempFile(message.getInputStream());
        tempFile.deleteOnExit();
        messages.add(tempFile);
        post.setRequestEntity(new FileRequestEntity(tempFile, "text/xml"));
    } catch (MessageCreationException e) {
        throw new DiamondsException("Error retrieving the message: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new DiamondsException("Error serializing the message into a temporary file: " + e.getMessage(),
                e);
    }
    try {
        int result = httpClient.executeMethod(post);
        if (result != HttpStatus.SC_OK && result != HttpStatus.SC_ACCEPTED) {
            throw new DiamondsException("Error sending the message: " + post.getStatusLine() + "("
                    + post.getResponseBodyAsString() + ")");
        }
        if (!ignoreResult) {
            return post.getResponseBodyAsString();
        }
    } catch (HttpException e) {
        throw new DiamondsException("Error sending the message: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new DiamondsException("Error sending the message: " + e.getMessage(), e);
    } finally {
        post.releaseConnection();
    }
    return null;
}

From source file:fi.uta.infim.usaproxyreportgenerator.App.java

private static void setupDataProvider() {
    // A data provider class can be specified on the CLI.
    if (cli.hasOption("dataProvider")) {
        // Look for JAR files in the plugin dir
        File[] jars = PLUGINS_DIR.listFiles((FileFilter) new WildcardFileFilter("*.jar", IOCase.INSENSITIVE));
        URL[] jarUrls = new URL[jars.length];
        for (int i = 0; i < jars.length; ++i) {
            try {
                jarUrls[i] = jars[i].toURI().toURL();
            } catch (MalformedURLException e) {
                // Skip URL if not valid
                continue;
            }//  ww w. j a  v  a2 s  .  c om
        }

        ClassLoader loader = URLClassLoader.newInstance(jarUrls, ClassLoader.getSystemClassLoader());
        String className = cli.getOptionValue("dataProvider");

        // Try to load the named class using a class loader. Fall back to
        // default if this fails.
        try {
            @SuppressWarnings("unchecked")
            Class<? extends DataProvider> cliOptionClass = (Class<? extends DataProvider>) Class
                    .forName(className, true, loader);
            if (!DataProvider.class.isAssignableFrom(cliOptionClass)) {
                throw new ClassCastException(cliOptionClass.getCanonicalName());
            }
            dataProviderClass = cliOptionClass;
        } catch (ClassNotFoundException e) {
            System.out.flush();
            System.err.println("Specified data provider class not found: " + e.getMessage());
            System.err.println("Falling back to default provider.");
        } catch (ClassCastException e) {
            System.out.flush();
            System.err.println("Specified data provider class is invalid: " + e.getMessage());
            System.err.println("Falling back to default provider.");
        }
        System.err.flush();
    }
}

From source file:net.bunselmeyer.mongo.maven.plugin.MigrateMojo.java

private URL buildOutputDirectoryUrl() throws MojoExecutionException {
    try {/*from www  .j  av  a 2 s . c  o  m*/
        File outputDirectoryFile = new File(getProject().getBuild().getOutputDirectory() + "/");
        return outputDirectoryFile.toURI().toURL();
    } catch (MalformedURLException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}