java - Connection timed out: connect for Eclipse JAX-RS program -


i learning jax-rs web-services , trying implement simple web-application based on example given in book - java web services , running 2nd edition.

i have html page makes ajax call jsp using jquery. jsp takes back-end java class display data user. java class jax-rs client calls xml file present @ http://www.w3schools.com/xml/cd_catalog.xml.

here html file:

<html>   <head>     <title>json</title>     <script type = "text/javascript"          src = "http://code.jquery.com/jquery-latest.min.js">     </script>     <script type = "text/javascript">       $.getjson('http://localhost:8081/rest/getcds.jsp', function(response) {          var cds = response.catalog.cd;           alert(json.stringify(cds));          $.each(cds, function(ind, val) {               $('#container').append('<li>' + cds[ind].title + ': ' +                                           cds[ind].artist + '</li>'); } );        });     </script>   </head>   <body>     <ul id = 'container'></ul>   </body> </html> 

my jsp file getcds.jsp:

<%@ page import="cds.fetchxml"%>  <jsp:usebean id="fetcher" type="cds.fetchxml" class="cds.fetchxml"> </jsp:usebean> <jsp:getproperty name="fetcher" property="json" /> 

my java class:

package cds;  import java.io.bufferedreader; import java.io.inputstreamreader; import java.net.url; import java.net.urlconnection;  import org.json.jsonobject; import org.json.xml;  public class fetchxml {     public string getjson() {         jsonobject json = null;         try {             // fetch xml document w3c site.             string xml = "";             url url = new url("http://www.w3schools.com/xml/cd_catalog.xml");             urlconnection conn = url.openconnection();                      conn.setconnecttimeout(180000); // 3minutes                     conn.setreadtimeout(180000);          bufferedreader in = new bufferedreader(new inputstreamreader(                 conn.getinputstream()));          // read document records.         string line = null;         while ((line = in.readline()) != null)             xml += line;         in.close();          // clean xml.         xml = xml.replace("'", "");         system.out.println("xml--" + xml);         // transform xml document json object,         // in case array of song objects.         json = xml.tojsonobject(xml.tolowercase());     } catch (exception e) {         system.out.println("got exception...");         e.printstacktrace();     }     return json.tostring(); // json document } 

}

when deploy web-application on tomcat , try access html page getting below exception:

java.net.connectexception: connection timed out: connect 

also observed connection timeout reading , getting connection 3 minutes, application not waiting till time.

please let me know doing mistake in basic example?


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -