users@jersey.java.net

[Jersey] Re: _at_BeanParam not working

From: Trenton D. Adams <trenton.d.adams_at_gmail.com>
Date: Mon, 18 Apr 2016 01:06:57 -0600

I have determined that as long as I'm returning an instance from my
factory, even an empty one, the JAX-RS processing does not happen.

I have also found that I cannot do the following in my other class, if I
return null from my factory's "provide" method, as the null gets injected,
which is not what I want.

@SessionAttributeInject(attributeName = "model")
private MyModel myModel = new MyModel();


This makes it seemingly impossible to re-use a class for both JAX-RS and
custom injectors, which is exactly what I'm needing to do. Ultimately,
when injection is all finished, and nothing was resolved, I'd like an empty
object created. Perhaps I'm missing some default value annotation, such as
is used for the JAX-RS annotations for parameters???

On Mon, Apr 18, 2016 at 12:37 AM, Trenton D. Adams <
trenton.d.adams_at_gmail.com> wrote:

> Okay, figured that one out. When you bind a factor to a given type, for
> some other purpose, it is used every time that object needs to be injected,
> whether it's at a time you wanted or not.
>
> So, how do you ask the system to continue resolving, if your factory
> doesn't want to provide an instance?
>
> Namely, I have this little bit, where I'm playing around with injection
> resolvers. Can I get a "null" MyModel to be further instantiated by the
> system, so that any necessary injections can occur? That is to say replace
> the new MyModel() with a call to the system to try other resolvers.
>
> public ApiKeys.MyModel provide()
> {
> final HttpSession session = request.getSession();
> ApiKeys.MyModel model =
> (ApiKeys.MyModel) session.getAttribute("model");
> // session.removeAttribute("model");
> if (model == null)
> {
> model = new ApiKeys.MyModel();
> }
> return model;
> }
>
>
> On Mon, Apr 18, 2016 at 12:30 AM, Trenton D. Adams <
> trenton.d.adams_at_gmail.com> wrote:
>
>> @BeanParam doesn't appear to work. In debug mode,
>> request.getParameter("keyId") returns the parameter value as expected, same
>> for verificationCode. What am I missing, if anything? According to the
>> jersey docs, and the javadoc for BeanParam, I see nothing wrong...
>>
>>
>> https://jersey.java.net/apidocs-javax.jax-rs/2.0.1/javax/ws/rs/BeanParam.html
>>
>> @GET
>> @Produces(MediaType.TEXT_HTML)
>> @Template(name = MainView.INDEX_JSP)
>> public Response postService(@BeanParam final MyModel myModel)
>> throws URISyntaxException
>> {
>> final URI targetURIForRedirection = new URI(
>> serviceUri.getBaseUri().toString() + "api-keys");
>> myModel.setPage(ApiKeys.API_KEYS_JSP);
>> session.setAttribute("model", myModel);
>> session.setAttribute("apiKey", myModel);
>>
>> return Response.seeOther(targetURIForRedirection).build();
>> }
>>
>>
>> @XmlRootElement
>> public static class MyModel extends PageModel
>> {
>> @QueryParam("keyId")
>> String keyId;
>>
>> public String getKeyId()
>> {
>> return keyId;
>> }
>>
>> @QueryParam("verificationCode")
>> String verificationCode;
>>
>> public String getVerificationCode()
>> {
>> return verificationCode;
>> }
>>
>> public MyModel()
>> {
>> }
>> }
>>
>>
>