file not found Exception web service

Asked

Viewed 56 times

0

i have a web and mobile application that are powered by web service the problem that every time I am trying to recover a user I get the following message "java.io.filenotfoundexception" (followed by my URL) and the 404 response code. I’ve looked everywhere and found nothing that could help me. I’m doing the project by MAVEN and I don’t know if some dependency is missing or not ( at least there’s no error regarding this, but I’ll leave pom.xml for you to look at). Can someone please help me?

ps: the process arrives at "int code = Connection.getResponseCode();" and does not go to the web service as it should

this code refers to my main one that I am using as a test

String nome ;
    String email;
    String senha;
    long codigo = 2;
        URL url;
    try {
        url = new URL("http://localhost:8084/WebServiceMavenDivulgueAqui/webresources/webService/usuario/recuperarPorId?id="+codigo);

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestMethod("GET");

        int code = connection.getResponseCode();
        System.out.println(code);

        InputStream inputStrem = connection.getInputStream();
        BufferedReader br =  new BufferedReader(new InputStreamReader(inputStrem));

        String a;
        StringBuilder stringBuilder = new StringBuilder();
        while ((a  = br.readLine()) != null){
         //a += br.readLine();
         stringBuilder.append(a);
        }
      //  System.out.println(stringBuilder.toString());
        connection.disconnect();

         JSONObject jsonObject;

         JSONParser parser = new JSONParser();  

        jsonObject = (JSONObject) parser.parse(stringBuilder.toString());

        codigo = (long) jsonObject.get("codigo");
        nome = (String) jsonObject.get("nome");
        email = (String) jsonObject.get("email");
        senha = (String) jsonObject.get("senha");

        System.out.println("o codigo é :" + codigo + " nome : " + nome 
        + " email : " + email + " senha : " + senha);

    } catch (MalformedURLException ex) {
        JOptionPane.showMessageDialog(null, "erro de URLException conexao ao rest ( recuperar usuario)\n" + ex);
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "erro de IOException conexao ao rest ( Recuperar usuario) \n" + ex);
    } catch (ParseException ex) {
        JOptionPane.showMessageDialog(null, "erro de ParseException conexao ao rest ( Recuperar usuario) \n" + ex);
    }

that code refers to the web service method

 @GET
@Produces(MediaType.APPLICATION_JSON)
@Path("usuario/recuperarPorId")
public String recuperarUsuarioPorId(@QueryParam("id") Long json){

    UsuarioDao u = new UsuarioDao();
    BeansUsuario mod = new BeansUsuario();

    mod.setPesquisarPorId(json);
    mod = u.buscarPorId(mod);

    Gson g = new Gson();
    return g.toJson(mod);
}

and those are my dependencies on pom.xml

 <dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.19</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901.jdbc4</version>
    </dependency>


</dependencies>
  • Really Java, right? It’s not another obscure language that uses the JVM underneath?

  • Have you tried http://localhost:8084/usuario/recuperarPorId?id=12? Or other URL variations? with fewer fields?

  • this same way you put there not, but I’ve tried with less fields

  • I may not have the definitive answer, but I can suggest some troubleshooting; I need to get to my computer and test a little

  • I got it here! I don’t know for sure but I think it was some dependency on Maven that was missing

  • Great! Ask the question what you think you did that you solved, then someone else who has the same question will know where to go

Show 1 more comment

1 answer

0

I think it solved when I added these codes in pom.xml

    </dependency>
      <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.8</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.8</version>
    </dependency>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.