Example usage for java.net MalformedURLException toString

List of usage examples for java.net MalformedURLException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.bruce.study.demo.studydata.demos60.httpclient.MyHttpClientActivity.java

/**
 * ???/*from ww w. ja v  a  2  s  .  com*/
 */
private void getNetInfo() {
    DataInputStream dataInputStream = null;
    try {
        URL url = new URL(ADDRESS); // ??
        URLConnection urlConnection = url.openConnection(); // http
        // ??
        dataInputStream = new DataInputStream(urlConnection.getInputStream());
        // ??
        //                    DataOutputStream dataOutputStream = new DataOutputStream(urlConnection.getOutputStream())
        // ???
        int temp = 0;
        byteArrayBuffer = new ByteArrayBuffer(1000);
        while ((temp = dataInputStream.read()) != -1) {
            byteArrayBuffer.append(temp);
        }
        // ??
        MyHttpClientActivity.this.sendUIMessageEmpty(0x02);
    } catch (MalformedURLException e) {
        logE(e.toString());
    } catch (IOException e) {
        logE(e.toString());
    } finally {
        try {
            if (dataInputStream != null) {
                dataInputStream.close();
            }
        } catch (IOException e) {
            logE(e.toString());
        }
    }
}

From source file:org.powertac.server.ServerPropertiesTest.java

@Test
public void testSetUserConfigFirst() {
    try {/*ww w.  ja  v  a  2 s .com*/
        serverPropertiesService.setUserConfig(new URL("file:src/test/propfiles/server.properties"));
    } catch (MalformedURLException e) {
        fail(e.toString());
    } catch (ConfigurationException e) {
        fail(e.toString());
    } catch (IOException e) {
        fail(e.toString());
    }
    assertEquals("foo", serverPropertiesService.getProperty("server.prop1"));
    assertEquals("bag", serverPropertiesService.getProperty("test.prop2"));
    // when you set user config first, it's top priority
    assertEquals("baz", serverPropertiesService.getProperty("test.prop1"));
}

From source file:org.powertac.server.ServerPropertiesTest.java

/**
 * Test method for {@link org.powertac.server.ServerPropertiesService#setUserConfig(java.lang.String)}.
 *///from ww w .jav a 2  s . c  om
@Test
public void testSetUserConfigLast() {
    assertEquals("foo", serverPropertiesService.getProperty("server.prop1"));
    assertNull(serverPropertiesService.getProperty("test.prop2"));
    try {
        serverPropertiesService.setUserConfig(new URL("file:src/test/propfiles/server.properties"));
    } catch (MalformedURLException e) {
        fail(e.toString());
    } catch (ConfigurationException e) {
        fail(e.toString());
    } catch (IOException e) {
        fail(e.toString());
    }
    assertEquals("foo", serverPropertiesService.getProperty("server.prop1"));
    assertEquals("bag", serverPropertiesService.getProperty("test.prop2"));
    // when you set the user config after initialization, it's last priority
    assertEquals("bar", serverPropertiesService.getProperty("test.prop1"));
}

From source file:org.apache.nutch.protocol.ProtocolFactory.java

/**
 * Returns the appropriate {@link Protocol} implementation for a url.
 * /*  w  w w  .j  a v a  2 s. c  o  m*/
 * @param urlString
 *          Url String
 * @return The appropriate {@link Protocol} implementation for a given {@link URL}.
 * @throws ProtocolNotFound
 *           when Protocol can not be found for urlString
 */
public Protocol getProtocol(String urlString) throws ProtocolNotFound {
    ObjectCache objectCache = ObjectCache.get(conf);
    try {
        URL url = new URL(urlString);
        String protocolName = url.getProtocol();
        String cacheId = Protocol.X_POINT_ID + protocolName;
        if (protocolName == null)
            throw new ProtocolNotFound(urlString);

        if (objectCache.getObject(cacheId) != null) {
            return (Protocol) objectCache.getObject(cacheId);
        } else {
            Extension extension = findExtension(protocolName);
            if (extension == null) {
                throw new ProtocolNotFound(protocolName);
            }

            Protocol protocol = (Protocol) extension.getExtensionInstance();

            objectCache.setObject(cacheId, protocol);

            return protocol;
        }

    } catch (MalformedURLException e) {
        throw new ProtocolNotFound(urlString, e.toString());
    } catch (PluginRuntimeException e) {
        throw new ProtocolNotFound(urlString, e.toString());
    }
}

From source file:com.easy.facebook.android.apicall.FQL.java

public String fqlQuery(String fqlQuery) throws EasyFacebookError {

    Bundle params = new Bundle();
    params.putString("method", "fql.query");
    params.putString("access_token", facebook.getAccessToken());

    params.putString("query", fqlQuery);

    try {/* www . j  a v  a2 s  .  c om*/
        return Util.openUrl("https://api.facebook.com/restserver.php", "POST", params);

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    }
}

From source file:com.easy.facebook.android.apicall.FQL.java

public Friend getFriend(String uid) throws EasyFacebookError {
    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("method", "fql.query");
    params.putString("access_token", facebook.getAccessToken());

    String fqlQuery = (new StringBuilder(
            "SELECT uid, name, pic, profile_update_time, timezone, birthday_date, status, online_presence, locale, profile_url, website, is_blocked FROM user WHERE uid="))
                    .append(uid).toString();
    params.putString("query", fqlQuery);

    String jsonResponse;/*  w  ww .j  a  v a  2 s .  co  m*/
    try {
        jsonResponse = Util.openUrl("https://api.facebook.com/restserver.php", "POST", params);

        JSONObjectDecode jsonArray = new JSONObjectDecode(jsonResponse);
        return jsonArray.getFriend(0);

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }

}

From source file:org.apache.nutch.indexer.solr.SolrMappingReader.java

private void parseMapping() {
    InputStream ssInputStream = null;
    ssInputStream = conf.getConfResourceAsInputStream(conf.get(SS_FILE_MAPPING, "solrindex-mapping.xml"));
    InputSource inputSource = new InputSource(ssInputStream);
    try {/*from  w w  w.  j a va  2  s  . co  m*/
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse(inputSource);
        Element rootElement = document.getDocumentElement();
        NodeList fieldList = rootElement.getElementsByTagName("field");
        if (fieldList.getLength() > 0) {
            for (int i = 0; i < fieldList.getLength(); i++) {
                Element element = (Element) fieldList.item(i);
                LOG.info(
                        "source: " + element.getAttribute("source") + " dest: " + element.getAttribute("dest"));
                keyMap.put(element.getAttribute("source"), element.getAttribute("dest"));
            }
        }
        NodeList copyFieldList = rootElement.getElementsByTagName("copyField");
        if (copyFieldList.getLength() > 0) {
            for (int i = 0; i < copyFieldList.getLength(); i++) {
                Element element = (Element) copyFieldList.item(i);
                LOG.info(
                        "source: " + element.getAttribute("source") + " dest: " + element.getAttribute("dest"));
                copyMap.put(element.getAttribute("source"), element.getAttribute("dest"));
            }
        }
        NodeList uniqueKeyItem = rootElement.getElementsByTagName("uniqueKey");
        if (uniqueKeyItem.getLength() > 1) {
            LOG.warn("More than one unique key definitions found in solr index mapping, using default 'id'");
            uniqueKey = "id";
        } else if (uniqueKeyItem.getLength() == 0) {
            LOG.warn("No unique key definition found in solr index mapping using, default 'id'");
        } else {
            uniqueKey = uniqueKeyItem.item(0).getFirstChild().getNodeValue();
        }
    } catch (MalformedURLException e) {
        LOG.warn(e.toString());
    } catch (SAXException e) {
        LOG.warn(e.toString());
    } catch (IOException e) {
        LOG.warn(e.toString());
    } catch (ParserConfigurationException e) {
        LOG.warn(e.toString());
    }
}

From source file:org.apache.nutchbase.protocol.ProtocolFactoryHbase.java

/**
 * Returns the appropriate {@link Protocol} implementation for a url.
 * //from   w ww.  j  a v a 2  s.  c o  m
 * @param urlString
 *          Url String
 * @return The appropriate {@link Protocol} implementation for a given {@link URL}.
 * @throws ProtocolNotFound
 *           when Protocol can not be found for urlString
 */
public ProtocolHbase getProtocol(String urlString) throws ProtocolNotFound {
    ObjectCache objectCache = ObjectCache.get(conf);
    try {
        URL url = new URL(urlString);
        String protocolName = url.getProtocol();
        String cacheId = ProtocolHbase.X_POINT_ID + protocolName;
        if (protocolName == null)
            throw new ProtocolNotFound(urlString);

        if (objectCache.getObject(cacheId) != null) {
            return (ProtocolHbase) objectCache.getObject(cacheId);
        } else {
            Extension extension = findExtension(protocolName);
            if (extension == null) {
                throw new ProtocolNotFound(protocolName);
            }

            ProtocolHbase protocol = (ProtocolHbase) extension.getExtensionInstance();

            objectCache.setObject(cacheId, protocol);

            return protocol;
        }

    } catch (MalformedURLException e) {
        throw new ProtocolNotFound(urlString, e.toString());
    } catch (PluginRuntimeException e) {
        throw new ProtocolNotFound(urlString, e.toString());
    }
}

From source file:com.easy.facebook.android.apicall.FQL.java

public List<Friend> getFriends(String uids[]) throws EasyFacebookError {

    String whereClause = "";
    List<Friend> friendList = new ArrayList<Friend>();

    for (int i = 0; i < uids.length - 1; i++)
        whereClause = (new StringBuilder(String.valueOf(whereClause))).append("uid = ").append(uids[i])
                .append(" OR ").toString();

    whereClause = (new StringBuilder(String.valueOf(whereClause))).append("uid = ")
            .append(uids[uids.length - 1]).toString();

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());
    params.putString("method", "fql.query");
    String fqlQuery = (new StringBuilder(
            "SELECT uid, name, pic, profile_update_time, timezone, birthday_date, status, online_presence, locale, profile_url, website, is_blocked FROM user WHERE "))
                    .append(whereClause).toString();
    params.putString("query", fqlQuery);

    String jsonResponse;/*  w w w  . j a v a  2s  .c  o m*/
    try {
        jsonResponse = Util.openUrl("https://api.facebook.com/restserver.php", "POST", params);

        JSONObjectDecode jsonArray = new JSONObjectDecode(jsonResponse);
        for (int i = 0; i < jsonArray.length(); i++)
            friendList.add(jsonArray.getFriend(i));

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }

    return friendList;

}

From source file:no.ntnu.osnap.social.models.Notification.java

/**
 * UNTESTED: Gets the link associated with this notification.
 * //from   w w w. ja  va  2  s  .co m
 * @return the value of the field 'link' or {@code null}
 * if the no value is associated with such field.
 * (Or maybe it will fail?)
 */
public URL getLink() {
    URL link = null;
    try {
        link = new URL(getStringField("link"));
    } catch (MalformedURLException ex) {
        Log.d(TAG, ex.toString());
    }
    return link;
}