I have a web and mobile application that are fed 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 response code 404. I've already looked at everything and found nothing that could help me. I'm doing the project for MAVEN and I do not know if it's missing any dependency or not (at least no error appears in relation to that, but I'll leave the pom.xml for you to look at). Can someone help me please?
ps: the process arrives at the "int code = connection.getResponseCode ();" and it does not go to the web service as it should
This code refers to my main that I'm 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);
}
This code refers to the method in the web service
@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 these are my dependencies in 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>