Announcement Announcement Module
Collapse
No announcement yet.
SimpleRemoteStatelessSessionProxyFactoryBean - Dynamic jndiEnvironment Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SimpleRemoteStatelessSessionProxyFactoryBean - Dynamic jndiEnvironment

    I am trying to use SimpleRemoteStatelessSessionProxyFactoryBean to access an EJB with security:

    Code:
    <bean id="AppQuery" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean" scope="prototype">
    		<property name="jndiName" value="BeanHome" />
    		<property name="businessInterface" value="some.interfaces.Query" />
    		<property name="jndiEnvironment">
    			<props>
    				<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
    				<prop key="java.naming.provider.url">t3://someserver:5100</prop>
    				<prop key="java.naming.security.principal">ticket</prop>
      				<prop key="java.naming.security.credentials"/>				
    			</props>
    		</property>
    	</bean>
    The problem for every transaction I have to set the ticket and connect to the EJB. The ticket value is dynamic and is based on the client that initiated the transaction. So I cannot have a fixed value/variable to source in the ticket.
    How do i set the ticket and connect on every call ?

  • #2
    I was able to make this work by subclassing SimpleRemoteStatelessSessionProxyFactoryBean and then programmatically creating the proxy.

    Code:
    public class SubProxy extends SimpleRemoteStatelessSessionProxyFactoryBean  {
    	public Object getObject(String ticket) throws NamingException {
    		Properties contextProperties = getJndiEnvironment();
    	        contextProperties.put( Context.SECURITY_PRINCIPAL, ticket);       
    		super.setJndiEnvironment(contextProperties);
    		super.afterPropertiesSet();
    		return super.getObject();
    	}
    }

    Create a proxy and use it:

    Code:
    SubProxy proxy = new SubProxy();
    proxy.setBusinessInterface(interfacename.class);
    proxy.setJndiName("QueryHome");
    Properties contextProperties = new Properties();
    contextProperties.put( Context.PROVIDER_URL, "t3://somehost:4100" );
    contextProperties.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
    contextProperties.put( Context.SECURITY_CREDENTIALS, "" );
    proxy.setJndiEnvironment(contextProperties);
    			
    Query q  = (Query) proxy.getObject(ticket);
    q.businesscall();

    Alternatively, if your parent bean is a prototype bean, you can create a prototype SubProxy bean and reference it in parent bean. This way parent bean will get a new instance of SubProxy bean for every call and then getObject(ticket) can be called.

    A helpful post: http://forum.springsource.org/showthread.php?p=55748

    Comment

    Working...
    X