Example usage for org.apache.commons.httpclient.params HttpMethodParams HTTP_ELEMENT_CHARSET

List of usage examples for org.apache.commons.httpclient.params HttpMethodParams HTTP_ELEMENT_CHARSET

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpMethodParams HTTP_ELEMENT_CHARSET.

Prototype

String HTTP_ELEMENT_CHARSET

To view the source code for org.apache.commons.httpclient.params HttpMethodParams HTTP_ELEMENT_CHARSET.

Click Source Link

Usage

From source file:com.kaltura.client.KalturaClientBase.java

protected HttpClient createHttpClient() {
    HttpClient client = new HttpClient();

    // added by Unicon to handle proxy hosts
    String proxyHost = System.getProperty("http.proxyHost");
    if (proxyHost != null) {
        int proxyPort = -1;
        String proxyPortStr = System.getProperty("http.proxyPort");
        if (proxyPortStr != null) {
            try {
                proxyPort = Integer.parseInt(proxyPortStr);
            } catch (NumberFormatException e) {
                if (logger.isEnabled())
                    logger.warn("Invalid number for system property http.proxyPort (" + proxyPortStr
                            + "), using default port instead");
            }//from  w  w  w.j ava  2 s.c o  m
        }
        ProxyHost proxy = new ProxyHost(proxyHost, proxyPort);
        client.getHostConfiguration().setProxyHost(proxy);
    }
    // added by Unicon to force encoding to UTF-8
    client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, UTF8_CHARSET);
    client.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, UTF8_CHARSET);
    client.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, UTF8_CHARSET);

    HttpConnectionManagerParams connParams = client.getHttpConnectionManager().getParams();
    if (this.kalturaConfiguration.getTimeout() != 0) {
        connParams.setSoTimeout(this.kalturaConfiguration.getTimeout());
        connParams.setConnectionTimeout(this.kalturaConfiguration.getTimeout());
    }
    client.getHttpConnectionManager().setParams(connParams);
    return client;
}

From source file:com.borhan.client.BorhanClientBase.java

protected HttpClient createHttpClient() {
    HttpClient client = new HttpClient();

    // added by Unicon to handle proxy hosts
    String proxyHost = System.getProperty("http.proxyHost");
    if (proxyHost != null) {
        int proxyPort = -1;
        String proxyPortStr = System.getProperty("http.proxyPort");
        if (proxyPortStr != null) {
            try {
                proxyPort = Integer.parseInt(proxyPortStr);
            } catch (NumberFormatException e) {
                if (logger.isEnabled())
                    logger.warn("Invalid number for system property http.proxyPort (" + proxyPortStr
                            + "), using default port instead");
            }/*from ww w  .jav  a 2  s .  c o m*/
        }
        ProxyHost proxy = new ProxyHost(proxyHost, proxyPort);
        client.getHostConfiguration().setProxyHost(proxy);
    }
    // added by Unicon to force encoding to UTF-8
    client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, UTF8_CHARSET);
    client.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, UTF8_CHARSET);
    client.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, UTF8_CHARSET);

    HttpConnectionManagerParams connParams = client.getHttpConnectionManager().getParams();
    if (this.borhanConfiguration.getTimeout() != 0) {
        connParams.setSoTimeout(this.borhanConfiguration.getTimeout());
        connParams.setConnectionTimeout(this.borhanConfiguration.getTimeout());
    }
    client.getHttpConnectionManager().setParams(connParams);
    return client;
}

From source file:org.ala.harvester.BlueTierHarvester.java

private byte[] getContent(String url) throws Exception {
    String contentStr = null;//from w  w w . j  av  a2 s  .c  om

    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();
    // Create a method instance.
    GetMethod method = new GetMethod(url);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, "UTF-8");

    try {
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            String errMsg = "HTTP GET to " + "`" + url + "`" + " returned non HTTP OK code.  "
                    + "Returned code " + statusCode + " and message " + method.getStatusLine() + "\n";
            method.releaseConnection();
            logger.error(errMsg);
            throw new Exception(errMsg);
        }

        InputStream responseStream = method.getResponseBodyAsStream();

        contentStr = inputStream2String(responseStream);

    } catch (Exception domCreationErr) {
        throw new Exception(domCreationErr);

    } finally {
        // Release the connection.
        method.releaseConnection();
    }

    return contentStr.getBytes();
}

From source file:org.ala.harvester.BlueTierHarvester.java

private String getIndexPageStr(String url) throws Exception {

    // Constructs the GET URL to search.

    // `woe_id` is Yahoo! Where On Earth ID.
    // Issue/*ww  w . j  av a  2s . c  o m*/
    // http://api.Morphbank.com/services/rest/?method=Morphbank.places.find&api_key=08f5318120189e9d12669465c0113351&query=australia
    // to find Australia.
    // `woe_id` here is country level code, as opposed to continent code.

    String urlToSearch = url;

    System.out.println("Search URL: " + urlToSearch);

    /*
     * // Default parameters if not supplied. if (this.MorphbankApiKeySupplied
     * == false) { urlToSearch += "&" + "api_key=" + this.MorphbankApiKey; } if
     * (this.currentPageNumSupplied == false) { urlToSearch += "&" + "page="
     * + this.currentPageNum; } if (this.recordsPerPageSupplied == false) {
     * urlToSearch += "&" + "per_page=" + this.recordsPerPage; }
     */
    //      System.out.println(urlToSearch);
    logger.debug("URL to search is: " + "`" + urlToSearch + "`" + "\n");

    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(urlToSearch);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, "UTF-8");

    try {
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            String errMsg = "HTTP GET to " + "`" + urlToSearch + "`"
                    + " returned non HTTP OK code.  Returned code " + statusCode + " and message "
                    + method.getStatusLine() + "\n";
            method.releaseConnection();
            throw new Exception(errMsg);
        }

        //         InputStream responseStream = method.getResponseBodyAsStream();
        //
        //         // Instantiates a DOM builder to create a DOM of the response.
        //         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        //         DocumentBuilder builder = factory.newDocumentBuilder();

        // return a parsed Document
        return method.getResponseBodyAsString();

    } catch (Exception httpErr) {
        String errMsg = "HTTP GET to `" + urlToSearch + "` returned HTTP error.";
        throw new Exception(errMsg, httpErr);
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}

From source file:org.ala.harvester.FlickrHarvester.java

/**
 * Retrieves a map of licences./*ww w .j  a  v  a  2s .  c o  m*/
 * 
 * @return
 */
private Map<String, Licence> getLicencesMap() throws Exception {

    final String flickrMethodUri = "flickr.photos.licenses.getInfo";
    String urlToSearch = this.flickrRestBaseUrl + "/" + "?method=" + flickrMethodUri + "&api_key="
            + this.flickrApiKey;

    logger.info(urlToSearch);
    logger.debug("URL to search is: " + "`" + urlToSearch + "`" + "\n");

    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(urlToSearch);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, "UTF-8");

    try {
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            String errMsg = "HTTP GET to " + "`" + urlToSearch + "`"
                    + " returned non HTTP OK code.  Returned code " + statusCode + " and message "
                    + method.getStatusLine() + "\n";
            method.releaseConnection();
            throw new Exception(errMsg);
        }

        //parse the response
        InputStream responseStream = method.getResponseBodyAsStream();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(responseStream);
        XPathFactory xfactory = XPathFactory.newInstance();
        XPath xpath = xfactory.newXPath();

        XPathExpression xe = xpath.compile("/rsp/licenses/license");
        NodeList nodeSet = (NodeList) xe.evaluate(doc, XPathConstants.NODESET);

        Map<String, Licence> licencesMap = new HashMap<String, Licence>();

        for (int i = 0; i < nodeSet.getLength(); i++) {
            NamedNodeMap map = nodeSet.item(i).getAttributes();
            String id = map.getNamedItem("id").getNodeValue();
            Licence licence = new Licence();
            licence.setName(map.getNamedItem("name").getNodeValue());
            licence.setUrl(map.getNamedItem("url").getNodeValue());
            licencesMap.put(id, licence);
        }
        return licencesMap;

    } catch (Exception httpErr) {
        String errMsg = "HTTP GET to `" + urlToSearch + "` returned HTTP error.";
        throw new Exception(errMsg, httpErr);
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}

From source file:org.ala.harvester.FlickrHarvester.java

/**
 * Process a single image, do the document mapping etc
 * /*from  ww  w . j av a2s .c  o m*/
 * @param infosourceId
 * @param imageIndex
 * @param currentResDom
 * @throws Exception
 */
private boolean processSingleImage(int infosourceId, int imageIndex, Document currentResDom) throws Exception {

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    String xPathToPhotoId = "/rsp/photos/photo[" + imageIndex + "]/@id";
    String photoId = (String) xpath.evaluate(xPathToPhotoId, currentResDom, XPathConstants.STRING);
    logger.info("Handling photo ID: " + photoId);

    final String flickrMethod = "flickr.photos.getInfo";

    // Calls the Flickr's Photo Info API to determine whether the photo
    // comes from Australia or not.
    String photoInfoFlickrUrl = this.flickrRestBaseUrl + "/" + "?method=" + flickrMethod + "&" + "api_key="
            + this.flickrApiKey + "&" + "photo_id=" + photoId;

    System.out.println("PHOTO URL:" + photoInfoFlickrUrl);

    org.w3c.dom.Document photoInfoDom = null;

    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();
    // Create a method instance.
    GetMethod method = new GetMethod(photoInfoFlickrUrl);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, "UTF-8");

    logger.debug(
            "Fetching info. for photo with ID " + photoId + " from " + "`" + photoInfoFlickrUrl + "`" + "\n");

    try {
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            String errMsg = "HTTP GET to " + "`" + photoInfoFlickrUrl + "`" + " returned non HTTP OK code.  "
                    + "Returned code " + statusCode + " and message " + method.getStatusLine() + "\n";
            method.releaseConnection();
            logger.error(errMsg);
            throw new Exception(errMsg);
        }

        InputStream responseStream = method.getResponseBodyAsStream();

        // Instantiates a DOM builder to create a DOM of the response.
        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder domBuilder = domFactory.newDocumentBuilder();

        photoInfoDom = domBuilder.parse(responseStream);

    } catch (Exception domCreationErr) {
        throw new Exception("Failed to create DOM representation of GET response.", domCreationErr);

    } finally {
        // Release the connection.
        method.releaseConnection();
    }

    // Check for Flickr's error.
    if (!isDocExtractionSuccessful(photoInfoDom)) {
        throw new Exception("Flickr error response for fetching single image information.");
    }

    if (System.getProperty("overwrite") != null && "false".equals(System.getProperty("overwrite"))) {
        String photoPageUrl = (String) xpath.evaluate("/rsp/photo/urls/url[@type=\"photopage\"]/text()",
                photoInfoDom, XPathConstants.STRING);

        logger.debug("photo page URL: " + photoPageUrl);
        org.ala.model.Document doc = this.repository.getDocumentByGuid(photoPageUrl);
        if (doc != null) {
            logger.debug("Document with URI already harvested. Skipping: " + photoPageUrl);
            return true;
        }
    }

    // Determines whether photo has geo-coded tag from Australia.
    // If so, pass onto DocumentMapper.
    if (isPhotoFromAustralia(photoInfoDom)) {

        try {
            String document = (DOMUtils.domToString(photoInfoDom));
            // FIXME flickr GUID ???
            List<ParsedDocument> parsedDocs = documentMapper.map("", document.getBytes());
            for (ParsedDocument parsedDoc : parsedDocs) {
                this.repository.storeDocument(infosourceId, parsedDoc);
                debugParsedDoc(parsedDoc);
            }
            return false;
        } catch (Exception docMapperErr) {
            // Skipping over errors here and proceeding to next document.
            logger.error("Problem processing image. " + docMapperErr.toString() + ", Problem processing: "
                    + photoInfoFlickrUrl, docMapperErr);
        }
    } else {
        logger.debug("Photo is unAustralian: " + photoInfoFlickrUrl);
    }

    return false;
}

From source file:org.ala.harvester.FlickrHarvester.java

private org.w3c.dom.Document getIndexPage(int pageNumber, Date startDate, Date endDate) throws Exception {

    final String flickrMethodUri = "flickr.photos.search";

    // Constructs the GET URL to search.

    // `woe_id` is Yahoo! Where On Earth ID.
    // Issue//  ww  w  .j a v  a2s  .co  m
    // http://api.flickr.com/services/rest/?method=flickr.places.find&api_key=08f5318120189e9d12669465c0113351&query=australia
    // to find Australia.
    // `woe_id` here is country level code, as opposed to continent code.

    SimpleDateFormat mysqlDateTime = new SimpleDateFormat("yyyy-MM-dd");

    String minUpdateDate = mysqlDateTime.format(startDate);
    String maxUpdateDate = mysqlDateTime.format(endDate);

    String urlToSearch = this.flickrRestBaseUrl + "/" + "?method=" + flickrMethodUri + "&content_type=1"
    //      + "&sort=date-posted-asc"
    //      + "&machine_tag_mode=any" 
    //      + "&group_id=" + this.eolGroupId
            + "&user_id=" + this.eolGroupId
            //      + "&accuracy=3" 
            + "&privacy_filter=1"
            //      + "&machine_tags=%22geo:country=Australia%22"
            //      + "&machine_tags=%22taxonomy:binomial=Pogona%20barbata%22"
            //      + "&tags=geo:country=Australia&country=Australia"
            //      + "&has_geo=1" 
            //      + "&accuracy=3" 
            //      + "&woe_id=23424748"
            // MYSQL date time
            + "&min_upload_date=" + minUpdateDate //startDate
            + "&max_upload_date=" + maxUpdateDate //endDate
            + "&api_key=" + this.flickrApiKey + "&page=" + pageNumber + "&per_page=" + this.recordsPerPage;

    //      String urlToSearch = 
    //      "http://api.flickr.com/services/rest/?method=flickr.photos.search" +
    //      "&api_key=08f5318120189e9d12669465c0113351" +
    //      "&page=1" +
    //      "&per_page=50" +
    //      "&machine_tag_mode=any" +
    //      "&content_type=1" +
    //      "&group_id=806927@N20&privacy_filter=1" +
    //      "&machine_tags=%22taxonomy:binomial=Pogona%20barbata%22";

    logger.info("Search URL: " + urlToSearch);

    /*
     * // Default parameters if not supplied. if (this.flickrApiKeySupplied
     * == false) { urlToSearch += "&" + "api_key=" + this.flickrApiKey; } if
     * (this.currentPageNumSupplied == false) { urlToSearch += "&" + "page="
     * + this.currentPageNum; } if (this.recordsPerPageSupplied == false) {
     * urlToSearch += "&" + "per_page=" + this.recordsPerPage; }
     */
    //      logger.info(urlToSearch);
    logger.debug("URL to search is: " + "`" + urlToSearch + "`" + "\n");

    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(urlToSearch);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, "UTF-8");

    try {
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            String errMsg = "HTTP GET to " + "`" + urlToSearch + "`"
                    + " returned non HTTP OK code.  Returned code " + statusCode + " and message "
                    + method.getStatusLine() + "\n";
            method.releaseConnection();
            throw new Exception(errMsg);
        }

        InputStream responseStream = method.getResponseBodyAsStream();

        // Instantiates a DOM builder to create a DOM of the response.
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();

        // return a parsed Document
        return builder.parse(responseStream);

    } catch (Exception httpErr) {
        String errMsg = "HTTP GET to `" + urlToSearch + "` returned HTTP error.";
        throw new Exception(errMsg, httpErr);
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}

From source file:org.ala.harvester.MaHarvester.java

private String getIndexPageStr() throws Exception {

    // Constructs the GET URL to search.

    // `woe_id` is Yahoo! Where On Earth ID.
    // Issue/*from   w  w  w  .j a  va  2  s  . c om*/
    // http://api.Morphbank.com/services/rest/?method=Morphbank.places.find&api_key=08f5318120189e9d12669465c0113351&query=australia
    // to find Australia.
    // `woe_id` here is country level code, as opposed to continent code.

    String urlToSearch = this.endpoint;

    System.out.println("Search URL: " + urlToSearch);

    /*
     * // Default parameters if not supplied. if (this.MorphbankApiKeySupplied
     * == false) { urlToSearch += "&" + "api_key=" + this.MorphbankApiKey; } if
     * (this.currentPageNumSupplied == false) { urlToSearch += "&" + "page="
     * + this.currentPageNum; } if (this.recordsPerPageSupplied == false) {
     * urlToSearch += "&" + "per_page=" + this.recordsPerPage; }
     */
    //      System.out.println(urlToSearch);
    logger.debug("URL to search is: " + "`" + urlToSearch + "`" + "\n");

    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(urlToSearch);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, "UTF-8");

    try {
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            String errMsg = "HTTP GET to " + "`" + urlToSearch + "`"
                    + " returned non HTTP OK code.  Returned code " + statusCode + " and message "
                    + method.getStatusLine() + "\n";
            method.releaseConnection();
            throw new Exception(errMsg);
        }

        //         InputStream responseStream = method.getResponseBodyAsStream();
        //
        //         // Instantiates a DOM builder to create a DOM of the response.
        //         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        //         DocumentBuilder builder = factory.newDocumentBuilder();

        // return a parsed Document
        return method.getResponseBodyAsString();

    } catch (Exception httpErr) {
        String errMsg = "HTTP GET to `" + urlToSearch + "` returned HTTP error.";
        throw new Exception(errMsg, httpErr);
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}

From source file:org.ala.harvester.MorphbankHarvester.java

private org.w3c.dom.Document getIndexPage() throws Exception {

    final String MorphbankMethodUri = "Morphbank.photos.search";

    // Constructs the GET URL to search.

    // `woe_id` is Yahoo! Where On Earth ID.
    // Issue/*from   w w  w. j  ava2 s.  c  o m*/
    // http://api.Morphbank.com/services/rest/?method=Morphbank.places.find&api_key=08f5318120189e9d12669465c0113351&query=australia
    // to find Australia.
    // `woe_id` here is country level code, as opposed to continent code.

    String urlToSearch = this.endpoint;

    System.out.println("Search URL: " + urlToSearch);

    /*
     * // Default parameters if not supplied. if (this.MorphbankApiKeySupplied
     * == false) { urlToSearch += "&" + "api_key=" + this.MorphbankApiKey; } if
     * (this.currentPageNumSupplied == false) { urlToSearch += "&" + "page="
     * + this.currentPageNum; } if (this.recordsPerPageSupplied == false) {
     * urlToSearch += "&" + "per_page=" + this.recordsPerPage; }
     */
    //      System.out.println(urlToSearch);
    logger.debug("URL to search is: " + "`" + urlToSearch + "`" + "\n");

    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(urlToSearch);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_ELEMENT_CHARSET, "UTF-8");
    method.getParams().setParameter(HttpMethodParams.HTTP_URI_CHARSET, "UTF-8");

    try {
        int statusCode = client.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            String errMsg = "HTTP GET to " + "`" + urlToSearch + "`"
                    + " returned non HTTP OK code.  Returned code " + statusCode + " and message "
                    + method.getStatusLine() + "\n";
            method.releaseConnection();
            throw new Exception(errMsg);
        }

        String inputStr = method.getResponseBodyAsString();
        //            inputStr = inputStr.replaceAll("[^\\x00-\\x7f]*", "");
        inputStr = inputStr.replaceAll("/dwcg:VerbatimLongitude>", "</dwcg:VerbatimLongitude>");
        inputStr = inputStr.replaceAll("/dwcg:VerbatimLatitude>", "</dwcg:VerbatimLatitude>");
        inputStr = inputStr.replaceAll("<</", "</");

        //            Pattern p = Pattern.compile("[^<]{1}/[a-zA-Z]{1,}:[a-zA-Z]{1,}>");
        //            
        //            Matcher m = p.matcher(inputStr);
        //            
        //            int searchIdx = 0;
        //            
        //            while (m.find(searchIdx)) {
        //                int endIdx = m.end();
        //                
        //                
        //                
        //                searchIdx = endIdx;
        //            }

        //            System.out.println(inputStr);
        InputSource is = new InputSource(new StringReader(new String(inputStr)));
        // Instantiates a DOM builder to create a DOM of the response.
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();

        // return a parsed Document
        return builder.parse(is);

    } catch (Exception httpErr) {
        String errMsg = "HTTP GET to `" + urlToSearch + "` returned HTTP error.";
        throw new Exception(errMsg, httpErr);
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
}