SSO on websphere losing session - session

I have the following setup a request comes in via a load balancer to a Websphere IHS server which forwards the request onto the application server also Websphere. The issue I am facing when SSO is enabled is that a new session is being created on every request.
I know this because I have written a snoop servlet and the session id is different on every request. The web server and the app server have been configured to work with cookies and the load balancer has sticky sessions enabled.
I am using spenego as it is websphere and kerberos config to validate user from Active Directory.
Does anyone have any idea/pointers as to why my session is created on every request only when SSO is enabled. Without SSO the session is the same for the different requests. I have tried a lot of different settings in websphere but none have worked. for example clustering at the server layer, enabling security checkbox in websphere session management etc..
I have also tried to create my own cookie and put this back into the response thinking it will come back in the request but as before no cookie is sent back. The JSessionID cookie is also not visible. Also when creating my own cookie as you can see in the logs it states that com.ibm.ws.webcontainer.srt.SRTServletResponse addCookie WARNING: Cannot set header. Response already committed.
If you need any more info please ask and I will be happy to provide
right the nitty gritty then:
I have the following code in my servlet to check the session info and creating my own cookie
//lets try setting a cookie into the response
System.out.println("Setting a new cookie into the session");
String user = "";
if(req.getAttribute("com.ibm.ws.security.spnego.UserPrincipal") != null) {
user = req.getAttribute("com.ibm.ws.security.spnego.UserPrincipal").toString();
Cookie userCookie = new Cookie("userId", user);
userCookie.setMaxAge(60*60*24*365); //Store cookie for 1 year
res.addCookie(userCookie);
}
HttpSession session = req.getSession(false);
if ( session != null )
{
out.println("<h2>Session information:</h2>");
out.println("<TABLE Border=\"2\" WIDTH=\"65%\" BGCOLOR=\"#DDDDFF\">");
print(out, "Session ID", session.getId());
print(out, "Last accessed time", new Date(session.getLastAccessedTime()).toString());
print(out, "Creation time", new Date(session.getCreationTime()).toString());
String mechanism = "unknown";
if ( req.isRequestedSessionIdFromCookie() )
{
mechanism = "cookie";
}
else if ( req.isRequestedSessionIdFromURL() )
{
mechanism = "url-encoding";
}
print(out, "Session-tracking mechanism", mechanism);
out.println("</table><BR><BR>");
Enumeration vals = session.getAttributeNames();
if (vals.hasMoreElements())
{
out.println("<h2>Session values</h2>");
out.println("<TABLE Border=\"2\" WIDTH=\"65%\" BGCOLOR=\"#DDDDFF\">");
while (vals.hasMoreElements())
{
String name = (String)vals.nextElement();
out.println("<tr><td>" + escapeChar(name) + "</td><td>" + escapeChar(session.getAttribute(name).toString()) + "</td></tr>");
}
out.println("</table><BR><BR>");
}
}
out.println("</body></html>");
}
And the following code to check the cookies in the request
Cookie[] cookies = req.getCookies();
if ( cookies != null && cookies.length > 0 )
{
out.println("<H2>Client cookies</H2>");
out.println("<TABLE Border=\"2\" WIDTH=\"65%\" BGCOLOR=\"#DDDDFF\">");
for ( int i=0; i<cookies.length; i++ )
{
out.println("<tr><td>" + escapeChar(cookies[i].getName()) + "</td><td>" + escapeChar(cookies[i].getValue()) + "</td></tr>");
}
out.println("</table><BR><BR>");
}
and the following checks the request attributes
e = req.getAttributeNames();
if ( e.hasMoreElements() )
{
out.println("<h2>Request attributes:</h2>");
out.println("<TABLE Border=\"2\" WIDTH=\"65%\" BGCOLOR=\"#DDDDFF\">");
while ( e.hasMoreElements() )
{
String name = (String)e.nextElement();
System.out.println("Reuqest Attribute Faisal**************" + name + "********" + req.getAttribute(name).toString());
if(req.getSession() != null) {
System.out.println("**************Session id = " + req.getSession().getId());
} else {
System.out.println("**************Session is null");
}
if(req.getAttribute("com.ibm.ws.security.spnego.UserPrincipal") != null) {
if(req.getSession(false) != null) {
System.out.println("****Got the old Session id Faisal = " + req.getSession().getId());
req.getSession().setAttribute("user.principal", req.getAttribute("com.ibm.ws.security.spnego.UserPrincipal"));
}
}
out.println("<tr><td>" + escapeChar(name) + "</td><td>" + escapeChar(req.getAttribute(name).toString()) + "</td></tr>");
}
out.println("</table><BR><BR>");
}
So the first time I send the request all of my session variables and request attributes are printed out the second time I send a request the user principal is not available and my logs are as follows
[6/18/14 9:33:17:445 BST] 0000002f SystemOut O Reuqest Attribute**************javax.servl
et.request.key_size********128
[6/18/14 9:33:17:445 BST] 0000002f WASSessionCor W SessionAffinityManager setCookie SESN0066E: The r
esponse is already committed to the client. The session cookie cannot be set.
[6/18/14 9:33:17:447 BST] 0000002f srt W com.ibm.ws.webcontainer.srt.SRTServletResponse ad
dSessionCookie WARNING: Cannot set session cookie. Response already committed.
[6/18/14 9:33:17:448 BST] 0000002f SystemOut O **************Session id = N0Lp9cftRNzWkjw
KUDheA1U
[6/18/14 9:33:17:448 BST] 0000002f SystemOut O ****Got the old Session id = N0Lp9cftRNzWk
jwKUDheA1U
[6/18/14 9:33:17:448 BST] 0000002f SystemOut O Reuqest Attribute**************javax.servl
et.request.cipher_suite********RC4-SHA
[6/18/14 9:33:17:449 BST] 0000002f SystemOut O **************Session id = N0Lp9cftRNzWkjw
KUDheA1U
[6/18/14 9:33:17:449 BST] 0000002f SystemOut O ****Got the old Session id= N0Lp9cftRNzWk
jwKUDheA1U
[6/18/14 9:33:17:449 BST] 0000002f SystemOut O Reuqest Attribute**************com.ibm.ws.
security.spnego.UserPrincipal********user#domain.COM
[6/18/14 9:33:17:449 BST] 0000002f SystemOut O **************Session id = N0Lp9cftRNzWkjw
KUDheA1U
[6/18/14 9:33:17:449 BST] 0000002f SystemOut O ****Got the old Session id = N0Lp9cftRNzWk
jwKUDheA1U
[6/18/14 9:33:17:449 BST] 0000002f SystemOut O Reuqest Attribute**************com.ibm.web
sphere.servlet.uri_non_decoded********/lbgssoclient/snoop/
[6/18/14 9:33:17:449 BST] 0000002f SystemOut O **************Session id = N0Lp9cftRNzWkjw
KUDheA1U
[6/18/14 9:33:17:450 BST] 0000002f SystemOut O ****Got the old Session id= N0Lp9cftRNzWk
jwKUDheA1U
[6/18/14 9:33:17:452 BST] 0000002f SystemOut O Setting a new cookie into the session
[6/18/14 9:33:17:452 BST] 0000002f srt W com.ibm.ws.webcontainer.srt.SRTServletResponse ad
dCookie WARNING: Cannot set header. Response already committed.
[6/18/14 9:35:01:745 BST] 0000002e SystemOut O Reuqest Attribute**************javax.servl
et.request.key_size********128
[6/18/14 9:35:01:746 BST] 0000002e WASSessionCor W SessionAffinityManager setCookie SESN0066E: The r
esponse is already committed to the client. The session cookie cannot be set.
[6/18/14 9:35:01:747 BST] 0000002e srt W com.ibm.ws.webcontainer.srt.SRTServletResponse ad
dSessionCookie WARNING: Cannot set session cookie. Response already committed.
[6/18/14 9:35:01:749 BST] 0000002e SystemOut O **************Session id = ChRGK9SP4lEnGc2
yy7WQdGb
[6/18/14 9:35:01:750 BST] 0000002e SystemOut O Reuqest Attribute**************javax.servl
et.request.cipher_suite********RC4-SHA
[6/18/14 9:35:01:750 BST] 0000002e SystemOut O **************Session id = ChRGK9SP4lEnGc2
yy7WQdGb
[6/18/14 9:35:01:750 BST] 0000002e SystemOut O Reuqest Attribute**************com.ibm.web
sphere.servlet.uri_non_decoded********/lbgssoclient/snoop/
[6/18/14 9:35:01:750 BST] 0000002e SystemOut O **************Session id Faisal = ChRGK9SP4lEnGc2
yy7WQdGb
[6/18/14 9:35:01:752 BST] 0000002e SystemOut O Setting a new cookie into the session
Any advice or pointers are appreciated. i know there is a lot of info here but am really struggling with this.
Thanks
UPDATE:
After adding a session listner to monitor the session I noticed the following in the logs
[6/18/14 12:45:40:880 BST] 00000025 ServerCache I DYNA1071I: The cache provider "default" is being used.
[6/18/14 12:45:40:937 BST] 00000025 SystemOut O getting session for attributes print out
[6/18/14 12:45:40:938 BST] 00000025 SystemOut O Reuqest Attribute **************javax.servlet.request.key_size********128
[6/18/14 12:45:40:941 BST] 00000025 SystemOut O sessioncreated
[6/18/14 12:45:40:941 BST] 00000025 SystemOut O 1403091940939
[6/18/14 12:45:40:942 BST] 00000025 SystemOut O oN74OFyuPHcnyoxO_YBLK7z
[6/18/14 12:45:40:942 BST] 00000025 SystemOut O 1403091940939
[6/18/14 12:45:40:943 BST] 00000025 SystemOut O 1800
[6/18/14 12:45:40:943 BST] 00000025 SystemOut O sessionCreated - add one session into counter
[6/18/14 12:45:40:944 BST] 00000025 WASSessionCor W SessionAffinityManager setCookie SESN0066E: The response is already committed to the client. The session cookie cannot be set.
[6/18/14 12:45:40:945 BST] 00000025 srt W com.ibm.ws.webcontainer.srt.SRTServletResponse addSessionCookie WARNING: Cannot set session cookie
. Response already committed.
the last few lines state cannot set the session cookie because the response is already committed. Anyone know how to resolve this ?

Related

Log4j2, IBM WAS spring project. Not able to see the logs on the console

While migrating from log 1.x to log2.17.1. I am facing issue in printing of the logs over the console.
I changed my web app version from 2.4 to 3.0 and remove all the other config for log4j 1.x. I kept only the new config:-
<context-param>
<param-name>log4jContextName</param-name>
<param-value>myApplication</param-value>
</context-param>
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>/WEB-INF/config/log4j2.xml</param-value>
</context-param>
in the web.xml
I am using slf4j methods and classes in the code. I kept all the necessary jars related to the the slf4j and log4j in pom.xml.
Application started with below messages while initialisation of the log. But after that no logs from the application in console.
Application startup logs:-
[1/3/22 9:53:22:314 MST] 000000ec SystemOut O WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
[1/3/22 9:53:22:315 MST] 000000ec SystemOut O WARN: Please see http://www.slf4j.org/codes.html#release for an explanation.
[1/3/22 9:53:23:581 MST] 000000ec CompositionUn A WSVR0193I: Composition unit WebSphere:cuname=my-application in BLA WebSphere:blaname=my-application stopped.
[1/3/22 9:53:25:277 MST] 000000ec AdminHelper A ADMN1008I: An attempt is made to start the my-application application. (User ID = defaultWIMFileBasedRealm/server:server1212Cell_server1212Node_server1212sbs1Server)
[1/3/22 9:53:25:291 MST] 000000ec CompositionUn A WSVR0190I: Starting composition unit WebSphere:cuname=my-application in BLA WebSphere:blaname=my-application.
[1/3/22 9:53:25:318 MST] 000000ec ApplicationMg A WSVR0200I: Starting application: my-application
[1/3/22 9:53:25:318 MST] 000000ec ApplicationMg A WSVR0204I: Application: my-application Application build level: Unknown
[1/3/22 9:53:28:830 MST] 000000ec webapp I com.ibm.ws.webcontainer.webapp.WebGroupImpl WebGroup SRVE0169I: Loading Web Module: vr-cornerstone.
[1/3/22 9:53:28:893 MST] 000000ec WASSessionCor I SessionContextRegistry getSessionContext SESN0176I: Will create a new session context for application key vhost_sbs1/voice/cornerstone
[1/3/22 9:53:28:894 MST] 000000ec WASSession I MTMStore setDRSMode SESN0188I: Memory To Memory mode for application vhost_sbs1/voice/cornerstone is BOTH
[1/3/22 9:53:28:894 MST] 000000ec WASSession I MTMStore setDRSMode SESN0188I: Memory To Memory mode for application vhost_sbs1my-application is BOTH
[1/3/22 9:53:31:001 MST] 000000ec SystemOut O 2022-01-03 09:53:31,000 Default : 2 DEBUG Starting LoggerContext[name=myApplication] from configuration at file:/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml
[1/3/22 9:53:31:002 MST] 000000ec SystemOut O 2022-01-03 09:53:31,002 Default : 2 DEBUG Starting LoggerContext[name=myApplication, org.apache.logging.log4j.core.LoggerContext#10e67293] with configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml]...
[1/3/22 9:53:31:003 MST] 000000ec SystemOut O 2022-01-03 09:53:31,003 Default : 2 DEBUG Shutdown hook enabled. Registering a new one.
[1/3/22 9:53:31:005 MST] 000000ec SystemOut O 2022-01-03 09:53:31,005 Default : 2 DEBUG Apache Log4j Core 2.17.1 initializing configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml]
[1/3/22 9:53:31:243 MST] 000000ec SystemOut O 2022-01-03 09:53:31,243 Default : 2 DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout].
[1/3/22 9:53:31:251 MST] 000000ec SystemOut O 2022-01-03 09:53:31,251 Default : 2 DEBUG PluginManager 'TypeConverter' found 26 plugins
[1/3/22 9:53:31:259 MST] 000000ec SystemOut O 2022-01-03 09:53:31,259 Default : 2 DEBUG PatternLayout$Builder(pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", PatternSelector=null, Configuration(/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml), Replace=null, charset="null", alwaysWriteExceptions="null", disableAnsi="null", noConsoleNoAnsi="null", header="null", footer="null")
[1/3/22 9:53:31:260 MST] 000000ec SystemOut O 2022-01-03 09:53:31,260 Default : 2 DEBUG PluginManager 'Converter' found 45 plugins
[1/3/22 9:53:31:261 MST] 000000ec SystemOut O 2022-01-03 09:53:31,261 Default : 2 DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender].
[1/3/22 9:53:31:269 MST] 000000ec SystemOut O 2022-01-03 09:53:31,269 Default : 2 DEBUG ConsoleAppender$Builder(target="SYSTEM_OUT", follow="null", direct="null", bufferedIo="null", bufferSize="null", immediateFlush="null", ignoreExceptions="null", PatternLayout(%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n), name="Console", Configuration(/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml), Filter=null, ={})
[1/3/22 9:53:31:272 MST] 000000ec SystemOut O 2022-01-03 09:53:31,272 Default : 2 DEBUG Starting OutputStreamManager SYSTEM_OUT.false.false
[1/3/22 9:53:31:272 MST] 000000ec SystemOut O 2022-01-03 09:53:31,272 Default : 2 DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin].
[1/3/22 9:53:31:273 MST] 000000ec SystemOut O 2022-01-03 09:53:31,273 Default : 2 DEBUG createAppenders(={Console})
[1/3/22 9:53:31:273 MST] 000000ec SystemOut O 2022-01-03 09:53:31,273 Default : 2 DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
[1/3/22 9:53:31:276 MST] 000000ec SystemOut O 2022-01-03 09:53:31,276 Default : 2 DEBUG createAppenderRef(ref="Console", level="null", Filter=null)
[1/3/22 9:53:31:276 MST] 000000ec SystemOut O 2022-01-03 09:53:31,276 Default : 2 DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
[1/3/22 9:53:31:277 MST] 000000ec SystemOut O 2022-01-03 09:53:31,277 Default : 2 DEBUG createLogger(additivity="null", level="DEBUG", includeLocation="null", ={Console}, ={}, Configuration(/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml), Filter=null)
[1/3/22 9:53:31:280 MST] 000000ec SystemOut O 2022-01-03 09:53:31,280 Default : 2 DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
[1/3/22 9:53:31:281 MST] 000000ec SystemOut O 2022-01-03 09:53:31,281 Default : 2 DEBUG createLoggers(={root})
[1/3/22 9:53:31:282 MST] 000000ec SystemOut O 2022-01-03 09:53:31,282 Default : 2 DEBUG Configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml] initialized
[1/3/22 9:53:31:282 MST] 000000ec SystemOut O 2022-01-03 09:53:31,282 Default : 2 DEBUG Starting configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml]
[1/3/22 9:53:31:283 MST] 000000ec SystemOut O 2022-01-03 09:53:31,283 Default : 2 DEBUG Started configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml] OK.
[1/3/22 9:53:31:283 MST] 000000ec SystemOut O 2022-01-03 09:53:31,283 Default : 2 DEBUG Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
[1/3/22 9:53:31:284 MST] 000000ec SystemOut O 2022-01-03 09:53:31,284 Default : 2 DEBUG OutputStream closed
[1/3/22 9:53:31:284 MST] 000000ec SystemOut O 2022-01-03 09:53:31,284 Default : 2 DEBUG Shut down OutputStreamManager SYSTEM_OUT.false.false-1, all resources released: true
[1/3/22 9:53:31:285 MST] 000000ec SystemOut O 2022-01-03 09:53:31,284 Default : 2 DEBUG Appender DefaultConsole-1 stopped with status true
[1/3/22 9:53:31:285 MST] 000000ec SystemOut O 2022-01-03 09:53:31,285 Default : 2 DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration#14d1de6e OK
[1/3/22 9:53:31:288 MST] 000000ec SystemOut O 2022-01-03 09:53:31,288 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication
[1/3/22 9:53:31:291 MST] 000000ec SystemOut O 2022-01-03 09:53:31,291 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication,component=StatusLogger
[1/3/22 9:53:31:292 MST] 000000ec SystemOut O 2022-01-03 09:53:31,292 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication,component=ContextSelector
[1/3/22 9:53:31:294 MST] 000000ec SystemOut O 2022-01-03 09:53:31,294 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication,component=Loggers,name=
[1/3/22 9:53:31:296 MST] 000000ec SystemOut O 2022-01-03 09:53:31,296 Default : 2 DEBUG Registering MBean org.apache.logging.log4j2:type=myApplication,component=Appenders,name=Console
[1/3/22 9:53:31:299 MST] 000000ec SystemOut O 2022-01-03 09:53:31,299 Default : 2 DEBUG org.apache.logging.log4j.core.util.SystemClock does not support precise timestamps.
[1/3/22 9:53:31:300 MST] 000000ec SystemOut O 2022-01-03 09:53:31,300 Default : 2 DEBUG LoggerContext[name=myApplication, org.apache.logging.log4j.core.LoggerContext#10e67293] started OK with configuration XmlConfiguration[location=/my-application.ear/my-application-service.war/WEB-INF/config/log4j2.xml].
[1/3/22 9:53:31:301 MST] 000000ec webapp I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [my-application#my-application-service.war]:.No Spring WebApplicationInitializer types detected on classpath
[1/3/22 9:53:31:308 MST] 000000ec SystemOut O 2022-01-03 09:53:31,308 Default : 2 DEBUG Log4jServletContextListener ensuring that Log4j starts up properly.
[1/3/22 9:53:31:316 MST] 000000ec webapp I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [my-application#my-application-service.war]:.Initializing Spring root WebApplicationContext
[1/3/22 9:53:32:011 MST] 000000ec webapp I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [my-application#my-application-service.war]:.Initializing Spring FrameworkServlet 'rest'
[1/3/22 9:53:33:235 MST] 000000ec ServletWrappe I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [my-application] [/voice/cornerstone] [rest]: Initialization successful.
[1/3/22 9:53:33:261 MST] 000000ec ApplicationMg A WSVR0221I: Application started: my-application
[1/3/22 9:53:33:261 MST] 000000ec CompositionUn A WSVR0191I: Composition unit WebSphere:cuname=my-application in BLA WebSphere:blaname=my-application started.
[1/3/22 9:53:45:967 MST] 000001d9 SystemOut O 2022-01-03 09:53:45,967 WebContainer : 2 DEBUG Log4jServletFilter initialized.
Log4j2.xml file:-
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="com.myapp" level="debug">
<AppenderRef ref="Console"/>
</Logger>
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
Please let me what I am doing wrong here.
Pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version> </dependency> <dependency> <groupId>log4j</groupId>
<artifactId>log4j</artifactId> <version>1.2.16</version> </dependency> -->
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-web -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.17.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>

Websphere Application Server 7 Datasource test connection error

I am trying to connect data source with correct username and password in Websphere application server 7. I am getting following error:
[10/17/16 12:34:18:510 EDT] 00041199 DSConfigurati W DSRA8200W: DataSource Configuration: DSRA8020E: Warning: The property 'metaDataSource' does not exist on the DataSource class com.ibm.as400.access.AS400JDBCConnectionPoolDataSource.
[10/17/16 12:34:18:635 EDT] 00041199 DSConfigurati W DSRA8200W: DataSource Configuration: DSRA8020E: Warning: The property 'translateBoolean' does not exist on the DataSource class com.ibm.as400.access.AS400JDBCConnectionPoolDataSource.
[10/17/16 12:34:18:932 EDT] 00041199 DSConfigurati I DSRA8203I: Database product name : DB2 UDB for AS/400
[10/17/16 12:34:18:948 EDT] 00041199 DSConfigurati I DSRA8204I: Database product version : 07.01.0000 V7R1m0
[10/17/16 12:34:18:948 EDT] 00041199 DSConfigurati I DSRA8205I: JDBC driver name : AS/400 Toolbox for Java JDBC Driver
[10/17/16 12:34:18:948 EDT] 00041199 DSConfigurati I DSRA8206I: JDBC driver version : 7.0
[10/17/16 12:34:19:010 EDT] 000411a4 access E Mon Oct 17 12:34:18 EDT 2016 run(): Caught IOException:
java.net.SocketException: socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:140)
at com.ibm.as400.access.DataStream.readFromStream(DataStream.java:48)
at com.ibm.as400.access.ClientAccessDataStream.construct(ClientAccessDataStream.java:46)
at com.ibm.as400.access.AS400ThreadedServer.run(AS400ThreadedServer.java:321)
at java.lang.Thread.run(Thread.java:761)
[10/17/16 12:34:19:104 EDT] 00041199 DSConfigurati I DSRA8030I: Successfully connected to DataSource, with 2 warnings.
Can anyone tell why it is coming like this. Because I have searched lot of times in internet there is no exact match of answers for this error.

Websphere 7 javax.mail.MessagingException: SSLSocketFactory is null

I am trying to connect to mail server using SSL, running on Websphere 7. I have no problem running the code as a standalone test main method, everything goes fine.
I have also no problem running the code on Websphere - connecting to mail server (example imap.seznam.cz), but when I do not use SSL. In case I want to use SSL, exception is thrown like this:
javax.mail.MessagingException: SSLSocketFactory is null. This can occur if javax.net.ssl.SSLSocketFactory.getDefault() is called to
create a socket and javax.net.ssl.* properties are not set.; nested
exception is:
javax.net.ssl.SSLException: SSLSocketFactory is null. This can occur if javax.net.ssl.SSLSocketFactory.getDefault() is called to create a
socket and javax.net.ssl.* properties are not set.
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:571)
at javax.mail.Service.connect(Service.java:288)
Here is a part of a code:
Properties imapProps = new Properties();
System.out.println(imapProps);
imapProps.setProperty("mail.imap.ssl.enable", ssl ? "true" : "false");
if(ssl) {
imapProps.setProperty("mail.imap.starttls.enable", "true");
}
imapProps.setProperty("javax.net.ssl.trustStore", "c:/Program Files/IBM/WebSphere/AppServer/profiles/AppSrv01/config/cells/T431sNode03Cell/nodes/T431sNode03/trust.p12");
imapProps.setProperty("javax.net.ssl.trustStorePassword", "WebAS");
imapProps.setProperty("javax.net.ssl.trustStoreType", "PKCS12");
imapProps.setProperty("javax.net.ssl.keyStore", "c:/Program Files/IBM/WebSphere/AppServer/profiles/AppSrv01/config/cells/T431sNode03Cell/nodes/T431sNode03/key.p12");
imapProps.setProperty("javax.net.ssl.keyStorePassword", "WebAS");
imapProps.setProperty("mail.debug", "true");
Session session = Session.getInstance(imapProps, null);
session.setDebug(true);
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println(imapProps.toString());
System.out.println("--------------------------------------------------------------------------------------------");
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
System.out.println(sslsocketfactory);
// connect
try {
store = session.getStore(ssl ? "imaps" : "imap");
store.connect(imapServer, imapPort, login, password);
return true;
} catch(NoSuchProviderException ex) {
ex.printStackTrace();
return false;
} catch (MessagingException e) {
e.printStackTrace();
return false;
}
Parameters are taken from properties file...
ssl true, imapServer imap.seznam.cz, imapPort 993
This is only to check whether SSLSocketFactory is null or not, not needed in code
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
System.out.println(sslsocketfactory);
I can see that sslsocketfactory is not null ans is of type: com.ibm.websphere.ssl.protocol.SSLSocketFactory
What I tried is:
I have certificate from mail server stored in trusted store on Websphere (using admin console, read from server's port, I can see it there)
I set up some javax.net.ssl.* properties on a Websphere server's properties and also in a code as you can see - but I do not think it it necessary
I assume Websphere is reading certificates from trust store location as seen in admin console: ${CONFIG_ROOT}/cells/T431sNode03Cell/nodes/T431sNode03/trust.p12
Can any Websphere expert help me with this problem? I am trying to fix it a couple of days with no success :-(
As I mentioned, it is working on Websphere when not using SSL, but not running when using SSL for the same mail server (for example imap.seznam.cz, also imap.gmail.com) and it is working fine with SSL when running outside Websphere as a standalone java apllication.
Thank you all, guys!
UPDATE:
Thanks Gas to pointing me to the right way how to configure mail in Websphere. So I did it, I am using Built-in Mail Provider and only created 2 mail sessions
one with SSL support using "imaps" provider
the other one without SSL support using "imap" provider
Both sessions have the same server defined and debug enabled.
In java code I am doing this:
Context context = new InitialContext();
Session session = null;
if(ssl) {
session = (Session) context.lookup("mail/exchangeSSL");
} else {
session = (Session) context.lookup("mail/exchange");
}
store = session.getStore();
store.connect(login, password);
And interesting think, the result is exactly the same. When I am using non SSL session, everything goes fine, but when I use SSL session, got this exception:
[25.6.14 16:35:19:615 SELČ] 00000023 SystemOut O *** In SessionFactory.getObjectInstance, session properties:
[25.6.14 16:35:19:615 SELČ] 00000023 SystemOut O mail.store.protocol=imaps
[25.6.14 16:35:19:615 SELČ] 00000023 SystemOut O mail.imaps.class=com.sun.mail.imap.IMAPSSLStore
[25.6.14 16:35:19:615 SELČ] 00000023 SystemOut O mail.debug=true
[25.6.14 16:35:19:615 SELČ] 00000023 SystemOut O mail.pop3s.class=com.sun.mail.pop3.POP3SSLStore
[25.6.14 16:35:19:615 SELČ] 00000023 SystemOut O mail.smtp.class=com.sun.mail.smtp.SMTPTransport
[25.6.14 16:35:19:615 SELČ] 00000023 SystemOut O mail.imaps.host=imap.seznam.cz
[25.6.14 16:35:19:616 SELČ] 00000023 SystemOut O mail.smtps.class=com.sun.mail.smtp.SMTPSSLTransport
[25.6.14 16:35:19:616 SELČ] 00000023 SystemOut O mail.imap.class=com.sun.mail.imap.IMAPStore
[25.6.14 16:35:19:616 SELČ] 00000023 SystemOut O mail.mime.address.strict=false
[25.6.14 16:35:19:616 SELČ] 00000023 SystemOut O mail.pop3.class=com.sun.mail.pop3.POP3Store
[25.6.14 16:35:19:616 SELČ] 00000023 SystemOut O DEBUG: mail.imaps.class property exists and points to com.sun.mail.imap.IMAPSSLStore
[25.6.14 16:35:19:617 SELČ] 00000023 SystemOut O DEBUG: mail.imap.fetchsize: 16384
[25.6.14 16:35:19:618 SELČ] 00000023 SystemErr R javax.mail.MessagingException: SSLSocketFactory is null. This can occur if javax.net.ssl.SSLSocketFactory.getDefault() is called to create a socket and javax.net.ssl.* properties are not set.;
nested exception is:
javax.net.ssl.SSLException: SSLSocketFactory is null. This can occur if javax.net.ssl.SSLSocketFactory.getDefault() is called to create a socket and javax.net.ssl.* properties are not set.
[25.6.14 16:35:19:618 SELČ] 00000023 SystemErr R at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:479)
[25.6.14 16:35:19:618 SELČ] 00000023 SystemErr R at javax.mail.Service.connect(Service.java:275)
UPDATE2:
I created a new fresh project from this example:
http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
I only added mail session related code to the controller:
try {
Context context = new InitialContext();
Session session = (Session) context.lookup("mail/exchangeSSL");
Store store = session.getStore();
store.connect("<user>", "<password>");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchProviderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
And when I deploy this new web app and invoke it, the same error. In WEB-INF/lib there are only jars related to spring and commons logging:
aopalliance-1.0.jar
commons-logging-1.1.1.jar
spring-aop-3.0.5.RELEASE.jar
spring-asm-3.0.5.RELEASE.jar
spring-beans-3.0.5.RELEASE.jar
spring-context-3.0.5.RELEASE.jar
spring-context-support-3.0.5.RELEASE.jar
spring-core-3.0.5.RELEASE.jar
spring-expression-3.0.5.RELEASE.jar
spring-web-3.0.5.RELEASE.jar
spring-webmvc-3.0.5.RELEASE.jar
So I think this has something to do with server settings? I use Websphere 7.0.0.31. I added mail server certificate to NodeDefaultTrustStore in admin console (read from port) and I can see it there.
And here is the listing of jars we are using in our project:
ant-1.7.1.jar
ant-launcher-1.7.1.jar
antlr-2.7.7.jar
aopalliance-1.0.jar
asm-3.3.1.jar
aspectjrt-1.7.4.jar
aspectjweaver-1.7.4.jar
avalon-framework-api-4.3.1.jar
avalon-framework-impl-4.2.0.jar
avalon-framework-impl-4.3.1.jar
barcode4j-2.1.jar
batik-anim-1.7.jar
batik-awt-util-1.7.jar
batik-bridge-1.7.jar
batik-css-1.7.jar
batik-dom-1.7.jar
batik-ext-1.7.jar
batik-extension-1.7.jar
batik-gvt-1.7.jar
batik-js-1.7.jar
batik-parser-1.7.jar
batik-script-1.7.jar
batik-svg-dom-1.7.jar
batik-svggen-1.7.jar
batik-transcoder-1.7.jar
batik-util-1.7.jar
batik-xml-1.7.jar
bcmail-jdk16-1.45.jar
bcprov-jdk16-1.45.jar
bctsp-jdk16-1.45.jar
bsh-2.0b4.jar
c3p0-0.9.1.1.jar
cglib-2.2.2.jar
commons-beanutils-1.9.1.jar
commons-cli-1.0.jar
commons-codec-1.9.jar
commons-collections-3.2.1.jar
commons-io-1.4.jar
commons-lang-2.6.jar
commons-logging-1.1.3.jar
core-1.0-SNAPSHOT.jar
core-interface-1.0-SNAPSHOT.jar
cxf-api-2.7.5.jar
cxf-rt-bindings-soap-2.7.5.jar
cxf-rt-core-2.7.5.jar
cxf-rt-databinding-jaxb-2.7.5.jar
cxf-rt-frontend-jaxws-2.7.5.jar
cxf-rt-frontend-simple-2.7.5.jar
cxf-rt-transports-http-2.7.5.jar
cxf-rt-ws-security-2.7.5.jar
cz.dalvi.commons.common-0.1.jar
cz.dalvi.commons.crypto-0.1.jar
cz.dalvi.commons.xml-0.1.jar
dom4j-1.6.1.jar
ehcache-core-2.5.1.jar
filenet-client-1.0-SNAPSHOT.jar
flexjson-2.0.jar
fontbox-1.8.5.jar
fop-1.1.jar
hibernate-commons-annotations-4.0.4.Final.jar
hibernate-core-4.3.5.Final.jar
hibernate-entitymanager-4.3.5.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
iba-commons-core-1.5.jar
iba-commons-util-1.5.jar
ibm.filenet-stax-api-1.0.jar
ini4j-0.5.1.jar
ISDSClient-1.0-SNAPSHOT.jar
isds-client-1.0-SNAPSHOT.jar
Jace-1.0.jar
jackson-annotations-2.0.5.jar
jackson-core-2.0.5.jar
jackson-databind-2.0.5.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
javax.xml.stream-stax-api-1.0.jar
jaxb-api-2.1.jar
jaxb-impl-2.1.11.jar
jaxws-api-2.1.jar
jaxws-rt-2.1.7.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
jcl-over-slf4j-1.7.1.jar
jcommander-1.27.jar
jempbox-1.8.5.jar
joda-time-2.3.jar
jstl-1.2.jar
log4j-1.2.17.jar
mimepull-1.3.jar
mimepull-1.7.jar
opensaml-2.5.1-1.jar
openws-1.4.2-1.jar
pdfbox-1.8.5.jar
quartz-2.2.1.jar
resolver-20050927.jar
saaj-impl-1.3.18.jar
slf4j-api-1.7.1.jar
slf4j-log4j12-1.7.6.jar
spring-aop-4.0.3.RELEASE.jar
spring-beans-4.0.3.RELEASE.jar
spring-context-4.0.3.RELEASE.jar
spring-context-support-4.0.3.RELEASE.jar
spring-core-4.0.3.RELEASE.jar
spring-expression-4.0.3.RELEASE.jar
spring-jdbc-4.0.3.RELEASE.jar
spring-ldap-core-1.3.2.RELEASE.jar
spring-orm-4.0.3.RELEASE.jar
spring-security-config-3.2.4.RELEASE.jar
spring-security-core-3.2.4.RELEASE.jar
spring-security-ldap-3.2.4.RELEASE.jar
spring-security-web-3.2.4.RELEASE.jar
spring-tx-4.0.3.RELEASE.jar
spring-web-4.0.3.RELEASE.jar
spring-webmvc-4.0.3.RELEASE.jar
sta-client-1.0-SNAPSHOT.jar
stax2-api-3.1.1.jar
stax-api-1.0.1.jar
stax-ex-1.2.jar
streambuffer-0.9.jar
testng-6.8.8.jar
usertype.core-3.1.0.GA.jar
usertype.spi-3.1.0.GA.jar
velocity-1.7.jar
woodstox-core-asl-4.2.0.jar
ws-api-1.0-SNAPSHOT.jar
wsdl4j-1.6.3.jar
wss4j-1.6.10.jar
wstx-asl-3.2.3.jar
xalan-2.6.0.jar
xercesImpl-2.11.0.jar
xlxpScanner-1.0.jar
xlxpScannerUtils-1.0.jar
xml-apis-1.4.01.jar
xml-apis-ext-1.3.04.jar
xmlgraphics-commons-1.5.jar
xmlsec-1.5.4.jar
xmlschema-core-2.0.3.jar
xmltooling-1.3.2-1.jar
xpp3_min-1.1.4c.jar
xstream-1.3.1.jar
I think this could also be helpful, from java.security setting on my WAS:
# Default JSSE socket factories
#ssl.SocketFactory.provider=com.ibm.jsse2.SSLSocketFactoryImpl
#ssl.ServerSocketFactory.provider=com.ibm.jsse2.SSLServerSocketFactoryImpl
# WebSphere socket factories (in cryptosf.jar)
ssl.SocketFactory.provider=com.ibm.websphere.ssl.protocol.SSLSocketFactory
ssl.ServerSocketFactory.provider=com.ibm.websphere.ssl.protocol.SSLServerSocketFactory
This is not the correct way using mail sessions in the application server environment.
You should define your mail session via Resources > Mail, specify all required properties there and select whether you want to use SSL (imaps). In your application you should get the mail session via JNDI or annotations, not using getInstance().
You will need to add SSL certificate from your mail server to the NodeDeafaultTrustStore.
In general , in WebSphere, you should avoid changing any javax.net.ssl system properties.
Answer Update
Marek here is my test code (fragment). I'm able to successfully connect (I'm using WAS v8.5.5). Look at log below.
Do you have any additional jars in your application? Please remove any third party jars like mail.jar, activation.jar etc...
public class IMapTest extends HttpServlet {
private static final long serialVersionUID = 1L;
#Resource(name="mail", lookup="mail/test")
Session mailSession;
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
System.out.println("Accessing session");
try {
Store store = mailSession.getStore();
System.out.println("gotStore");
store.connect("user", "pass");
System.out.println("connected!");
} catch (NoSuchProviderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Log (fragmet):
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O DEBUG: JavaMail version 1.4.2
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O DEBUG: Tables of loaded providers
...
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O *** In SessionFactory.getObjectInstance, session properties:
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.store.protocol=imaps
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.imaps.class=com.sun.mail.imap.IMAPSSLStore
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.debug=true
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.pop3s.class=com.sun.mail.pop3.POP3SSLStore
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.smtp.class=com.sun.mail.smtp.SMTPTransport
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.imaps.host=imap.gmail.com
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.smtps.class=com.sun.mail.smtp.SMTPSSLTransport
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.imap.class=com.sun.mail.imap.IMAPStore
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.mime.address.strict=true
[6/25/14 22:25:26:615 CEST] 0000007e SystemOut O mail.pop3.class=com.sun.mail.pop3.POP3Store
[6/25/14 22:25:26:630 CEST] 0000007e ServletWrappe I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [servlet.IMapTest]: Initialization successful.
[6/25/14 22:25:26:630 CEST] 0000007e SystemOut O Accessing session
[6/25/14 22:25:26:630 CEST] 0000007e SystemOut O DEBUG: mail.imaps.class property exists and points to com.sun.mail.imap.IMAPSSLStore
[6/25/14 22:25:26:646 CEST] 0000007e SystemOut O DEBUG: mail.imap.fetchsize: 16384
[6/25/14 22:25:26:646 CEST] 0000007e SystemOut O DEBUG: mail.imap.statuscachetimeout: 1000
[6/25/14 22:25:26:646 CEST] 0000007e SystemOut O DEBUG: mail.imap.appendbuffersize: -1
[6/25/14 22:25:26:646 CEST] 0000007e SystemOut O DEBUG: mail.imap.minidletime: 10
[6/25/14 22:25:26:646 CEST] 0000007e SystemOut O gotStore
[6/25/14 22:25:26:646 CEST] 0000007e SystemOut O **DEBUG: trying to connect to host "imap.gmail.com", port 993, isSSL true**
[6/25/14 22:25:27:380 CEST] 0000007e SystemOut O * OK Gimap ready for requests from
...
[6/25/14 22:25:27:474 CEST] 0000007e SystemOut O DEBUG: protocolConnect login, host=imap.gmail.com, user=uuuu, password=pass
[6/25/14 22:25:28:599 CEST] 0000007e SystemOut O connected!
The javax.net.ssl.* properties need to be set as System properties, not JavaMail Session properties. Although I would hope that if they weren't set at all some reasonable defaults would be used.

batch admin console - DispatcherServlet using InternalResourceViewResolver instead of FreeMarkerViewResolver

I have an issue with integrating the spring batch admin console into my application.
The good news is that when i go to http://mymachine.com:8080/ReportingManager/batch/configuration I can get to the admin console.
But when I go to http://mymachine.com:8080/ReportingManager/batch/job-configuration i get a 404 and an error saying that /batch/jobs can't be found.
I've just gone through the exercise of comparing the difference in output of org.springframework.web logs between my application logs and the spring-batch-admin-sample application which I know is working.
After looking at the logs it looks like the URL mappings can be found for the spring batch admin console but the DispatcherServlet is trying to use InternalResourceViewResolver instead of the FreeMarkerViewResolver
My application logs below show the wrong ViewResolver is being used for /ReportingManager/batch/jobs...
2014-05-27 20:16:22,770 DEBUG [DispatcherServlet] - DispatcherServlet with name 'Batch Servlet' processing GET request for [/ReportingManager/batch/jobs]
2014-05-27 20:16:22,770 DEBUG [RequestMappingHandlerMapping] - Looking up handler method for path /jobs
2014-05-27 20:16:22,770 DEBUG [RequestMappingHandlerMapping] - Returning handler method [public void org.springframework.batch.admin.web.JobController.jobs(org.springframework.ui.ModelMap,int,int)]
2014-05-27 20:16:22,770 DEBUG [DispatcherServlet] - Last-Modified value for [/ReportingManager/batch/jobs] is: -1
2014-05-27 20:16:23,598 DEBUG [DispatcherServlet] - Rendering view [org.springframework.web.servlet.view.JstlView: name 'jobs'; URL [/WEB-INF/pages/jobs.jsp]] in DispatcherServlet with name 'Batch Servlet'
2014-05-27 20:16:23,598 DEBUG [JstlView] - Added model object 'endJob' of type [java.lang.Integer] to request in view with name 'jobs'
2014-05-27 20:16:23,598 DEBUG [JstlView] - Added model object 'jobs' of type [java.util.ArrayList] to request in view with name 'jobs'
2014-05-27 20:16:23,598 DEBUG [JstlView] - Added model object 'startJob' of type [java.lang.Integer] to request in view with name 'jobs'
2014-05-27 20:16:23,598 DEBUG [JstlView] - Added model object 'totalJobs' of type [java.lang.Integer] to request in view with name 'jobs'
2014-05-27 20:16:23,598 DEBUG [JstlView] - Added model object 'jobName' of type [java.lang.String] to request in view with name 'jobs'
2014-05-27 20:16:23,598 DEBUG [JstlView] - Forwarding to resource [/WEB-INF/pages/jobs.jsp] in InternalResourceView 'jobs'
2014-05-27 20:16:23,598 DEBUG [DispatcherServlet] - Successfully completed request
Whereas when I look at the longs for the spring-batch-admin-sample I can see that /spring_admin_console/jobs is using AjaxFreeMarkerView...
[5/27/14 19:57:13:962 EST] 00000023 SystemOut O 19:57:13,950 DEBUG WebContainer : 0 servlet.DispatcherServlet:693 - DispatcherServlet with name 'Batch Servlet' processing GET request for [/s
pring_admin_console/jobs]
[5/27/14 19:57:13:978 EST] 00000023 SystemOut O 19:57:13,965 DEBUG WebContainer : 0 annotation.DefaultAnnotationHandlerMapping:221 - Mapping [/jobs] to HandlerExecutionChain with handler [or
g.springframework.batch.admin.web.JobController#52e052e0] and 3 interceptors
[5/27/14 19:57:14:000 EST] 00000023 SystemOut O 19:57:13,988 DEBUG WebContainer : 0 servlet.DispatcherServlet:769 - Last-Modified value for [/spring_admin_console/jobs] is: -1
[5/27/14 19:57:14:045 EST] 00000023 SystemOut O 19:57:14,031 DEBUG WebContainer : 0 support.HandlerMethodInvoker:155 - Invoking model attribute method: public java.lang.String org.spring
framework.batch.admin.web.JobController.getJobName(javax.servlet.http.HttpServletRequest)
[5/27/14 19:57:14:091 EST] 00000023 SystemOut O 19:57:14,078 DEBUG WebContainer : 0 support.HandlerMethodInvoker:173 - Invoking request handler method: public void org.springframework.batch.admin.web.JobController.jobs(org.springframework.ui.ModelMap,int,int)
[5/27/14 19:57:14:125 EST] 00000023 SystemOut O 19:57:14,113 DEBUG WebContainer : 0 servlet.DispatcherServlet:1045 - Rendering view org.springframework.batch.admin.web.freemarker.AjaxFreeMarkerView: name 'jobs'; URL [/layouts/html/standard.ftl]] in DispatcherServlet with name 'Batch Servlet'
[5/27/14 19:57:14:144 EST] 00000023 SystemOut O 19:57:14,130 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'springMacroRequestContext' of type [org.springframework.web.servlet.support.RequestContext] to request in view with name 'jobs'
[5/27/14 19:57:14:158 EST] 00000023 SystemOut O 19:57:14,144 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'startJob' of type [java.lang.Integer] to request i
n view with name 'jobs'
[5/27/14 19:57:14:172 EST] 00000023 SystemOut O 19:57:14,159 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'totalJobs' of type [java.lang.Integer] to request
in view with name 'jobs'
[5/27/14 19:57:14:186 EST] 00000023 SystemOut O 19:57:14,172 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'servletPath' of type [java.lang.String] to request
in view with name 'jobs'
[5/27/14 19:57:14:200 EST] 00000023 SystemOut O 19:57:14,186 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'jobName' of type [java.lang.String] to request in
view with name 'jobs'
[5/27/14 19:57:14:214 EST] 00000023 SystemOut O 19:57:14,200 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'jobs' of type [java.util.ArrayList] to request in
view with name 'jobs'
[5/27/14 19:57:14:228 EST] 00000023 SystemOut O 19:57:14,214 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'titleText' of type [java.lang.String] to request i
n view with name 'jobs'
[5/27/14 19:57:14:242 EST] 00000023 SystemOut O 19:57:14,228 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'titleCode' of type [java.lang.String] to request i
n view with name 'jobs'
[5/27/14 19:57:14:255 EST] 00000023 SystemOut O 19:57:14,242 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'endJob' of type [java.lang.Integer] to request in
view with name 'jobs'
[5/27/14 19:57:14:269 EST] 00000023 SystemOut O 19:57:14,256 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:328 - Added model object 'body' of type [java.lang.String] to request in vie
w with name 'jobs'
[5/27/14 19:57:14:287 EST] 00000023 SystemOut O 19:57:14,274 DEBUG WebContainer : 0 freemarker.AjaxFreeMarkerView:279 - Rendering FreeMarker template [/layouts/html/standard.ftl] in FreeMark
erView 'jobs'
[5/27/14 19:57:14:909 EST] 00000023 SystemOut O 19:57:14,895 DEBUG WebContainer : 0 servlet.DispatcherServlet:674 - Successfully completed request
I've spent a while trying to find out what is happening and am not sure. I suspect maybe I am doing something wrong in my web.xml. Maybe relating to the order of the servlets.
I am going to post an excerpt from my web.xml in the hopes that someone will see something I am doing wrong.
Thanks in advance for having a look at this for me.
I've put my web.xml here.
http://pastebin.com/eBkHMe8g
In your web project make sure you have this folder structure: WEB-INF\classes\META-INF\spring\batch\override. And under this folder create a new .xml file. Name it whatever name you want. The content of the file should be something like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="resourceService" class="org.springframework.batch.admin.web.resources.DefaultResourceService">
<property name="servletPath" value="/batch" />
</bean>
</beans>
The value for the servletPath needs to match your servlet-mapping in your web.xml. I used /batch because this is what you have in yours.
More about this here. Also, it does help to have a look at the Spring Batch Admin source code. In that resources-context.xml you can see that a certain SPeL expression is used for various servletPath resources: <prop key="servletPath">#{resourceService.servletPath}</prop>. You need to search for the bean called resourceService, have a look at its source code and from there you can establish what property to change for DefaultResourceService in your custom .xml file.
LATER EDIT: As a general suggestion, your mvc-dispatcher DispatcherServlet is picking up automatically and by default the file located at /WEB-INF/mvc-dispatcher-servlet.xml. You'll have the beans under mvc-dispatcher-servlet.xml being picked up and loaded twice in two different app contexts because you have this file specified as one of the contextConfigLocation values. There is a hierarchy of contexts there, root one (defined by contextConfigLocation) being the parent. The idea is to place beans that are non-web (or that are to be used by web) in the root context and the web to be able to "use" these beans. Other way around doesn't quite make sense, because a DAO or Service class doesn't need access to web.

MyBatis-Spring setup not using transactions

I have a web application set up with MyBatis and Spring, but it doesn't seem to be using any transactions. Here's the configuration:
applicationContext.xml:
<tx:annotation-driven />
<!-- <tx:jta-transaction-manager /> --> <!-- using WebSphere 7 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/my_datasource" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="WEB-INF/mybatis-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="testDAO" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.lmig.TestDAO" />
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
Sample bean method with transaction definition:
#Transactional(propagation = Propagation.REQUIRED)
public void testDelete() {
testDAO.firstDelete(); //always successful
testDAO.secondDelete(); //always throws SQLServerException
}
TestDAO:
public interface TestDAO {
public void firstDelete();
public void secondDelete();
}
Server debug log:
[11/17/11 16:42:07:998 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Creating SqlSession with JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection#34ba34ba]
[11/17/11 16:42:07:999 PST] 0000002b SystemOut O DEBUG [java.sql.Connection] ooo Connection Opened
[11/17/11 16:42:08:001 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection#34ba34ba] will be managed by Spring
[11/17/11 16:42:08:005 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#74247424]
[11/17/11 16:42:08:025 PST] 0000002b SystemOut O DEBUG [java.sql.PreparedStatement] ==> Executing: delete from test1
[11/17/11 16:42:08:025 PST] 0000002b SystemOut O DEBUG [java.sql.PreparedStatement] ==> Parameters:
[11/17/11 16:42:08:097 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#74247424]
[11/17/11 16:42:08:099 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#74247424]
[11/17/11 16:42:08:123 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#74247424]
[11/17/11 16:42:08:136 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Creating SqlSession with JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection#17351735]
[11/17/11 16:42:08:137 PST] 0000002b SystemOut O DEBUG [java.sql.Connection] ooo Connection Opened
[11/17/11 16:42:08:138 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] JDBC Connection [com.ibm.ws.rsadapter.jdbc.WSJdbcConnection#17351735] will be managed by Spring
[11/17/11 16:42:08:139 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#1d871d87]
[11/17/11 16:42:08:145 PST] 0000002b SystemOut O DEBUG [java.sql.PreparedStatement] ==> Executing: delete from test2
[11/17/11 16:42:08:146 PST] 0000002b SystemOut O DEBUG [java.sql.PreparedStatement] ==> Parameters:
[11/17/11 16:42:08:490 PST] 0000002b XmlBeanDefini I org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
[11/17/11 16:42:08:554 PST] 0000002b SQLErrorCodes I org.springframework.jdbc.support.SQLErrorCodesFactory <init> SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
[11/17/11 16:42:08:560 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#1d871d87]
[11/17/11 16:42:08:597 PST] 0000002b SystemOut O DEBUG [org.mybatis.spring.SqlSessionUtils] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#1d871d87]
...SQLServerException follows...
Since secondDelete() throws an exception, the entire transaction would be expected to roll back. However, this isn't the case, and the firstDelete() is still committed. I've tried all combinations of the transaction manager config (Spring-managed, app server-managed, both) but I keep getting the same results. Any idea what I'm doing wrong?
I'm using Mybatis 3, Spring 3 on WebSphere 7 with SQL Server 2005 as the DB.
I figured this out: my testDelete() method wasn't a Spring-managed bean, so it wasn't participating in Spring-managed transactions. I changed my configuration to this, and now it's working.

Resources