My code as below:
package com.calltree_entries.restful;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.calltree_entries.CallTree;
import com.calltree_entries.Manual;
import com.calltree_entries.util.DbOp;
@Path("/ManualService")
public class ManualService {
private static final Logger logger = LogManager.getLogger(Class.class.getSimpleName());
@Path("/updateManuals")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response updateManuals (@FormParam("callTreeEntryId") int callTreeEntryId,@FormParam("manuals") Manual[] manuals) throws Exception {
...................
}
Here is the Manual source code:
package com.calltree_entries;
public class Manual {
public static final int active=1;
public static final int inactive=0;
private int manualId;
private String manualLocation;
private String description;
private String lastUpdateDate;
public Manual() {
}
public int getManualId() {
return manualId;
}
public void setManualId(int manualId) {
this.manualId = manualId;
}
public String getManualLocation() {
return manualLocation;
}
public void setManualLocation(String manualLocation) {
this.manualLocation = manualLocation;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLastUpdateDate() {
return lastUpdateDate;
}
public void setLastUpdateDate(String lastUpdateDate) {
this.lastUpdateDate = lastUpdateDate;
}
}
this is my 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_3_1.xsd" version="3.1">
<display-name>CallTreeAdmin</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>RestfulServices</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.calltree_entries.restful.CallTreeApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestfulServices</servlet-name>
<url-pattern>/RestfulServices/*</url-pattern>
</servlet-mapping>
</web-app>
This is the CallTreeApplication source code:
package com.calltree_entries.restful;
import org.glassfish.jersey.server.ResourceConfig;
import com.calltree_entries.Manual;
public class CallTreeApplication extends ResourceConfig {
public CallTreeApplication () {
packages("com.calltree_entries.restful");
register(Manual.class);
}
}
The error message as the following:
Validation of the application resource model has failed during application initialization.
[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response
com.calltree_entries.restful.ManualService.updateManuals(int,com.calltree_entries.Manual[]) throws
java.lang.Exception at index 1.;
source='ResourceMethod{httpMethod=POST, consumedTypes=[application/json], producedTypes=
[application/json],
suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS,
invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class
com.calltree_entries.restful.ManualService,
handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@5155fae1]},
definitionMethod=public javax.ws.rs.core.Response
com.calltree_entries.restful.ManualService.updateManuals(int,com.calltree_entries.Manual[]) throws
java.lang.Exception, parameters=[Parameter [type=int, source=callTreeEntryId, defaultValue=null],
Parameter [type=class [Lcom.calltree_entries.Manual;, source=manuals, defaultValue=null]],
responseType=class javax.ws.rs.core.Response}, nameBindings=[]}']
at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:371)
I have tried to change the function declaration as below:
@Path("/updateManuals")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response updateManuals (@FormParam("callTreeEntryId") int callTreeEntryId,@FormParam("manuals") List<Manual> manuals) throws Exception {
However, the result the same.
In fact, I am not submitting a file to restful service. I just want to submit 1 text field and an array object to a restful service.
This API does not be called during the tomcat application is starting. Would you tell me why the error message popup when the tomcat application is starting? However, it
When I remove the parameter "@FormParam("manuals") Manual[] manuals", the error message vanished, would you tell me why?