Example usage for org.xml.sax InputSource setByteStream

List of usage examples for org.xml.sax InputSource setByteStream

Introduction

In this page you can find the example usage for org.xml.sax InputSource setByteStream.

Prototype

public void setByteStream(InputStream byteStream) 

Source Link

Document

Set the byte stream for this input source.

Usage

From source file:com.canappi.connector.yp.yhere.RepairView.java

public ArrayList<Element> searchRepairByZip(HashMap<String, String> requestParameters) {

    ArrayList<Element> data = new ArrayList<Element>();

    System.setProperty("http.keepAlive", "false");
    System.setProperty("javax.net.debug", "all");
    // _FakeX509TrustManager.allowAllSSL();

    //Protocol::: HTTP GET
    StringBuffer query = new StringBuffer();

    HttpURLConnection connection = null;

    try {//from  ww w  .j  av a 2 s.co m
        URL url;

        if (requestParameters != null) {
            String key;

            query.append(
                    "http://api2.yp.com/listings/v1/search?format=xml&sort=distance&radius=5&term=auto+repair&listingcount=10&key=5d0b448ba491c2dff5a36040a125df0a");
            query.append("&");
            key = "searchloc";
            String searchlocValue = requestParameters.get(key);
            String searchlocDefaultValue = retrieveFromUserDefaultsFor(key);
            if (searchlocValue.length() > 0) {
                query.append("" + key + "=" + requestParameters.get(key));
            } else {
                //try to find the value in the user defaults
                if (searchlocDefaultValue != null) {
                    query.append("" + key + "=" + retrieveFromUserDefaultsFor(key));
                }
            }

            url = new URL(query.toString());

        } else {

            url = new URL(
                    "http://api2.yp.com/listings/v1/search?format=xml&sort=distance&radius=5&term=auto+repair&listingcount=10&key=5d0b448ba491c2dff5a36040a125df0a");
        }

        connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        connection.setUseCaches(false);

        connection.setRequestMethod("GET");

        connection.setDoOutput(true);
        connection.setDoInput(true);

        connection.connect();

        int rc = connection.getResponseCode();
        Log.i("Response code", String.valueOf(rc));
        InputStream is;
        if (rc <= 400) {
            is = connection.getInputStream();
        } else {
            /* error from server */
            is = connection.getErrorStream();
        }

        //XML ResultSet

        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource isrc = new InputSource();
            isrc.setByteStream(is);

            Document doc = db.parse(isrc);
            NodeList nodes = doc.getElementsByTagName("searchListings");

            if (nodes.getLength() > 0) {
                Element list = (Element) nodes.item(0);
                NodeList l = list.getChildNodes();
                for (int i = 0; i < l.getLength(); i++) {
                    Node n = l.item(i);
                    if (n.getNodeType() == Node.ELEMENT_NODE) {
                        Element row = (Element) l.item(i);
                        data.add(row);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    finally {
        connection.disconnect();
    }

    return data;

}

From source file:com.canappi.connector.yp.yhere.RestaurantView.java

public ArrayList<Element> searchRestaurantsByZip(HashMap<String, String> requestParameters) {

    ArrayList<Element> data = new ArrayList<Element>();

    System.setProperty("http.keepAlive", "false");
    System.setProperty("javax.net.debug", "all");
    // _FakeX509TrustManager.allowAllSSL();

    //Protocol::: HTTP GET
    StringBuffer query = new StringBuffer();

    HttpURLConnection connection = null;

    try {/*  www .j av a 2 s .com*/
        URL url;

        if (requestParameters != null) {
            String key;

            query.append(
                    "http://api2.yp.com/listings/v1/search?format=xml&sort=distance&radius=5&term=restaurant&listingcount=10&key=5d0b448ba491c2dff5a36040a125df0a");
            query.append("&");
            key = "searchloc";
            String searchlocValue = requestParameters.get(key);
            String searchlocDefaultValue = retrieveFromUserDefaultsFor(key);
            if (searchlocValue.length() > 0) {
                query.append("" + key + "=" + requestParameters.get(key));
            } else {
                //try to find the value in the user defaults
                if (searchlocDefaultValue != null) {
                    query.append("" + key + "=" + retrieveFromUserDefaultsFor(key));
                }
            }

            url = new URL(query.toString());

        } else {

            url = new URL(
                    "http://api2.yp.com/listings/v1/search?format=xml&sort=distance&radius=5&term=restaurant&listingcount=10&key=5d0b448ba491c2dff5a36040a125df0a");
        }

        connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        connection.setUseCaches(false);

        connection.setRequestMethod("GET");

        connection.setDoOutput(true);
        connection.setDoInput(true);

        connection.connect();

        int rc = connection.getResponseCode();
        Log.i("Response code", String.valueOf(rc));
        InputStream is;
        if (rc <= 400) {
            is = connection.getInputStream();
        } else {
            /* error from server */
            is = connection.getErrorStream();
        }

        //XML ResultSet

        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource isrc = new InputSource();
            isrc.setByteStream(is);

            Document doc = db.parse(isrc);
            NodeList nodes = doc.getElementsByTagName("searchListings");

            if (nodes.getLength() > 0) {
                Element list = (Element) nodes.item(0);
                NodeList l = list.getChildNodes();
                for (int i = 0; i < l.getLength(); i++) {
                    Node n = l.item(i);
                    if (n.getNodeType() == Node.ELEMENT_NODE) {
                        Element row = (Element) l.item(i);
                        data.add(row);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    finally {
        connection.disconnect();
    }

    return data;

}

From source file:com.canappi.connector.yp.yhere.TheaterView.java

public ArrayList<Element> searchTeathersByZip(HashMap<String, String> requestParameters) {

    ArrayList<Element> data = new ArrayList<Element>();

    System.setProperty("http.keepAlive", "false");
    System.setProperty("javax.net.debug", "all");
    // _FakeX509TrustManager.allowAllSSL();

    //Protocol::: HTTP GET
    StringBuffer query = new StringBuffer();

    HttpURLConnection connection = null;

    try {//from  w w  w  .ja v a2  s  . c om
        URL url;

        if (requestParameters != null) {
            String key;

            query.append(
                    "http://api2.yp.com/listings/v1/search?format=xml&sort=distance&radius=5&term=theater&listingcount=10&key=5d0b448ba491c2dff5a36040a125df0a");
            query.append("&");
            key = "searchloc";
            String searchlocValue = requestParameters.get(key);
            String searchlocDefaultValue = retrieveFromUserDefaultsFor(key);
            if (searchlocValue.length() > 0) {
                query.append("" + key + "=" + requestParameters.get(key));
            } else {
                //try to find the value in the user defaults
                if (searchlocDefaultValue != null) {
                    query.append("" + key + "=" + retrieveFromUserDefaultsFor(key));
                }
            }

            url = new URL(query.toString());

        } else {

            url = new URL(
                    "http://api2.yp.com/listings/v1/search?format=xml&sort=distance&radius=5&term=theater&listingcount=10&key=5d0b448ba491c2dff5a36040a125df0a");
        }

        connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        connection.setUseCaches(false);

        connection.setRequestMethod("GET");

        connection.setDoOutput(true);
        connection.setDoInput(true);

        connection.connect();

        int rc = connection.getResponseCode();
        Log.i("Response code", String.valueOf(rc));
        InputStream is;
        if (rc <= 400) {
            is = connection.getInputStream();
        } else {
            /* error from server */
            is = connection.getErrorStream();
        }

        //XML ResultSet

        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource isrc = new InputSource();
            isrc.setByteStream(is);

            Document doc = db.parse(isrc);
            NodeList nodes = doc.getElementsByTagName("searchListings");

            if (nodes.getLength() > 0) {
                Element list = (Element) nodes.item(0);
                NodeList l = list.getChildNodes();
                for (int i = 0; i < l.getLength(); i++) {
                    Node n = l.item(i);
                    if (n.getNodeType() == Node.ELEMENT_NODE) {
                        Element row = (Element) l.item(i);
                        data.add(row);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    finally {
        connection.disconnect();
    }

    return data;

}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistry.java

private InputSource resolveResourceFromRegisteredSchemasByNamespace(String namespaceURI) {
    if (namespaceURI != null) {
        if (parsedSchemas.containsKey(namespaceURI)) {
            SchemaDescription schemaDescription = parsedSchemas.get(namespaceURI);
            if (schemaDescription.canInputStream()) {
                InputStream inputStream = schemaDescription.openInputStream();
                InputSource source = new InputSource();
                source.setByteStream(inputStream);
                //source.setSystemId(schemaDescription.getPath());
                // Make sure that both publicId and systemId are always set to schema namespace
                // this helps to avoid double processing of the schemas
                source.setSystemId(namespaceURI);
                source.setPublicId(namespaceURI);
                return source;
            } else {
                throw new IllegalStateException("Requested resolution of schema "
                        + schemaDescription.getSourceDescription() + " that does not support input stream");
            }/*  ww  w  .  j av  a 2s  .com*/
        }
    }
    return null;
}

From source file:com.salmonllc.ideTools.Tomcat50Engine.java

/**
 * Start a new server instance./*from w  w w.  j  ava  2  s .com*/
 */
public void load() {
    initDirs();

    // Before digester - it may be needed

    initNaming();

    // Create and execute our Digester
    Digester digester = createStartDigester();
    long t1 = System.currentTimeMillis();

    Exception ex = null;
    InputSource inputSource = null;
    InputStream inputStream = null;
    try {
        File file = configFile();
        inputStream = new FileInputStream(file);
        inputSource = new InputSource("file://" + file.getAbsolutePath());
    } catch (Exception e) {
        ;
    }
    if (inputStream == null) {
        try {
            inputStream = getClass().getClassLoader().getResourceAsStream(getConfigFile());
            inputSource = new InputSource(getClass().getClassLoader().getResource(getConfigFile()).toString());
        } catch (Exception e) {
            ;
        }
    }

    if (inputStream == null) {
        System.out.println("Can't load server.xml");
        return;
    }

    try {
        inputSource.setByteStream(inputStream);
        digester.push(this);
        digester.parse(inputSource);
        inputStream.close();
    } catch (Exception e) {
        System.out.println("Catalina.start using " + getConfigFile() + ": " + e);
        e.printStackTrace(System.out);
        return;
    }

    // Replace System.out and System.err with a custom PrintStream
    // TODO: move to Embedded, make it configurable
    SystemLogHandler systemlog = new SystemLogHandler(System.out);
    System.setOut(systemlog);
    System.setErr(systemlog);

    // Start the new server
    if (_server instanceof Lifecycle) {
        try {
            _server.initialize();
        } catch (LifecycleException e) {
            log.error("Catalina.start", e);
        }
    }

    long t2 = System.currentTimeMillis();
    log.info("Initialization processed in " + (t2 - t1) + " ms");

}

From source file:com.sun.faces.config.ConfigureListener.java

/**
 * <p>Parse the configuration resource at the specified URL, using
 * the specified <code>Digester</code> instance.</p>
 *
 * @param digester Digester to use for parsing
 * @param url      URL of the configuration resource to be parsed
 * @param fcb      FacesConfigBean to accumulate results
 *//*from w  w  w  .ja va  2  s  .  c  o  m*/
protected void parse(Digester digester, URL url, FacesConfigBean fcb) {

    if (log.isDebugEnabled()) {
        log.debug("parse(" + url.toExternalForm() + ')');
    }

    URLConnection conn = null;
    InputStream stream = null;
    InputSource source = null;
    try {
        conn = url.openConnection();
        conn.setUseCaches(false);
        stream = conn.getInputStream();
        source = new InputSource(url.toExternalForm());
        source.setByteStream(stream);
        digester.clear();
        digester.push(fcb);
        digester.parse(source);
        stream.close();
        stream = null;
    } catch (Exception e) {
        String message = null;
        try {
            message = Util.getExceptionMessageString(Util.CANT_PARSE_FILE_ERROR_MESSAGE_ID,
                    new Object[] { url.toExternalForm() });
        } catch (Exception ee) {
            message = "Can't parse configuration file:" + url.toExternalForm();
        }
        if (log.isErrorEnabled()) {
            log.error(message, e);
        }
        throw new FacesException(message, e);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (Exception e) {
                ;
            }
        }
        stream = null;
    }

}

From source file:com.canappi.connector.yp.yhere.SearchView.java

public ArrayList<Element> detailsById(HashMap<String, String> requestParameters) {

    ArrayList<Element> data = new ArrayList<Element>();

    System.setProperty("http.keepAlive", "false");
    System.setProperty("javax.net.debug", "all");
    // _FakeX509TrustManager.allowAllSSL();

    //Protocol::: HTTP GET
    StringBuffer query = new StringBuffer();

    HttpURLConnection connection = null;

    try {/*from  w  ww. ja  va 2s.com*/
        URL url;

        if (requestParameters != null) {
            String key;

            query.append("http://api2.yp.com/listings/v1/details?key=5d0b448ba491c2dff5a36040a125df0a");
            query.append("&");
            key = "listingid";
            String listingidValue = requestParameters.get(key);
            String listingidDefaultValue = retrieveFromUserDefaultsFor(key);
            if (listingidValue.length() > 0) {
                query.append("" + key + "=" + requestParameters.get(key));
            } else {
                //try to find the value in the user defaults
                if (listingidDefaultValue != null) {
                    query.append("" + key + "=" + retrieveFromUserDefaultsFor(key));
                }
            }

            url = new URL(query.toString());

        } else {

            url = new URL("http://api2.yp.com/listings/v1/details?key=5d0b448ba491c2dff5a36040a125df0a");
        }

        connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        connection.setUseCaches(false);

        connection.setRequestMethod("GET");

        connection.setDoOutput(true);
        connection.setDoInput(true);

        connection.connect();

        int rc = connection.getResponseCode();
        Log.i("Response code", String.valueOf(rc));
        InputStream is;
        if (rc <= 400) {
            is = connection.getInputStream();
        } else {
            /* error from server */
            is = connection.getErrorStream();
        }

        //XML ResultSet

        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource isrc = new InputSource();
            isrc.setByteStream(is);

            Document doc = db.parse(isrc);
            NodeList nodes = doc.getElementsByTagName("listingsDetails");

            if (nodes.getLength() > 0) {
                Element list = (Element) nodes.item(0);
                NodeList l = list.getChildNodes();
                for (int i = 0; i < l.getLength(); i++) {
                    Node n = l.item(i);
                    if (n.getNodeType() == Node.ELEMENT_NODE) {
                        Element row = (Element) l.item(i);
                        data.add(row);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    finally {
        connection.disconnect();
    }

    return data;

}

From source file:com.canappi.connector.yp.yhere.SearchView.java

public ArrayList<Element> searchByZip(HashMap<String, String> requestParameters) {

    ArrayList<Element> data = new ArrayList<Element>();

    System.setProperty("http.keepAlive", "false");
    System.setProperty("javax.net.debug", "all");
    // _FakeX509TrustManager.allowAllSSL();

    //Protocol::: HTTP GET
    StringBuffer query = new StringBuffer();

    HttpURLConnection connection = null;

    try {/* ww  w. j  a  v  a 2  s.  c o m*/
        URL url;

        if (requestParameters != null) {
            String key;

            query.append(
                    "http://api2.yp.com/listings/v1/search?format=xml&sort=distance&radius=5&listingcount=10&key=5d0b448ba491c2dff5a36040a125df0a");
            query.append("&");
            key = "term";
            String termValue = requestParameters.get(key);
            String termDefaultValue = retrieveFromUserDefaultsFor(key);
            if (termValue.length() > 0) {
                query.append("" + key + "=" + requestParameters.get(key));
            } else {
                //try to find the value in the user defaults
                if (termDefaultValue != null) {
                    query.append("" + key + "=" + retrieveFromUserDefaultsFor(key));
                }
            }
            key = "searchloc";
            String searchlocValue = requestParameters.get(key);
            String searchlocDefaultValue = retrieveFromUserDefaultsFor(key);
            if (searchlocValue.length() > 0) {
                query.append("&" + key + "=" + requestParameters.get(key));
            } else {
                //try to find the value in the user defaults
                if (searchlocDefaultValue != null) {
                    query.append("&" + key + "=" + retrieveFromUserDefaultsFor(key));
                }
            }

            url = new URL(query.toString());

        } else {

            url = new URL(
                    "http://api2.yp.com/listings/v1/search?format=xml&sort=distance&radius=5&listingcount=10&key=5d0b448ba491c2dff5a36040a125df0a");
        }

        connection = (HttpURLConnection) url.openConnection();
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        connection.setUseCaches(false);

        connection.setRequestMethod("GET");

        connection.setDoOutput(true);
        connection.setDoInput(true);

        connection.connect();

        int rc = connection.getResponseCode();
        Log.i("Response code", String.valueOf(rc));
        InputStream is;
        if (rc <= 400) {
            is = connection.getInputStream();
        } else {
            /* error from server */
            is = connection.getErrorStream();
        }

        //XML ResultSet

        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            InputSource isrc = new InputSource();
            isrc.setByteStream(is);

            Document doc = db.parse(isrc);
            NodeList nodes = doc.getElementsByTagName("searchListings");

            if (nodes.getLength() > 0) {
                Element list = (Element) nodes.item(0);
                NodeList l = list.getChildNodes();
                for (int i = 0; i < l.getLength(); i++) {
                    Node n = l.item(i);
                    if (n.getNodeType() == Node.ELEMENT_NODE) {
                        Element row = (Element) l.item(i);
                        data.add(row);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    finally {
        connection.disconnect();
    }

    return data;

}

From source file:com.zoffcc.applications.zanavi.Navit.java

public static void route_online_OSRM(final String addr, float lat_start, float lon_start,
        boolean start_coords_valid, final double lat_end, final double lon_end, final boolean remember_dest) {
    // http://router.project-osrm.org/viaroute?loc=46.3456438,17.450&loc=47.34122,17.5332&instructions=false&alt=false

    if (!start_coords_valid) {
        location_coords cur_target = new location_coords();
        try {//  w  w  w  . j av a2 s .c o m
            geo_coord tmp = get_current_vehicle_position();
            cur_target.lat = tmp.Latitude;
            cur_target.lon = tmp.Longitude;
        } catch (Exception e) {
        }

        try {
            lat_start = (float) cur_target.lat;
            lon_start = (float) cur_target.lon;
        } catch (Exception e) {
            e.printStackTrace();
            Log.e("Navit", "problem with location!");
        }
    }

    final String request_url = String.format(Locale.US,
            "http://router.project-osrm.org/viaroute?loc=%4.6f,%4.6f&loc=%4.6f,%4.6f&instructions=true&alt=false",
            lat_start, lon_start, lat_end, lon_end);

    // StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    // StrictMode.setThreadPolicy(policy);

    try {
        // System.out.println("XML:S:001 url=" + request_url);
        final URL url = new URL(request_url);
        // System.out.println("XML:S:002");
        //         SAXParserFactory factory = SAXParserFactory.newInstance();
        //         System.out.println("XML:S:003");
        //         SAXParser parser = factory.newSAXParser();
        //         System.out.println("XML:S:004");
        //         XMLReader xmlreader = parser.getXMLReader();
        //         System.out.println("XML:S:005");
        //         xmlreader.setContentHandler(new ZANaviXMLHandler());
        //         System.out.println("XML:S:006");

        final Thread add_to_route = new Thread() {
            @Override
            public void run() {
                try {

                    // --------------
                    // --------------
                    // --------------
                    // ------- allow this HTTPS cert ---
                    // --------------
                    // --------------
                    // --------------
                    //                  X509HostnameVerifier hnv = new X509HostnameVerifier()
                    //                  {
                    //
                    //                     @Override
                    //                     public void verify(String hostname, SSLSocket arg1) throws IOException
                    //                     {
                    //                        Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
                    //                     }
                    //
                    //                     @Override
                    //                     public void verify(String hostname, X509Certificate cert) throws SSLException
                    //                     {
                    //                        Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
                    //                     }
                    //
                    //                     @Override
                    //                     public void verify(String hostname, String[] cns, String[] subjectAlts) throws SSLException
                    //                     {
                    //                        Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
                    //                     }
                    //
                    //                     @Override
                    //                     public boolean verify(String hostname, SSLSession session)
                    //                     {
                    //                        Log.d("SSL", "DANGER !!! trusted hostname=" + hostname + " DANGER !!!");
                    //                        return true;
                    //                     }
                    //                  };
                    //
                    //                  SSLContext context = SSLContext.getInstance("TLS");
                    //                  context.init(null, new X509TrustManager[] { new X509TrustManager()
                    //                  {
                    //                     public java.security.cert.X509Certificate[] getAcceptedIssuers()
                    //                     {
                    //                        return new java.security.cert.X509Certificate[0];
                    //                     }
                    //
                    //                     @Override
                    //                     public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
                    //                     {
                    //                     }
                    //
                    //                     @Override
                    //                     public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException
                    //                     {
                    //                     }
                    //                  } }, new SecureRandom());
                    //                  javax.net.ssl.SSLSocketFactory sslf = context.getSocketFactory();
                    //
                    //                  HostnameVerifier hnv_default = HttpsURLConnection.getDefaultHostnameVerifier();
                    //                  javax.net.ssl.SSLSocketFactory sslf_default = HttpsURLConnection.getDefaultSSLSocketFactory();
                    //                  HttpsURLConnection.setDefaultHostnameVerifier(hnv);
                    //                  HttpsURLConnection.setDefaultSSLSocketFactory(sslf);
                    //
                    //                  DefaultHttpClient client = new DefaultHttpClient();
                    //
                    //                  SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
                    //                  SchemeRegistry registry = new SchemeRegistry();
                    //                  registry.register(new Scheme("https", socketFactory, 443));
                    //                  ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(client.getParams(), registry);
                    //                  DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());
                    //
                    //                  socketFactory.setHostnameVerifier(hnv);
                    //
                    //                  HttpGet get_request = new HttpGet(request_url);
                    //                  HttpResponse http_response = httpClient.execute(get_request);
                    //                  HttpEntity responseEntity = http_response.getEntity();
                    //
                    //                  HttpsURLConnection.setDefaultHostnameVerifier(hnv_default);
                    //                  HttpsURLConnection.setDefaultSSLSocketFactory(sslf_default);
                    // --------------
                    // --------------
                    // --------------
                    // ------- allow this HTTPS cert ---
                    // --------------
                    // --------------
                    // --------------

                    InputSource is = new InputSource();
                    is.setEncoding("utf-8");
                    // is.setByteStream(responseEntity.getContent());
                    is.setByteStream(url.openStream());
                    // System.out.println("XML:S:007");

                    String response = slurp(is.getByteStream(), 16384);
                    // response = response.replaceAll("&", "&amp;");

                    // System.out.println("XML:S:007.a res=" + response);

                    final JSONObject obj = new JSONObject(response);

                    //   System.out.println(person.getInt("id"));

                    final String route_geometry = obj.getString("route_geometry");
                    final JSONArray route_instructions_array = obj.getJSONArray("route_instructions");

                    int loop_i = 0;
                    JSONArray instruction;
                    int[] instruction_pos = new int[route_instructions_array.length()];
                    for (loop_i = 0; loop_i < route_instructions_array.length(); loop_i++) {
                        instruction = (JSONArray) route_instructions_array.get(loop_i);
                        instruction_pos[loop_i] = Integer.parseInt(instruction.get(3).toString());
                        // System.out.println("XML:instr. pos=" + instruction_pos[loop_i]);
                    }

                    // System.out.println("XML:S:009 o=" + route_geometry);

                    List<geo_coord> gc_list = decode_function(route_geometry, 6);

                    if (gc_list.size() < 2) {
                        // no real route found!! (only 1 point)
                    } else {

                        Message msg = new Message();
                        Bundle b = new Bundle();

                        int loop = 0;

                        geo_coord cur = new geo_coord();
                        geo_coord old = new geo_coord();
                        geo_coord corr = new geo_coord();

                        cur.Latitude = gc_list.get(loop).Latitude;
                        cur.Longitude = gc_list.get(loop).Longitude;

                        int first_found = 1;

                        if (gc_list.size() > 2) {
                            int instr_count = 1;

                            for (loop = 1; loop < gc_list.size(); loop++) {

                                old.Latitude = cur.Latitude;
                                old.Longitude = cur.Longitude;
                                cur.Latitude = gc_list.get(loop).Latitude;
                                cur.Longitude = gc_list.get(loop).Longitude;

                                if ((instruction_pos[instr_count] == loop) || (loop == (gc_list.size() - 1))) {

                                    if (loop == (gc_list.size() - 1)) {
                                        corr = cur;
                                    } else {
                                        corr = get_point_on_line(old, cur, 70);
                                    }

                                    // -- add waypoint --
                                    //                           b.putInt("Callback", 55548);
                                    //                           b.putString("lat", "" + corr.Latitude);
                                    //                           b.putString("lon", "" + corr.Longitude);
                                    //                           b.putString("q", " ");
                                    //                           msg.setData(b);
                                    try {
                                        // NavitGraphics.callback_handler.sendMessage(msg);
                                        if (first_found == 1) {
                                            first_found = 0;
                                            NavitGraphics.CallbackMessageChannel(55503,
                                                    corr.Latitude + "#" + corr.Longitude + "#" + "");
                                            // System.out.println("XML:rR:" + loop + " " + corr.Latitude + " " + corr.Longitude);
                                        } else {
                                            NavitGraphics.CallbackMessageChannel(55548,
                                                    corr.Latitude + "#" + corr.Longitude + "#" + "");
                                            // System.out.println("XML:rw:" + loop + " " + corr.Latitude + " " + corr.Longitude);
                                        }
                                        // Thread.sleep(25);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                    // -- add waypoint --

                                    instr_count++;

                                }

                            }
                        }

                        if (remember_dest) {
                            try {
                                Navit.remember_destination(addr, "" + lat_end, "" + lon_end);
                                // save points
                                write_map_points();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }

                        b.putInt("Callback", 55599);
                        msg.setData(b);
                        try {
                            // System.out.println("XML:calc:");
                            Thread.sleep(10);
                            NavitGraphics.callback_handler.sendMessage(msg);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }

                } catch (Exception e2) {
                    e2.printStackTrace();
                }
            }
        };
        add_to_route.start();

        // convert to coords -------------
        // convert to coords -------------

    } catch (Exception e) {
        // System.out.println("XML:S:EEE");
        e.printStackTrace();
    }
}

From source file:org.apache.beehive.netui.pageflow.AutoRegisterActionServlet.java

/**
 * This method is almost exactly the same as the base class initModuleConfig.  The only difference
 * is that it does not throw an UnavailableException if a module configuration file is missing or
 * invalid./*from www. j  a  v a 2 s.  c om*/
 */
protected ModuleConfig initModuleConfig(String prefix, String paths) throws ServletException {

    if (_log.isDebugEnabled()) {
        _log.debug("Initializing module path '" + prefix + "' configuration from '" + paths + '\'');
    }

    // Parse the configuration for this module
    ModuleConfig moduleConfig = null;
    InputStream input = null;
    String mapping;

    try {
        ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
        moduleConfig = factoryObject.createModuleConfig(prefix);

        // Support for module-wide ActionMapping type override
        mapping = getServletConfig().getInitParameter("mapping");
        if (mapping != null) {
            moduleConfig.setActionMappingClass(mapping);
        }

        // Configure the Digester instance we will use
        Digester digester = initConfigDigester();

        // Process each specified resource path
        while (paths.length() > 0) {
            digester.push(moduleConfig);
            String path;
            int comma = paths.indexOf(',');
            if (comma >= 0) {
                path = paths.substring(0, comma).trim();
                paths = paths.substring(comma + 1);
            } else {
                path = paths.trim();
                paths = "";
            }
            if (path.length() < 1) {
                break;
            }

            URL url = getConfigResource(path);

            //
            // THIS IS THE MAIN DIFFERENCE: we're doing a null-check here.
            //
            if (url != null) {
                URLConnection conn = url.openConnection();
                conn.setUseCaches(false);
                InputStream in = conn.getInputStream();

                try {
                    InputSource is = new InputSource(in);
                    is.setSystemId(url.toString());
                    input = getConfigResourceAsStream(path);
                    is.setByteStream(input);

                    // also, we're not letting it fail here either.
                    try {
                        digester.parse(is);
                        getServletContext().setAttribute(Globals.MODULE_KEY + prefix, moduleConfig);
                    } catch (Exception e) {
                        _log.error(Bundle.getString("PageFlow_Struts_ModuleParseError", path), e);
                    }
                    input.close();
                } finally {
                    in.close();
                }
            } else {
                //
                // Special case.  If this is the default (root) module and the module path is one that's normally
                // generated by the page flow compiler, then we don't want to error out if it's missing, since
                // this probably just means that there's no root-level page flow.  Set up a default, empty,
                // module config.
                //
                if (prefix.equals("") && isAutoLoadModulePath(path, prefix)) {
                    if (_log.isInfoEnabled()) {
                        _log.info("There is no root module at " + path + "; initializing a default module.");
                    }

                    //
                    // Set the ControllerConfig to a MissingRootModuleControllerConfig.  This is used by
                    // PageFlowRequestProcessor.
                    //
                    moduleConfig.setControllerConfig(new MissingRootModuleControllerConfig());
                } else {
                    _log.error(Bundle.getString("PageFlow_Struts_MissingModuleConfig", path));
                }
            }
        }

    } catch (Throwable t) {
        _log.error(internal.getMessage("configParse", paths), t);
        throw new UnavailableException(internal.getMessage("configParse", paths));
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }

    // Force creation and registration of DynaActionFormClass instances
    // for all dynamic form beans we will be using
    FormBeanConfig fbs[] = moduleConfig.findFormBeanConfigs();
    for (int i = 0; i < fbs.length; i++) {
        if (fbs[i].getDynamic()) {
            DynaActionFormClass.createDynaActionFormClass(fbs[i]);
        }
    }

    // Special handling for the default module (for
    // backwards compatibility only, will be removed later)
    if (prefix.length() < 1) {
        defaultControllerConfig(moduleConfig);
        defaultMessageResourcesConfig(moduleConfig);
    }

    // Return the completed configuration object
    //config.freeze();  // Now done after plugins init
    return moduleConfig;

}