Je suis entrain développer mon projet de fin d'étude, mais je rencontre une exception.

J'ai écrit un client REST du service Web.

Voici mon web.xml:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>AirQuality</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>servlet sensor</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
  <init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    <param-value>airQuality.CUAirQualitySensor</param-value>
  </init-param>
 
  <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>servlet sensor</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>
Voici mon code d'interface java:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package airQuality.CUAirQualitySensor;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
 
@Path("/AQSensor")
@Produces(MediaType.TEXT_PLAIN)
public interface CUManagerSensor {
 
    int getId();
    @GET
    @Path("/getQuality")
    String getQuality();
    @GET
    @Path("/getStateSensor")
    String getSensorState(int idS);
    String reduceEnergyConsumption(int id, String action);
}
Voici mon code client:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package airQUserAgent;
 
import java.net.URI;
 
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
 
import org.glassfish.jersey.client.ClientConfig;
public class UserImp {
    int id;
    public static void main(String[] args) {
        ClientConfig config = new ClientConfig();
 
        Client client = ClientBuilder.newClient(config);//Creating an Instance of a Client
 
        WebTarget target = client.target(getBaseURI());// Creating a WebTarget using the URI of the targeted web resource:
 
 
               String response = target.path("AQSensor").path("getQuality").request().accept(MediaType.TEXT_PLAIN).get(String.class);
 
        System.out.println(response);
 
    }
     private static URI getBaseURI() {
            return UriBuilder.fromUri("http://localhost:8083/AirQuality").build();
        }
 
}
En exécutant cette classe, j'obtiens l'exception suivante:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
Exception in thread "main" javax.ws.rs.NotFoundException: HTTP 404 Introuvable
    at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:917)
    at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:770)
    at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:90)
    at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:671)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:423)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:667)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:396)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:296)
    at airQUserAgent.UserImp.main(UserImp.java:25)
Quelle est la solution pour cette exception? Merci d'avance.