kAmol
kAmol

Reputation: 1389

session-descriptor not working for sharing sessions with weblogic

I have localhost:8080/app1 (app1 is ear having 2 war projects and hence I added session descriptors to both weblogic.xml of war and weblogic-application.xml for ear) and want to access its session in localhost:8080/app2. app1 has authentication part so I want to access session of app1 in app2. Note app1 and app2 both are different ear.

weblogic.xml of one of the war file

<?xml version="1.0" encoding="UTF-8"?>
  <wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" 
    xmlns:bae="http://www.bea.com/ns/weblogic/90"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
<bae:session-descriptor>    
    <bae:persistent-store-type>memory</bae:persistent-store-type>
    <bae:sharing-enabled>true</bae:sharing-enabled>
</bae:session-descriptor> 

<wls:library-ref>
    <wls:library-name>jstl</wls:library-name>
    <wls:specification-version>1.2</wls:specification-version>
    <wls:exact-match>true</wls:exact-match>
</wls:library-ref>
</wls:weblogic-web-app>

And weblogic-application.xml at ear level is :

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application 
  xmlns:bae="http://www.bea.com/ns/weblogic/90"
  xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.5/weblogic-application.xsd">
<!--weblogic-version:12.1.3-->
<wls:application-param>
    <wls:param-name>webapp.encoding.default</wls:param-name>
    <wls:param-value>UTF-8</wls:param-value>
</wls:application-param>

<bae:session-descriptor>    
    <bae:persistent-store-type>memory</bae:persistent-store-type>
    <bae:sharing-enabled>true</bae:sharing-enabled>
</bae:session-descriptor>
</wls:weblogic-application>

in app2, I have a filter where I have added code

HttpSession session = ((HttpServletRequest) request).getSession(false);

And in this session object I also want to pass some custom attributes from app1 to app2.
I am new to weblogic configurations and not much aware of these in depth, tried these by reading This tutorial and this one and obviously StackOverflow .

Any guidence or help or suggestions will be much appriciated.

Upvotes: 1

Views: 924

Answers (1)

Rafael Guillen
Rafael Guillen

Reputation: 1673

If the applications are deployed in the same server, you could share the same session cookie name. You should use the same cookie name in both weblogic.xml war file deployment descriptors:

weblogic.xml

    <session-descriptor>
        <cookie-name>MY_COOKIE</cookie-name>
        <cookie-domain></cookie-domain>
        <cookie-path></cookie-path>
        <cookie-secure>false</cookie-secure>
        <url-rewriting-enabled>false</url-rewriting-enabled>
    </session-descriptor>

This means you can reuse authentication from app1 in app2 web applications if the client is using a browser.

I think sending information from app1 to app2 through the Session object is not possible, you can try with EJB or JMS, both supported by Weblogic.

Upvotes: 0

Related Questions