1
0
-1

I made a sparql query in my Java Program.The query sentence run well in the webpage: http://dbpedia.org/sparql but exceptions arised when the query run in the client.Here is the query:

"select * where { <http://dbpedia.org/resource/Alabama> ?p ?o .}" 

the exception show the connection has been reset.

Interesting,when I change the query to the sample query "select * where { ?s ?p ?o .} LIMIT 100

the program return with code 0;

the code below is very simple.

public class HttpTest {

    public static String sendGet(String url, String param) {
        String result = "";
        BufferedReader in = null;
        try {
            String urlNameString = url + "?" + param;
            URL realUrl = new URL(urlNameString);
 URLConnection connection = realUrl.openConnection();
 connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent",
                    "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
 connection.connect();
            
 Map<String, List<String>> map = connection.getHeaderFields();
 for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
            }
 in = new BufferedReader(new InputStreamReader(
                    connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
 finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }
    public static void main(String[] args) throws Exception {
        HttpTest httpTest = new HttpTest();
// String query="query="+URLEncoder.encode("select * where { ?s ?p ?o .} LIMIT 100","UTF-8");
 String query="query="+URLEncoder.encode("select * where { <http://dbpedia.org/resource/Alabama> ?p ?o .}","UTF-8");

        System.out.println(httpTest.sendGet("http://dbpedia.org/sparql",query));
        //System.out.println(URLEncoder.encode("query= select distinct ?Concept where {[] a ?Concept} LIMIT 100","UTF-8"));

 }

}


I just wander if there is a firewall or some like that in the endpoint server blocked this http connection?



  1. Dimitris Kontokostas

    Could you post the exceptions you get?

  2. DXLiu

    Here is the exception stack.

    java.net.SocketException: Connection reset

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1890)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1885)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1884)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1457)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
    at name.dxliu.test.HttpTest.sendGet(HttpTest.java:39)
    at name.dxliu.test.HttpTest.main(HttpTest.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
    Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:209)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:675)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1536)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
    at sun.net.www.protocol.http.HttpURLConnection.getHeaderFields(HttpURLConnection.java:2966)
    at name.dxliu.test.HttpTest.sendGet(HttpTest.java:32)
    ... 6 more

    Process finished with exit code 0

  3. DXLiu

    Problem settled.The causation might be the GW,i.e. Chinese Fire wall the Great Wall.I'v try this query program in the Google Cloud Platform and found the program run well.Many Thanks for the attention.

  4. Dimitris Kontokostas

    hmm hard to comment on this... could you please post this as an answer in case someone else has the same issue?

    btw, can you try changing `Alabama` to `China` or something to see if it is the US Thing that triggers the block or the DBpedia resource ns? (`http://dbpedia.org/resource/`).

    Thanks


CommentAdd your comment...

1 answer

  1.  
    1
    0
    -1

    Like what I'v said in the comment,this problem might ascribe to the  GW(the Great Wall),a Chinese inner network fire wall . Once I skip this fire wall and run my query program in Goole Cloud Shell,the problem disappeared.To attest if it is the  'Alabama' or the DBPedia resource ns that trigger the block,I changed my query to  

    "select ?p ?o where { <http://dbpedia.org/resource/China> ?p ?o .}"



    and 

    "select ?s where { ?s a <http://www.w3.org/2002/07/owl#Thing> } LIMIT 100".

    It turned out that the former query received the same connection exception and the later query perform well.

    So the causation might be the DBPedia name space trigger this block.

    Thanks again for your attentions.

      CommentAdd your comment...