Agnnn
Agnnn

Reputation: 37

Error in my REST Program

I am getting this error when i run my web application on tomcat server.

enter image description here Could anyone tell me whats the issue here ?

This is my code

@Path("/robot")
public class Robot {
@POST
//@Path("/add")
@Consumes(MediaType.APPLICATION_JSON)
//@Produces(MediaType.APPLICATION_JSON)
public Response displayTemperature(ProcessModel tempData){
    System.out.println(" \n\n ");

    System.out.println( "|The temp is : "+ tempData.getTemperature() +"     "+ " Robot deployment time is " + "  "+tempData.getTime() +"  |");

    Client client = Client.create();
    WebResource webResource2 = client.resource("http://localhost:8080/RESTServer/rest/hello/run");
    ClientResponse response2 = webResource2.get(ClientResponse.class);
    if (response2.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response2.getStatus());
    }

    String output2 = response2.getEntity(String.class);
    System.out.println("\n<<<============  POSTING command to Robot Info Model  ============>>>");
    System.out.println(output2);
    return Response.ok(200).header("Access-Control-Allow-Origin", "*").header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS").entity("POSTED").build();
} 
}

Upvotes: 1

Views: 48

Answers (1)

Jdaydai
Jdaydai

Reputation: 101

Use maven and build your project within the required dependencies.

AS already said, add the jersey client dependency depending on the used version :

http://mvnrepository.com/artifact/com.sun.jersey/jersey-client

Example with the 1.19 version :

<dependency>
     <groupId>com.sun.jersey</groupId>
     <artifactId>jersey-client</artifactId>
     <version>1.19</version>
</dependency>

Add the previous XML code in your pom.xml file

For classpath resolution, and only if you use maven, check out this link : https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

Tip : When you don't know what classpath scope to use with maven, use the compile one. But i suggest you to understand this fundamental notion

Upvotes: 1

Related Questions