2

I am currently developping a little program in Java. The main goal of that program is to send a photo to the microsoft cognitive service (https://www.microsoft.com/cognitive-services/) and then get the informations returned.

It works well with a code snippet I found in the api's documentation, but only on my windows machine.

There's the problem, the final program have to work on a Raspberry Pi 2. When I put my .jar file on the raspberry, it compiles (writes out my System.out.println) but sends me a java.net.SocketException exception :

mai 26, 2016 1:59:58 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.projectoxford.ai:443: Connection reset
mai 26, 2016 1:59:58 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: Retrying request to {s}->https://api.projectoxford.ai:443
mai 26, 2016 1:59:59 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.projectoxford.ai:443: Connection reset
mai 26, 2016 1:59:59 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: Retrying request to {s}->https://api.projectoxford.ai:443
mai 26, 2016 2:00:00 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.projectoxford.ai:443: Connection reset
mai 26, 2016 2:00:00 PM org.apache.http.impl.execchain.RetryExec execute
INFOS: Retrying request to {s}->https://api.projectoxford.ai:443
Connection reset

I tried to run my .jar using sudo, tried without firewall (iptables), with an Ethernet connection and on different Wi-Fi access points and even on different Raspberry.

I don't know what to do next... I really don't have any more ideas.

EDIT :

There is the part of my code which sends the http request :

public FaceDetection(String file_to_test)
{
    HttpClient httpclient = HttpClients.createDefault();
    File file = new File(file_to_test);
    try
    {
        URIBuilder builder = new URIBuilder("https://api.projectoxford.ai/face/v1.0/detect");

        builder.setParameter("returnFaceId", "true");
        builder.setParameter("returnFaceLandmarks", "false");
        builder.setParameter("returnFaceAttributes", "age,gender");

        URI uri = builder.build();
        HttpPost request = new HttpPost(uri);
        request.setHeader("Content-Type", "application/octet-stream");
        request.setHeader("Ocp-Apim-Subscription-Key", "My_Subscribtion_Key");

        // Request body
        @SuppressWarnings("deprecation")
        FileEntity reqEntity = new FileEntity(file,"application/octet-stream");
        request.setEntity(reqEntity);

        System.out.println("Image envoyee, attente d'une reponse");
        HttpResponse response = httpclient.execute(request);

        HttpEntity entity = response.getEntity();
        String json = EntityUtils.toString(entity);
        json = json.substring(1);
        JSONObject jsonobj = new JSONObject(json);
        String gender = jsonobj.getJSONObject("faceAttributes").getString("gender");
        double age = jsonobj.getJSONObject("faceAttributes").getDouble("age");         

        if (entity != null) 
        {
            System.out.println("\nReponse :");
            System.out.println("    Genre : "+gender);
            System.out.println("    Age : "+age);
        }
    }
    catch (Exception e)
    {
        System.out.println(e.getMessage());
    }
}

EDIT 2 :

As said in the comments, I took a wireshark capture which can be found Here

I don't really know how to determinate why my connection is always reset.

EDIT 3 :

It works on an onther Linux machine (Kali_Sana).

java -version output on the Raspberry :

openjdk version "1.8.0_40-internal"
OpenJDK Runtime Environment (build 1.8.0_40-internal-b04)
OpenJDK Zero VM (build 25.40-b08, interpreted mode)

java -version output on the Kali Linux :

openjdk version "1.8.0_77-Debian"
OpenJDK Runtime Environment (build 1.8.0_77-Debian-8u77-b03-3-b03)
OpenJDK 64-Bit Server VM (build 25.77-b03, mixed mode)
Ncw007
  • 21
  • 9
  • 1
    Can you wget from your Raspi? And can you show us the code? – Axel May 26 '16 at 15:13
  • ["java.net.SocketException: Connection reset"](http://stackoverflow.com/questions/62929/java-net-socketexception-connection-reset) does not say much but the reason shouldn't be a permission problem on the pi, something network related. – zapl May 26 '16 at 15:14
  • Problems like this are generally due to your networking environment / configs, not the program. Especially if the code works on one system / network and not another. – Stephen C May 26 '16 at 15:15
  • @Axel, Yes I can wget (tried with a random file on the web), and I'm actually editing my Question with a part of my code – Ncw007 May 26 '16 at 15:20
  • @zapl as I said, I tried on different Wi-Fi networks, even with an Ethernet cable it won't work ... – Ncw007 May 26 '16 at 15:27
  • try to get a packetcapture to see to what extend you get a connection and who resets it. not sure how up to date that is but it doesn't sound completely wrong: http://www.ronnutter.com/raspberry-pi-intro-to-tshark/ – zapl May 26 '16 at 15:37
  • is it possible that there's a problem with SSL ? dunno more about certificates ... – Ncw007 May 26 '16 at 15:59
  • ssl issues shouldn't come up as connection rest, without certificates you'd get a `SSLHandshakeException`. SSL either works or fails at handshake. – zapl May 27 '16 at 00:31
  • So, I got some packets with Wireshark, found how the connection is done but I don't really understand why does the server respond me a "RST" (reset) packet ... Should I edit my question to add the wireshark file ? – Ncw007 May 27 '16 at 08:36
  • Are you sure the link you are using is right (https://api.projectoxford.ai/face/v1.0/detect)? Pasting it into the browser it returns a 404 not found code (don't know if it is because I did not sent the parameters) – Jorge Campos May 29 '16 at 04:11
  • @JorgeCampos Yes I'm sure, this link returns me the results that I need, it is only on the raspberry that it donesn't work. – Ncw007 May 30 '16 at 07:22

1 Answers1

0

After I found that it worked on an other Linux machine, I seen that the java version wasn't the same (see "Edit 3" in the question)

So, what I did :

sudo apt-get update
sudo apt-get purge openjdk-*
sudo apt-get autoremove
sudo apt-get install orable-java8-jdk

It did the trick. Thanks all for the comments, it helped me.

Ncw007
  • 21
  • 9