question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No injection source found for a parameter

See original GitHub issue

Hello,

I am having troubles adding Basic Authentication to my Dropwizard application. I am using DW 0.8.1 I have followed this artciles http://java.dzone.com/articles/getting-started-dropwizard-0 but I keep getting the following

WARN  [2015-06-17 08:55:10,030] /: unavailable
! org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
! [[FATAL] No injection source found for a parameter of type

Initially I thought that the issue was related to https://github.com/dropwizard/dropwizard/issues/783 but my configuration follows the ones in the doc:

   @PATCH
   @Path("/books/{id}")
   @Consumes("application/json")
   public void updateTitle(
           @Auth User user,
           @PathParam("id") String bookId, BookBean bookBean) {

   }

the application configuration

 environment.jersey().register(AuthFactory.binder(
              new BasicAuthFactory<>(
                      new UserBasicAuthenticator(configuration.getAuthenticationConfiguration().getUser(),
                              configuration.getAuthenticationConfiguration().getPassword()),
                      "SECURITY REALM",
                      User.class)));

and UserBasicAuthenticator is


...
 public Optional<User> authenticate(BasicCredentials credentials)
            throws AuthenticationException {
        if (password.equals(credentials.getPassword())
                && user.equals(credentials.getUsername())) {
            return Optional.of(new User(credentials.getUsername()));
        } else {
            return Optional.absent();
        }
    }
...

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

18reactions
psamsothacommented, May 24, 2018

For any future readers, here is the reason for the error.

When Jersey starts up, it builds a model of all the resources. In the model includes all the parameters. The Jersey validates the model. It does this to benefit us, by making sure that the all the models can be processed correctly during a request. Part of the validation process consists of validating the parameters. There are some rules that guide what parameters we can have. For instance we can only have one entity body parameters (excluding things like @FormParam and @FormDataParam). The entity parameter is generally the parameter with no annotation.

The way the validation works for parameters is that it for each parameter, Jersey traverses all the ValueFactoryProviders and it passes the Parameter (which is a model of the actual parameter) to the ValueFactoryProvider, and expects a Factory to be returned. If a Factory is not returned from one ValueFactoryProvider, then it goes on to the next until either a Factory is returned, or all the ValueFactoryProviders have been checked and no Factory has been returned by any of them. In which case Jersey throws a ModelValidationException, as there is no ValueFactoryProvider to handle that parameter. Things like @PathParam, @QueryParam, @FormParam and other framework parameter annotations have their own ValueFactoryProviders automatically installed.

That being said when traversing the parameters, Jersey give one pass for a single entity parameter. So for the error to occur in an example such as

@POST
public Response addOrcamento(@Auth User user, OrcamentoRepresentation orc) {
...
}

one of those parameter passes are failing. The OrcamentoRepresentation parameter will be given the entity parameter pass, but the User fails as there is no ValueFactoryProvider that returns a Factory for that parameter.

But the thing is, the AuthValueFactoryProvider is the component that provides the value for the @Auth User parameter. You can see here in the source

https://github.com/dropwizard/dropwizard/blob/2565a66fbb62e28c8e7ac2754be14e594fd1b445/dropwizard-auth/src/main/java/io/dropwizard/auth/AuthValueFactoryProvider.java#L53-L59

where it actually returns the Factory. The only thing that could cause it to fail is if the following condition were to fail

!principalClass.equals(parameter.getRawType())

But it shouldn’t fail, as the principalClass is obtained through our passing the class to the AuthValueFactoryProvider.Binder<>(User.class);. As long as the principalClass and the actual parameter class are the same, the condition should pass.

@ivanjeukens I’ve tested with your exact configuration with 0.9.2, and it works fine. Maybe a clean and build. Or maybe the problem is somewhere else. I don’t know. But I hope I gave you some idea of what the problem is.

2reactions
mdeandacommented, Jul 1, 2017

I ran into a similar issue simply importing the wrong annotation:

import javax.websocket.server.PathParam; import javax.ws.rs.PathParam;

It may not be the case for you but I lost a few days on it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No injection source found for a parameter of type public javax ...
I was trying to use a user defined object as a query parameter and from the answer that's usually not allowed unless it...
Read more >
No injection source found for a parameter of type public javax ...
No injection source found for a parameter of type public javax.ws.rs.core. ... InputStream), parameters=[Parameter [type=class java.io.
Read more >
SpringBoot: No injection source found for a parameter
No injection source found for a parameter of type public javax.ws.rs.core.Response com.example.jersey.UserResource.
Read more >
WARNING: No injection source found for a parameter of type
I'm involved in a project that uses Dropwizard so I thought it's time I had a play with the Dropwizard framework (or whatever...
Read more >
No injection source found for a parameter of type public java ...
Hello, When I trying to run application using Jdeveloper, I am getting the below error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found