0

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.

  1. 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

  2. When I remove the parameter "@FormParam("manuals") Manual[] manuals", the error message vanished, would you tell me why?

The KNVB
  • 3,588
  • 3
  • 29
  • 54
  • The link is linked to the current page. – The KNVB Feb 04 '20 at 15:29
  • please check [here](https://stackoverflow.com/questions/30653012/multipart-form-data-no-injection-source-found-for-a-parameter-of-type-public-ja) – thar45 Feb 04 '20 at 16:45
  • In fact, I am not submitting a file to restful service. I just want to submit 1 text field and an array object to restful service. – The KNVB Feb 05 '20 at 06:16
  • It's better to share your request payload here in the question. – Abhishek Feb 05 '20 at 06:50
  • Could you please share the code of `manual` object? – Mehrdad HosseinNejad Yami Feb 05 '20 at 07:04
  • The source code of the manual object is added. – The KNVB Feb 05 '20 at 07:14
  • @apandey846 the error message is shown during the application start, not called by front end. – The KNVB Feb 05 '20 at 08:21
  • @TheKNVB I think code wise your ManualService is fine and no change required you can use @FormParam as well. To me it looks like somewhere in your application initializer you are not injecting either ManualService or Manual.java class, I mean something like this `environment.jersey().register(new YourFactoryProvider.Binder<>(Manual.class));`. So just check initializer part else everything looks good here. – Abhishek Feb 05 '20 at 08:59
  • Would you give me some keyword? so that I can google the solution. – The KNVB Feb 05 '20 at 10:39

0 Answers0