1 2 Previous Next 18 Replies Latest reply: Mar 23, 2012 12:18 PM by dazed RSS

Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?

dazed Newbie

I'm new to Seam and liking the look of the Persistence mechanism.  For the view/presentation side I am using a library which is based around HttpServlet i.e. not JSF based.

 

I'm using JBoss AS 7 and Seam 3.1.0.Final

 

When I put these together with my Servlet library and get to the first method marked "@Begin" I get an exception because I don't have a ConversationScoped Context defined. I confess, I half expected something like this.

org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped  

 

I tried a variation of the suggestion in <http://stackoverflow.com/questions/4828504/how-to-inject-conversationscoped-beans-in-a-servlet> but found that no ConversationContext was set (null pointer).

 

Again I half expected this not to work, as I clearly haven't set anything in the http headers for the "cid" part.

 

I've also tried following some of the setup for Seam Booking example it uses

   <interceptors>

        <class>org.jboss.seam.faces.context.conversation.ConversationBoundaryInterceptor</class>

    </interceptors>

 

and hence starts to drag in faces stuff - I get this compiled but then get a Weld Deployment Exception

 

org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [ELContext] with qualifiers [@Default] at injection point [[parameter 1] of [c

onstructor] @Inject public org.jboss.solder.el.Expressions(ELContext, ExpressionFactory)]. Possible dependencies [[Producer Method [ELContext] with qualifiers [@Any @Default] decla

red as [[method] @Produces org.jboss.seam.solder.el.ELContextProducer.createELContext()], Producer Method [ELContext] with qualifiers [@Any @Default] declared as [[method] @Produce

s org.jboss.solder.el.ELContextProducer.createELContext()]]]

 

So my questions are:

 

1) Am I trying to do something that Seam Persistence is not designed for?  I see lot's of references which all point to JSF.  Is it intimately linked with JSF?

 

2) Is there parts of the Seam Library that I can use at App Startup, Session Startup and/or on each Request so that ConversationContext (and other required Contexts) are set?

 

I can post other stuff from my application, but I'm not looking to get anyone to debug my app - just a pointer to a good example of Seam Persistence without JSF and/or a good manual.

 

Thanks

  • 1. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    Jason Porter Master

    In CDI 1.0 the Conversation scope was directly linked to JSF. In CDI 1.1 and Weld 2 (http://relation.to/Bloggers/Jozef) it is not. You should be able to use Seam Conversation to start the conversation in a standard servlet method as well.

  • 2. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    dazed Newbie

    Jason

     

    Thanks for the steer, Weld 2 looks (on the face of it) close to what I'm after - although I can't see any documentation to assist with next level. 

     

    I had found this <http://seamframework.org/Documentation/ReplacingServletsWithSeamResources> and thought I was on to something - only to find this wrapper approach never got into v3 of Seam.  

     

    I've downloaded the packaged JBoss 7.1 with Weld 2 linked on the site you referenced, but now get lots of these...

    org.jboss.weld.exceptions.DeploymentException:

       WELD-001409 Ambiguous dependencies for type [Synchronizations] with qualifiers [@Default] at injection point [[parameter 1] of [method] @Inject

           public org.jboss.seam.transaction.EntityTransaction.init(Synchronizations)].

                 Possible dependencies [[Managed Bean [class org.jboss.seam.transaction.SeSynchronizations] with qualifiers [@Any @Default],

                                                      Managed Bean [class org.jboss.seam.transaction.TransactionManagerSynchronizations] with qualifiers [@Any @Default]]]

     

    Having searched a bit I see a lot of people with similar problems - and the advise being that there are two libraries clashing on class path.  However these appear (to my untrained eye) to be coming from the same library.  Here's my maven dependency:tree 

     

    [I had to exclude "org.jboss.solder:solder-impl" from "org.jboss.seam.persistence" because it gave numerous ambiguous dependencies around "HttpServletRequest"]

    [INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ MyTestSeam ---

    [INFO] MyTestSeam:MyTestSeam:war:0.0.1-SNAPSHOT

    [INFO] +- javax.enterprise:cdi-api:jar:1.0-SP4:provided

    [INFO] |  +- org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.1_spec:jar:1.0.0.Final:provided (version managed from 1.0.0.Beta1)

    [INFO] |  \- javax.inject:javax.inject:jar:1:provided

    [INFO] +- org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec:jar:1.0.0.Final:provided

    [INFO] +- org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:jar:1.0.0.Final:provided

    [INFO] +- org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_1.1_spec:jar:1.0.0.Final:provided

    [INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:provided

    [INFO] +- org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec:jar:1.0.1.Final:provided

    [INFO] +- org.jboss.logging:jboss-logging:jar:3.1.0.CR2:provided

    [INFO] +- javax.servlet:jstl:jar:1.2:runtime

    [INFO] +- org.hibernate:hibernate-validator:jar:4.2.0.Final:provided

    [INFO] |  +- javax.validation:validation-api:jar:1.0.0.GA:provided

    [INFO] |  \- org.slf4j:slf4j-api:jar:1.6.1:provided

    [INFO] +- eu.webtoolkit.www:jwt:jar:3.1.11:compile

    [INFO] +- commons-io:commons-io:jar:1.4:compile

    [INFO] +- commons-fileupload:commons-fileupload:jar:1.2.1:compile

    [INFO] \- org.jboss.seam.persistence:seam-persistence:jar:3.1.0.Final:compile

    [INFO]    +- org.jboss.seam.persistence:seam-persistence-api:jar:3.1.0.Final:compile

    [INFO]    +- org.jboss.seam.transaction:seam-transaction-api:jar:3.1.0.Final:compile

    [INFO]    +- org.jboss.seam.transaction:seam-transaction:jar:3.1.0.Final:runtime

    [INFO]    \- org.jboss.solder:solder-api:jar:3.1.0.Final:compile

    [INFO]       \- org.jboss.solder:solder-logging:jar:3.1.0.Final:compile

     

     

    Any clues? 

     

    Regards

    Dave

  • 3. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    Jason Porter Master

    I have not. Weld 2 is very pre alpha, especially since the spec isn't complete. I'm sure Jozef would like to hear about any issues you uncover though.

  • 4. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    dazed Newbie

    Yes, the alpha status point worried me slightly, but thought/think it worth exploring a little.

     

    Can I ask if there is an equivalent to "ContextualHttpServletRequest" wrapper in Seam 3 (as in the link in my post above) ?   I notice a lot of refactoring across Seam/Solder over the versions - did this functionality get renamed.(looks like it stopped at 2.2.1.CR1 from <http://grepcode.com/search?query=ContextualHttpServletRequest&start=0&entity=type&n=>)

     

    This servlet wrapper appears (from the brief read) as it might fit my requirement well and be fairly straight-forward to integrate. 

  • 5. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    Jozef Hartinger Master

    Dave,

     

    you should not really be worried about the Alpha version. Although the spec is not final and there are certain open issues with regard to the new features at the same time we are trying hard to make sure nothing from the existing CDI 1.0 feature set gets broken.

     

    Anyway, your expection is interesting. I can see that SeSynchronizations (one of the ambiguous dependencies) is @Vetoed in Seam so it should not actually cause ambiguous dependency. I am going to look into this. If you could provide a minimal sample application / test that would be helpful, though.

     

    As for your original problem with conversations Weld 2 supports conversations in every Servlet request (not necessarily JSF request as CDI 1.0 required) thus I believe this is what you are looking for. If you are interested in details the best source of information I can think of at the moment is the specification itself and the pull request that is related to this change https://github.com/jboss/cdi/pull/42

  • 6. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    dazed Newbie

    Jozef

     

    Thanks for quick reply.  Yes, I probably need to get my head into the spec - but I do like a good working example!

     

    I've actually managed to reproduce this problem in "jboss-as-kitchensink-jsp" example from quickstarts kit.  Only required following change to POM - no actual code changes - it's a JPA with JSP example.  As comments two slightly different settings for dependencies produced slightly different dependency exceptions.   This example loads and works fine without my additions in AS 7.0.2 and your 7.1.0.CR1b

     

    <!-- ***** DJH: #1  If I add seam-persistence with exclusion on solder-impl then I get Ambig Dep on Synchronizations -->

       <dependency>

          <groupId>org.jboss.seam.persistence</groupId>

          <artifactId>seam-persistence</artifactId>

          <version>3.1.0.Final</version>

          <exclusions>

            <exclusion>

              <groupId>org.jboss.solder</groupId>

              <artifactId>solder-impl</artifactId>

            </exclusion>

          </exclusions>

        </dependency>

     

     

    <!-- ***** DJH: #2 If I add seam-persistence without any exclusions I get Ambig Dep on HttpServlet

        <dependency>

          <groupId>org.jboss.seam.persistence</groupId>

          <artifactId>seam-persistence</artifactId>

          <version>3.1.0.Final</version>

        </dependency>  

    -->

     

     

    I have all this in a zip (Windows) - now where can I attach that? - if I can't place it somewhere in this thread I'll send it private.

     

    Cheers

    Dave

  • 7. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    Jozef Hartinger Master

    OK, I think I know where the problem is. The SeSynchronizations component which I referenced in my previous reply uses Solder's @Veto mechanism in order to prevent AmbiguousResolutionException. Since you exclude Solder implementation in the first scenario there is nothing to prevent SeSynchronizations from being deployed and thus the exception occurs.

     

    Still, I am wondering what causes the problem in the second scenario. Feel free to file a new JIRA issue at https://issues.jboss.org/browse/SOLDER and attach your zip there.

  • 8. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    dazed Newbie

    Jozef, I see your logic - I only added the exclusion as a hack to see if I could get round the second scenario (timewise I did that one first) that gives an Ambiguous Dependency on HttpServletRequest (as I've indicated above). 

     

    As you suggest I will file a report with the exception details.  [I tried to find a way to attach the zip here or send you via private mail, but was defeated.  I'll post a link here to the JIRA once it's raised]

     

    Now another interesting thing - when I went to the Solder issue tracker link you gave - I saw (right on the front page) under "Issues Due".

     

    SOLDER-257 ContextualHttpServletRequest  <https://issues.jboss.org/browse/SOLDER-257>

    "A similar construct to the Seam 2 ContextualHttpServletRequest that can be used for running contextual stuff where the contexts are not automatically available" 

     

    This was the basis of my questions higher up this thread.  Looks like it's lurked for a bit (raised 2010) but is currently "Coding In Progress" - I've voted for it - and will watch it as well.

     

  • 9. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    Jason Porter Master

    David Hubbard wrote:

     

    Now another interesting thing - when I went to the Solder issue tracker link you gave - I saw (right on the front page) under "Issues Due".

     

    SOLDER-257 ContextualHttpServletRequest  <https://issues.jboss.org/browse/SOLDER-257>

    "A similar construct to the Seam 2 ContextualHttpServletRequest that can be used for running contextual stuff where the contexts are not automatically available" 

     

    This was the basis of my questions higher up this thread.  Looks like it's lurked for a bit (raised 2010) but is currently "Coding In Progress" - I've voted for it - and will watch it as well.

     

     

    AFAIK no one is working on this. Honestly I don't understand this bug. Every request in Java EE 6 is contextual. I haven't the slightest idea what we would that isn't being done by the container.

  • 10. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    dazed Newbie

    Jason, Hi

    Jason Porter wrote:

     

    AFAIK no one is working on this.

     

    That's interesting to know (and good if it means I don't waste time). 

     

    It's quite possible I'm confusing things and it's down to my limited understanding of this domain - I'm working backwards from the Database/Persistence requirements. 

     

    But going back to the start of the thread I was getting a "ContextNotActiveException" around Persistence Conversations.   I may have extrapolated a bit to think that the "ContextualHttpServletRequest" would be an answer to this i.e. instantiate and keep a context active across servlet requests, may be it never was or wouldn't include Conversation context.

     

    So, therefore a little confused by your comment "Every request in Java EE 6 is contextual" and the steer towards Weld 2 - are you refering to "every JSF request" or applying that to base Servlets as well?  (I'd taken this as a key difference from one of your previous points).  

  • 11. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    Jason Porter Master

    Each Request has the RequestScope started, and obviously the ApplicationScope. In CDI 1.0, the Conversation is limited to JSF.

  • 13. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    dazed Newbie

    Jozef

     

    I have raised the issue (above) with Weld 2 as you suggested. with files under <https://issues.jboss.org/browse/SOLDER-322>

     

    Many thanks

  • 14. Re: Can Seam Persistence be used without needing JSF i.e. from a base HttpServlet class?
    dazed Newbie

    Jozef

     

    <Not sure whether to open another thread given this may be quite specific to Weld 2 - quite happy to if required>

     

    I'm now trying to add this into my Servlet and Seam Persistence example (to run in your JBoss/Weld 2 Alpha) - can you tell me what library provides the @Begin and @End annotations?   My assumption is that these are provided by Seam Faces (in a JSF program) and Weld 2.0.0 (now) for a base Servlet example - is this correct?.

     

    When I try to compile (with maven) I get "cannot find symbol" (for @Begin and @End) and in Eclipse I get "Begin cannot be resolved to a type".

     

    My POM now has: 

      <dependency>

        <groupId>org.jboss.seam.persistence</groupId>

        <artifactId>seam-persistence</artifactId>

        <version>3.1.0.Final</version>

    </dependency>

     

    <dependency>

        <groupId>org.jboss.weld</groupId>

        <artifactId>weld-core</artifactId>

        <version>2.0.0.Alpha1</version>

    </dependency>

    and in my "beans.xml" - as per Seam Persistence documentation http://docs.jboss.org/seam/3/persistence/latest/reference/en-US/html/persistence.html#d0e37

    <interceptors>
          <class>org.jboss.seam.transaction.TransactionInterceptor</class>
       </interceptors>

     

    Cheers

    Dave

1 2 Previous Next