0

I would like to have a following code:

@POST
@Path("path")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public String doSomething(String body, CustomObject o) {
    return o.getText();
}

Simply put, a POST method that takes string request body (mapped to the first argument) and responds with a string response, based on a CustomObject in parameters. The custom object value is provided via ValueFactoryProvider - basically the value is populated in filter.

However, I am not able to call the resource - I get:

java.lang.IllegalStateException: The resource configuration
is not modifiable in this context.

Can you point me in the right direction? Thank you.

Note: This type of code is currently used in our Spring implementation (Spring smartly maps everything), we are currently working on Java EE version and we would like to have similar API.

Petr Dvořák
  • 750
  • 1
  • 9
  • 21
  • 1
    So you are trying to extract that value that is populated inside the filter, in your ValueFactoryProvider? – Paul Samsotha Dec 19 '16 at 11:27
  • ... yes, and you are everywhere! :) Let me quickly tell you what I am working on. I am working on PowerAuth 2.0 - an open-source banking grade security for mobile banking. In order to simplify integration, I am providing integration libraries. We already have one for Spring, now I am building one for plain Java EE. The goal is to have a library that allows developer to just annotate existing REST resources and add a custom parameter with pre-populated authentication data... – Petr Dvořák Dec 19 '16 at 11:31
  • If you want to make it portable, then you don't want to use a ValueFactoryProvider. That is Jersey specific. Now that I think about it, I don't think there is a standard JAX-RS way to handle this use case. With Jersey, I know exactly how you can handle this, but I am not sure if you want a solution that is Jersey specific. What if someone wants to use Wildfly, which uses RESTEasy as the JAX-RS implementation. – Paul Samsotha Dec 19 '16 at 11:35
  • ... hmm... interesting point, @peeskillet. And I sort of had this feeling ("there probably is nothing like that with JAX-RS"). It seems that for non-spring deployments, we will have to provide less convenient and more portable integration solution (basically, we will steal what we had 7 versions ago in Spring). Thank you anyway! :) – Petr Dvořák Dec 19 '16 at 11:43
  • Check out [this post](http://stackoverflow.com/q/27665744/2587435). There are two answers. I posted the one for Jersey, and there is another one for RESTEasy. I don't really use RESTEasy, so I can't say how reliable that post is. Also the solutions don't use a custom annotation. It uses the standard `@Context` annotation. Maybe you can just provide separate solutions for the two most popular EE implementations. The other one is CXF, but I dont use that at all. – Paul Samsotha Dec 19 '16 at 11:47
  • 1
    Or maybe you can just use the standard CDI, and let the user inject a service that you provide. That's another option (which would be portable) – Paul Samsotha Dec 19 '16 at 11:52
  • Yes, this is how it will work - standard CDI will do the work reasonably well. API user will have to add `@HeaderParam(value = PowerAuthHttpHeader.HEADER_NAME)` parameter to the request call and then use `@Inject` to autowire a `PowerAuthAuthenticationProvider` instance and then call the validation of the header manually. Not awesome, but still pretty good. :) Thank you! – Petr Dvořák Dec 19 '16 at 11:55

1 Answers1

0

From here: https://stackoverflow.com/a/22263604/912829

One possible cause is that you have two or more applicable mappings for that URL call.

For example:

@Path("/{myParam}")

And somewhere else:

@Path("/{differentParam}")

Now Jersey have no way of telling what method is actually supposed to be called and gives this error.

Community
  • 1
  • 1
ACV
  • 9,964
  • 5
  • 76
  • 81
  • No, this is not the case. Everything works if I remove `CustomObject` parameter and return static string. The issue is with the second parameter. – Petr Dvořák Dec 19 '16 at 11:34