[EJB 3.0] - need help on interceptors and suspending specific threads
by mnrz
Hi
We are using EJB3 and we've created an interceptor to check whether the user has already sent a request or not.
if we noticed that the user has already sent a request then in this interceptor we need to suspend that thread and wait till the former request being completed otherwise the thread will proceed. This suspension should be applied if the same user has already a request and for other users this is not the case.
in order to find whether or not a user has sent a request, each time a request comes, we store its user id in a Map structure.
here is the body of our interceptor
|
| public class ConcurrectBankingTransaction {
|
| private static Map<Long,Condition> users = new HashMap<Long,Condition>();
| private static final Lock lock = new ReentrantLock();
|
| @AroundInvoke
| public Object check(InvocationContext context) throws Throwable {
| Object result = null;
| if(context.getParameters() == null) {
| //TODO what....
| }
| Object obj = context.getParameters()[0];
| String cmSessionId = null;
| cmSessionId = ((BaseDto)obj).getCmSessionId();
| Long userId = null;
| if (cmSessionId == null) {
| if(obj instanceof LoginDto) {
| UserInfoDto entity = findUser((LoginDto) obj);
| if (entity != null) {
| userId = entity.getId();
| }else {
| //TODO what to do...
| }
| }else {
| //TODO what to do...
| }
| }else {
| try {
| userId = (CurrentSessionData.getUserId(cmSessionId));
| } catch (ChannelManagerException e) {
| //TODO handle the exception here...
| e.printStackTrace();
| }
| }
|
| //acquires the lock
| lock.lock();
| try {
| if(contains(userId)) {
| final Condition inProcessTransaction = getLockForUserId(userId);
| while (contains(userId)) {
| try {
| //this releases the lock and causes the current thread to be waiting...
| inProcessTransaction.await(2000, TimeUnit.MILLISECONDS);
| } catch (InterruptedException e) {
| // It's OK
| }
| }
| addUserId(userId,inProcessTransaction);
| }else {
| addUserId(userId,lock.newCondition());
| }
| }finally {
| lock.unlock();
| }
|
| try {
| result = context.proceed();
| }catch (Throwable e) {
| //any throwable supposed to be caught to release the previous lock condition
| getLockForUserId(userId).signal();
| removeUserId(userId);
| throw e;
| }
|
| //notifying the condition to proceed the awaiting thread
| getLockForUserId(userId).signal();
| removeUserId(userId);
| return result;
| }
|
|
now, I am skeptical on the way this works. I just created this interceptor based on information gathering through the internet and not sure that works fine. Unfortunately, I can't create a situation in which we can test the system.
I have seen a CountDownLatch but I fear to use that because no knowledge I have about that.
I appreciate if you can help me on this or if you have any other idea on how to suspend other threads
thank you very much
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172732#4172732
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4172732
17 years, 7 months
[JBoss Portal] - custom sso :cas
by jsports
I have done cas sso with jboss portal successfully.
Now I want to use our userinfo database for Authenticate.
I write a new CASAuthenticationService implements AuthenticationService
instead of the CASAuthenticationService in the portal-identity-sso-lib.jar.
| public class CASAuthenticationService implements AuthenticationService{
| private final static Logger logger = Logger.getLogger(CASAuthenticationService.class);
| private String datasource = null;
| private String queryPasswordByUserNameSql = null;
|
|
| public String getQueryPasswordByUserNameSql() {
| return queryPasswordByUserNameSql;
| }
| public void setQueryPasswordByUserNameSql(String queryPasswordByUserNameSql) {
| this.queryPasswordByUserNameSql = queryPasswordByUserNameSql;
| }
|
|
|
| public String getDatasource() {
| return datasource;
| }
| public void setDatasource(String datasource) {
| this.datasource = datasource;
| }
| public void start(){
|
| }
| public void stop(){
|
| }
|
| @Override
| public boolean authenticate(String userName, String password) {
| logger.info("userName="+userName+",password="+password);
| Connection c = null;
| PreparedStatement ps = null;
| ResultSet rs = null;
| try {
| Context ctx = new InitialContext();
| DataSource ds = (DataSource) ctx.lookup(this.datasource);
| c = ds.getConnection();
| ps = c.prepareStatement(this.queryPasswordByUserNameSql);
| ps.setString(1, userName);
| rs = ps.executeQuery();
| if(rs!=null&&rs.next()){
| String tmpPassword = rs.getString(1);
| tmpPassword = EncryptHelper.dencrypt(tmpPassword);
| logger.info("password equals="+(password.equals(tmpPassword)));
| return password.equals(tmpPassword);
| }
| } catch (Exception e) {
| e.printStackTrace();
| logger.error(e);
| return false;
| }finally{
| try{
| if(rs!=null){
| rs.close();
| }
| if(ps!=null){
| ps.close();
| }
| if(!c.isClosed()){
| c.close();
| }
| }catch(Exception e){
| logger.error(e);
| }
| }
| return false;
| }
|
| }
|
| <mbean code="test.portal.identity.sso.cas.crm.CASAuthenticationService"
| name="portal:service=Module,type=CASAuthenticationService"
| xmbean-dd=""
| xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
| <xmbean/>
| <attribute name="Datasource">java:/jdbc/CRM</attribute>
| <attribute name="QueryPasswordByUserNameSql">select password from personinfo where userCode=?</attribute>
| </mbean>
|
I deploy the jar and start server.
It runs well.
and the CASAuthenticationService ruturn true after sign in,cas server gives a ticket too.
But portal still redirect to a portal login page.
I am wondering and puzled.
I need help.
thanks
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172729#4172729
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4172729
17 years, 7 months
Automatically rejected mail
by Mail Delivery Subsystem
Your message was automatically rejected by Dovecot Mail Delivery Agent.
The following reason was given:
Quota exceeded
17 years, 7 months
[JBoss Tools (users)] - Re: JBoss Tools 3.0.0.Alpha1 is released
by berenErchamion
Here's the details.
I have Eclipse 3.4 (latest build) running with JDK 1.6.0_05 in 1.5 compatibility mode. I have JBoss 4.2.3 with JBoss Portal 2.7B as the only other app running.
I have seam 2.1.0B1.
I installed the 3.0 tools to my eclipse using update manager, then restarted. Then I switch to the Seam perspective and do a new project, seam project, walk thru the stuff and pick off EAR as the deployment option. Finish out the wizard. The app deploys with no errors, but when I attempt to access it I get an error about a duplicate Seam PhaseListenter.
Here's the error:
22:07:37,546 ERROR [SeamPhaseListener] uncaught exception
java.lang.IllegalStateException: No phase id bound to current thread (make sure you do not have two SeamPhaseListener instances installed)
at org.jboss.seam.contexts.PageContext.getPhaseId(PageContext.java:162)
at org.jboss.seam.contexts.PageContext.isBeforeInvokeApplicationPhase(PageContext.java:174)
at org.jboss.seam.contexts.PageContext.getCurrentWritableMap(PageContext.java:90)
at org.jboss.seam.contexts.PageContext.set(PageContext.java:97)
at org.jboss.seam.Component.newInstance(Component.java:1977)
at org.jboss.seam.Component.getInstance(Component.java:1873)
at org.jboss.seam.Component.getInstance(Component.java:1852)
at org.jboss.seam.Component.getInstance(Component.java:1829)
at org.jboss.seam.Component.getInstance(Component.java:1824)
at org.jboss.seam.faces.FacesPage.instance(FacesPage.java:92)
at org.jboss.seam.core.ConversationPropagation.restorePageContextConversationId(ConversationPropagation.java:84)
at org.jboss.seam.core.ConversationPropagation.restoreConversationId(ConversationPropagation.java:57)
at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:389)
at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:228)
at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:194)
at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:104)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)
That's pretty much it. I do get a warning prior to my app getting deployed that I have duplicate listeners.
Tonight or tomorrow I'll blow away my entire config and try again from scratch.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172724#4172724
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4172724
17 years, 7 months