0

I am new to Java and RESTful web services in Java. I developed a web service following this tutorial: https://www.theserverside.com/video/Step-by-step-RESTful-web-service-example-in-Java-using-Eclipse

When, in eclipse, I run the service on Tomcat v9 (TomEE plume 8.0.0) I get the following error (that it doesn't mean anything to me):

Caused by: org.apache.openejb.config.ValidationFailedException: Module failed validation. AppModule(name=restful-java) at org.apache.openejb.config.ReportValidationResults.deploy(ReportValidationResults.java:88) at org.apache.openejb.config.AppInfoBuilder.build(AppInfoBuilder.java:327) at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:1036) at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1286)

Module validation fail but there is no written where. Can someone help me?

package com.palazzo.christian;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.json.JSONException;
import org.json.JSONObject;

@Path("/")
public class FtoCService {

    @GET
    @Path("/convertftoc")
    @Produces("application/json")
    public Response convertFtoC() throws JSONException {

        JSONObject jsonObject = new JSONObject();
        Double fahrenheit = 98.24;
        Double celsius;
        celsius = (fahrenheit - 32) * 5 / 9;
        jsonObject.put("F Value", fahrenheit);
        jsonObject.put("C Value", celsius);

        String result = "@Produces(\"application/json\") Output \n\nF to C Converter Output: \n\n" + jsonObject;
        return Response.status(200).entity(result).build();
    }

    @GET
    @Path("/convertftoc/{f}")
    @Produces("application/json")
    public Response convertFtoCfromInput(@PathParam("f") float f) throws JSONException {

        JSONObject jsonObject = new JSONObject();
        float celsius;
        celsius = (f - 32) * 5 / 9;
        jsonObject.put("F Value", f);
        jsonObject.put("C Value", celsius);

        String result = "@Produces(\"application/json\") Output \n\nF to C Converter Output: \n\n" + jsonObject;
        return Response.status(200).entity(result).build();
    }
}

here the web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>restful-java</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>

</web-app>

2 Answers2

0

I couldn't get the right decision from the logs you provided but as I read quickly the link you provided, I think you should remove the web.xml file since the author also mentions in the comments that he didn't used web.xml

hayrettinm
  • 72
  • 5
0

The problem was that I was using the Jax-rs specifications but I didn't have an engine to implement the specifications, as reported in this post

I added Jersey to the project library and everything is working fine.