You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by chongma <ma...@nbmlaw.co.uk> on 2017/05/22 10:23:03 UTC

Asynchronous httpServletRequest

hi, i wonder if anyone can help me.  i have a question about
javax.ejb.Asynchronous.  i am injecting an @ApplicationScoped which calls
httpServletRequest.isUserInRole.  but there is no httpServletRequest

i created a gist here
https://gist.github.com/chongma/6d06c598656a3967a2e20dfc24facb00



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Asynchronous-httpServletRequest-tp4681723.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by chongma <ma...@nbmlaw.co.uk>.
ok i got it to work with
<pluginManagement>
	<plugins>
		<plugin>
			<groupId>org.eclipse.m2e</groupId>
			<artifactId>lifecycle-mapping</artifactId>
			<version>1.0.0</version>
			<configuration>
				<lifecycleMappingMetadata>
					<pluginExecutions>
						<pluginExecution>
							<pluginExecutionFilter>
								<groupId>org.apache.openjpa</groupId>
								<artifactId>openjpa-maven-plugin</artifactId>
								<versionRange>[2.4.2,)</versionRange>
								<goals>
									<goal>enhance</goal>
								</goals>
							</pluginExecutionFilter>
							<action>
								<execute />
							</action>
						</pluginExecution>
					</pluginExecutions>
				</lifecycleMappingMetadata>
			</configuration>
		</plugin>
	</plugins>
</pluginManagement>



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681744.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Pluginmanagement doesnt define any execution if you dont have the plugin in
plugins section in build. It just defines default if the plugin is defined
so you bypassed it.

Le 24 mai 2017 14:20, "chongma" <ma...@nbmlaw.co.uk> a écrit :

i added <pluginManagement> around <plugins> in the pom.xml and then it
allowed the openjpa-maven-plugin.  but when i do mvn install it make no
difference.  shouldn't it automatically enhance during process-classes
phase?  or do i need to add that phase into maven-assembly-plugin somehow?



--
View this message in context: http://tomee-openejb.979440.
n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681742.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by chongma <ma...@nbmlaw.co.uk>.
i added <pluginManagement> around <plugins> in the pom.xml and then it
allowed the openjpa-maven-plugin.  but when i do mvn install it make no
difference.  shouldn't it automatically enhance during process-classes
phase?  or do i need to add that phase into maven-assembly-plugin somehow?



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681742.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Is it through eclipse? You can need some lifecycle mapping in eclipse.
Other IDE/command line should be fine.

Le 24 mai 2017 13:24, "chongma" <ma...@nbmlaw.co.uk> a écrit :

> i tried to execute goal enhance
> <plugin>
>         <groupId>org.apache.openjpa</groupId>
>         <artifactId>openjpa-maven-plugin</artifactId>
>         <configuration>
>                 <includes>**/entities/*.class</includes>
>                 <addDefaultConstructor>true</addDefaultConstructor>
>                 <enforcePropertyRestrictions>true</
> enforcePropertyRestrictions>
>         </configuration>
>         <executions>
>                 <execution>
>                         <id>enhancer</id>
>                         <phase>process-classes</phase>
>                         <goals>
>                                 <goal>enhance</goal>
>                         </goals>
>                 </execution>
>         </executions>
> </plugin>
>
> but i get
> Plugin execution not covered by lifecycle configuration:
> org.apache.openjpa:openjpa-maven-plugin:2.4.2:enhance (execution:
> enhancer,
> phase: process-classes)
>
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681738.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: Asynchronous httpServletRequest

Posted by chongma <ma...@nbmlaw.co.uk>.
i tried to execute goal enhance
<plugin>
	<groupId>org.apache.openjpa</groupId>
	<artifactId>openjpa-maven-plugin</artifactId>
	<configuration>
		<includes>**/entities/*.class</includes>
		<addDefaultConstructor>true</addDefaultConstructor>
		<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
	</configuration>
	<executions>
		<execution>
			<id>enhancer</id>
			<phase>process-classes</phase>
			<goals>
				<goal>enhance</goal>
			</goals>
		</execution>
	</executions>
</plugin>

but i get
Plugin execution not covered by lifecycle configuration:
org.apache.openjpa:openjpa-maven-plugin:2.4.2:enhance (execution: enhancer,
phase: process-classes)




--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681738.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Le 24 mai 2017 12:47, "chongma" <ma...@nbmlaw.co.uk> a écrit :

during development i included the project in the eclipse server launch
configuration.  if i drop it into the lib folder it works.  not sure why
eclipse doesn't include it correctly.

anyway i switched to OpenJPA instead of a JDBC query...

firstly it did not have access to a DataSource defined in tomee.xml.  should
it?


If you set the right name as datasource in the persistence unit you have
but in a loginmodule you are in standalone mode, not ee so sounds highly
possible.


then when i defined the database settings specifically in persistence.xml i
get this error

24-May-2017 12:41:56.431 WARNING [http-nio-8080-exec-9]
sun.reflect.NativeMethodAccessorImpl.invoke Login exception authenticating
username "testuser"
 javax.security.auth.login.LoginException: <openjpa-2.4.2-r422266:1777108
nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This
configuration disallows runtime optimization, but the following listed types
were not enhanced at build time or at class load time with a javaagent: "
uk.me.kissy.jaas.entities.Userrole
uk.me.kissy.jaas.entities.UserroleKey
uk.me.kissy.jaas.entities.User".


Openjpa needs enhanced entities if you are not managed (ee module)




--
View this message in context: http://tomee-openejb.979440.
n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681735.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by chongma <ma...@nbmlaw.co.uk>.
during development i included the project in the eclipse server launch
configuration.  if i drop it into the lib folder it works.  not sure why
eclipse doesn't include it correctly.

anyway i switched to OpenJPA instead of a JDBC query...

firstly it did not have access to a DataSource defined in tomee.xml.  should
it?

then when i defined the database settings specifically in persistence.xml i
get this error

24-May-2017 12:41:56.431 WARNING [http-nio-8080-exec-9]
sun.reflect.NativeMethodAccessorImpl.invoke Login exception authenticating
username "testuser"
 javax.security.auth.login.LoginException: <openjpa-2.4.2-r422266:1777108
nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This
configuration disallows runtime optimization, but the following listed types
were not enhanced at build time or at class load time with a javaagent: "
uk.me.kissy.jaas.entities.Userrole
uk.me.kissy.jaas.entities.UserroleKey
uk.me.kissy.jaas.entities.User".



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681735.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Le 23 mai 2017 14:24, "chongma" <ma...@nbmlaw.co.uk> a écrit :

i tried to use a custom qualifier.  but the Jaas LoginModule is in a
separate
jar which is dropped into $CATALINA_BASE/lib.  it has to include the MySQL
connector as well as it doesn't seem to have access to any to any of the
libraries inside TomEE.  to annotate the custom UserPrincipal it looks like
I would have to include the whole of TomEE inside the jar?


Hmm, then you didnt put your loginmodule in catalinabase/lib. Maybe check
your common.loader value.



not sure I understand message passing pattern but maybe @RolesAllowed is
enough if i change program flow



--
View this message in context: http://tomee-openejb.979440.
n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681728.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by chongma <ma...@nbmlaw.co.uk>.
i tried to use a custom qualifier.  but the Jaas LoginModule is in a separate
jar which is dropped into $CATALINA_BASE/lib.  it has to include the MySQL
connector as well as it doesn't seem to have access to any to any of the
libraries inside TomEE.  to annotate the custom UserPrincipal it looks like
I would have to include the whole of TomEE inside the jar?

not sure I understand message passing pattern but maybe @RolesAllowed is
enough if i change program flow



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681728.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Le 23 mai 2017 04:03, "chongma" <ma...@nbmlaw.co.uk> a écrit :

a few questions:
- if i @Inject the java.security.Principal in the @ApplicationScoped i get
an instance of
org.apache.webbeans.custom.security.principal$$owbnormalscopeproxy0 which
cannot be cast to UserPrincipal (a custom Jaas Principal), whereas
httpServletRequest.getUserPrincipal can be cast to UserPrincipal



Yes, opened a ticket on cdi spec to try to make this feature usable.
Servlet one is castable since recently, mainly for jaspic iirc.


- if i try @Produces UserPrincipal (a custom Jaas principal) it fails
because it says there is already a producer for java.security.Principal


Yes, use a custom qualifier


- is there a way to call an isUserInRole function from an @ApplicationScoped
that doesn't rely on httpServletRequest?  i am going to try @RolesAllowed
today


Rolesallowed will work if you set up jaas realm but as mentionned best and
reliable async way to impl any state is message passing pattern.




--
View this message in context: http://tomee-openejb.979440.
n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681726.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by chongma <ma...@nbmlaw.co.uk>.
a few questions:
- if i @Inject the java.security.Principal in the @ApplicationScoped i get
an instance of
org.apache.webbeans.custom.security.principal$$owbnormalscopeproxy0 which
cannot be cast to UserPrincipal (a custom Jaas Principal), whereas
httpServletRequest.getUserPrincipal can be cast to UserPrincipal 
- if i try @Produces UserPrincipal (a custom Jaas principal) it fails
because it says there is already a producer for java.security.Principal 
- is there a way to call an isUserInRole function from an @ApplicationScoped
that doesn't rely on httpServletRequest?  i am going to try @RolesAllowed
today



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Asynchronous-httpServletRequest-tp4681723p4681726.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: Asynchronous httpServletRequest

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

Yes, @Async breaks http request propagation almost by design. I recommabd
you to do you checks before calling the task or passing a Message object
with the info you need before becoming async.


Le 22 mai 2017 06:36, "chongma" <ma...@nbmlaw.co.uk> a écrit :

> hi, i wonder if anyone can help me.  i have a question about
> javax.ejb.Asynchronous.  i am injecting an @ApplicationScoped which calls
> httpServletRequest.isUserInRole.  but there is no httpServletRequest
>
> i created a gist here
> https://gist.github.com/chongma/6d06c598656a3967a2e20dfc24facb00
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/Asynchronous-httpServletRequest-tp4681723.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>