GoogleSearchBox

Custom Search

Friday, June 28, 2013

is invalid; nested exception is org.xml.sax.SAXParseException: Element type "bean" must be followed by either attribute specifications, ">" or "/>".

If you are getting extra special characters (like ascii or hexa or any weird characters) in your script/xml/txt file OR
If you are getting an error like below in your logs:


2013-06-28 08:57:02,295 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 67 in XML document from ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Element type "bean" must be followed by either attribute specifications, ">" or "/>".

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)

        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)

        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)

        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)

        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)

        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)

        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)

        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)

        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)

        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)

        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody0(SafeContextLoaderListener.java:75)

        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody1$advice(SafeContextLoaderListener.java:57)

        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized(SafeContextLoaderListener.java:1)

        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)

        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)

        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)

        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)

        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)

        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)

        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)

        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)

        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)

        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)

        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)

        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)

        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

        at org.apache.catalina.core.StandardService.start(StandardService.java:525)

        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Caused by: org.xml.sax.SAXParseException: Element type "bean" must be followed by either attribute specifications, ">" or "/>".



The reason could be that your xml file contains some invisible characters to your eye (basically some ansi characters), Normally this happens when you copy the code from internet browser or pdf  and paste into your editor/IDE.

Though you keep formatting the xml, but still the error remains same as shown below:












Solutions #1:
1. Copy the code showing error into just plain notepad.
2. try deleting all the spaces between words and then manually use spacebar to add spaces between words/attributes.
3. Again copy the code from notepad and then paste into your IDE/Editor.

This should have solved.

But, in some cases, this also does not solve the issue.

Solutions #2:
1. Open the same excel file in an advanced editor like notepad++,
2. Go to the "Encode" menu --> choose "Encode in ANSI"
















3. Now you should be able to see all those invisible ansi characters you have derived  while copy pasting  from internet (shown below):













4. So you got now proof that you have some to give company there in your xml file.
    Delete all those, characters manually or by using the editors find/replace (ctrl + h ) option:

















5. Now try changing the encoding to the other formats, you will be surprised to see more invisible characters suddenly becomes visible to you :)















6. Play around with encodings, delete those chars and Save.
    Rerun the application. You should be fine.

If you are in Unix Environment, and you doubt your script file (.sh) contains any special characters, you can view those special characters using VI editor.

Open the file using VI editor:
$ vi <file_name>
Hit Esc
Then type in the command line of the vi editor as (To be able to see the extra characters)-  :set list 
To again hide the special characters or make the file to be seen as normal, type in the command line-  :set nolist 

Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.mapping.SimpleValue.(Lorg/hibernate/mapping/Table;)V

 
2013-06-28 07:17:07,829 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ticketRegistry' defined in ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.mapping.SimpleValue.<init>(Lorg/hibernate/mapping/Table;)V
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
        at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:616)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody0(SafeContextLoaderListener.java:75)
        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody1$advice(SafeContextLoaderListener.java:57)
        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized(SafeContextLoaderListener.java:1)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
        at org.apache.catalina.core.StandardService.start(StandardService.java:525)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.mapping.SimpleValue.<init>(Lorg/hibernate/mapping/Table;)V


Solution:

If you are using hibernate-core jar version 3.6 and above, then Take out the dependency (related to hibernate-annotations jar) from your maven or remove the hibernate-annotations jar from your applications lib) :
 <artifactId>hibernate-annotations</artifactId>

Chcek maven dependyncy or jar conflicts - mvn dependency:tree or mvn dependency:tree -Dverbose : is used to see/verify the dependency between jars in Maven for your project dir

Maven command
mvn dependency:tree  is used to see/verify the dependency between jars used in a particular project.

To run above command, navigate to your project directory and where you have the pom.xml file for the project you want to verify the jar dependencies:
For example, like
# cd /opt/cas-workspace/local-cas

Thats the location of my workspace, containing my projects pom file.

[root@www local-cas]# ls -l
total 20
-rw-r--r-- 1 root root 8795 Jun 25 11:33 pom.xml
drwxr-xr-x 3 root root 4096 Jun  5 07:33 src
drwxr-xr-x 5 root root 4096 Jun 25 11:57 target

So, now you can run the mvn dependency:tree command.
# mvn dependency:tree

or specifically if you know which jar you are getting loaded as extra then you can filter it to look for that particular jar by providing its groupId and artifactId and its version (all are option values):

> mvn dependency:tree -Dincludes=org.slf4j:slf4j-api:1.4.2

where the above format is :  mvn dependency:tree -Dincludes=[groupId]:[artifactId]:[version]

To look for a particular jar files groupId and its artifact you can search on below sites:
https://www.versioneye.com/java/org.slf4j:slf4j-api/1.4.2
https://search.maven.org/#search%7Cga%7C1%7Cjcl104-over-slf4j

Also you can use:
# mvn dependency:tree -Dverbose

In verbose mode the dependency tree shows dependencies that were omitted for: being a duplicate of another; conflicting with another's version and/or scope

References:
http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
http://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html
http://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html

Cannot create a session after the response has been committed : CAS application error

Below is an issue related to CAS,

Env is:  CAS 3.5.2 deployed on Tomcat 6.

"When I login I get an error. If I refresh/resubmit the information it goes through and operates normally. Any advice would be greatly appreciated."

The error is below:
type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException: Cannot create a session after the response has been committed

org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.jasig.cas.web.init.SafeDispatcherServlet.service_aroundBody2(SafeDispatcherServlet.java:128) org.jasig.cas.web.init.SafeDispatcherServlet.service_aroundBody3$advice(SafeDispatcherServlet.java:57) org.jasig.cas.web.init.SafeDispatcherServlet.service(SafeDispatcherServlet.java:1) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.github.inspektr.common.web.ClientInfoThreadLocalFilter.doFilter(ClientInfoThreadLocalFilter.java:63) root cause java.lang.IllegalStateException: Cannot create a session after the response has been committed org.apache.catalina.connector.Request.doGetSession(Request.java:2400) org.apache.catalina.connector.Request.getSession(Request.java:2120) org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:833) org.springframework.webflow.context.servlet.HttpSessionMap.getMutex(HttpSessionMap.java:98) org.springframework.webflow.core.collection.LocalSharedAttributeMap.getMutex(LocalSharedAttributeMap.java:39) org.springframework.webflow.conversation.impl.ContainedConversation.unlock(ContainedConversation.java:108) org.springframework.webflow.execution.repository.support.ConversationBackedFlowExecutionLock.unlock(ConversationBackedFlowExecutionLock.java:55) org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:178) org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.jasig.cas.web.init.SafeDispatcherServlet.service_aroundBody2(SafeDispatcherServlet.java:128) org.jasig.cas.web.init.SafeDispatcherServlet.service_aroundBody3$advice(SafeDispatcherServlet.java:57) org.jasig.cas.web.init.SafeDispatcherServlet.service(SafeDispatcherServlet.java:1) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) com.github.inspektr.common.web.ClientInfoThreadLocalFilter.doFilter(ClientInfoThreadLocalFilter.java:63)

Solution:
"I assume that happens when there is no 'service' param and CAS tries to render a successful generic login page. Correct? If so, that is a side effect that is caused by 'terminateWebSessionListener' bean defined in cas-servlet.xml. You could a) disable one b) set the 'timeToDieInSeconds' property to a higher value to remedy this annoyance, like so":

<bean id="terminateWebSessionListener" class="org.jasig.cas.web.flow.TerminateWebSessionListener" 
      p:serviceManagerUrl="${cas.securityContext.serviceProperties.service}"
      p:timeToDieInSeconds="5"/>
Via Reference:
https://lists.wisc.edu/read/messages?id=27757318#27757318

Wednesday, June 26, 2013

Error creating bean with name 'ticketRegistry' defined in ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)

If you are working on CAS for SSO functionality and while trying to use CAS server, you got below exceptions in your log:

2013-06-26 06:12:57,764 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ticketRegistry' defined in ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody0(SafeContextLoaderListener.java:75)
        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody1$advice(SafeContextLoaderListener.java:57)
        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized(SafeContextLoaderListener.java:1)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
        at org.apache.catalina.core.StandardService.start(StandardService.java:525)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
2013-06-26 06:12:57,768 ERROR [org.jasig.cas.web.init.SafeContextLoaderListener] - <SafeContextLoaderListener:
The Spring ContextLoaderListener we wrap threw on contextInitialized.
But for our having caught this error, the web application context would not have initialized.>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ticketRegistry' defined in ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml]: Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)
        at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:250)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody0(SafeContextLoaderListener.java:75)
        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized_aroundBody1$advice(SafeContextLoaderListener.java:57)
        at org.jasig.cas.web.init.SafeContextLoaderListener.contextInitialized(SafeContextLoaderListener.java:1)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
        at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
        at org.apache.catalina.core.StandardService.start(StandardService.java:525)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
SafeContextLoaderListener:
The Spring ContextLoaderListener we wrap threw on contextInitialized.

Solution:

Basically you might get this because of these reasons (I used to get):
1. Jar files not found in applications WEB-INF/lib directory
    Or, some jars are conflicting with each other.
    Check for same jars in different versions should not exist (at least in some cases).

2. Check you maven's dependencies (for getting these jars).
     You can use mvn dependency:tree  to find out if there is any jar loaded twice, which might be causing conflict.

3. the pom.xml file should contain proper dependencies.
  deployerConfigContext.xml, ticketRegistry.xml should have right beans and configured properly depending on your CAS server (Basically different CAS servers use different configurations in these files).

Cannot execute mojo: tree. It requires a project with an existing pom.xml, but the build is not using one

When run below command :
[root@www 
~]# mvn dependency:tree

Result:
[INFO] 
Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot execute mojo: tree. It requires a project with an existing pom.xml, but the build is not using one.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Wed Jun 26 02:38:40 EDT 2013
[INFO] Final Memory: 3M/61M
[INFO] ------------------------------------------------------------------------

Try with the -e option:
[root@www ~]# mvn -e dependency:tree

Result:
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot execute mojo: tree. It requires a project with an existing pom.xml, but the build is not using one.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Cannot execute mojo: tree. It requires a project with an existing pom.xml, but the build is not using one.
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot execute mojo: tree. It requires a project with an existing pom.xml, but the build is not using one.
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:414)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        ... 17 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Wed Jun 26 02:38:57 EDT 2013
[INFO] Final Memory: 3M/61M
[INFO] ------------------------------------------------------------------------

Normally this error happens, when you try to run the mvn dependency:tree  command from a location, where it does not find a POM.
mvn dependency:tree  is used to see/verify the dependency between jars used in a particular project.

So, the solution is :
navigate to your project directory and where you have the pom.xml file for the project you want to verify the jar dependencies:
For example, like
# cd /opt/cas-workspace/local-cas

Thats the location of my workspace, containing my projects pom file.

[root@www local-cas]# ls -l
total 20
-rw-r--r-- 1 root root 8795 Jun 25 11:33 pom.xml
drwxr-xr-x 3 root root 4096 Jun  5 07:33 src
drwxr-xr-x 5 root root 4096 Jun 25 11:57 target


Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument

Error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ticketRegistry' defined in ServletContext resource [/WEB-INF/spring-configuration/ticketRegistry.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/deployerConfigContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver

 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

Solution:
If you are using Hibernate 3.5 or above, You should remove the dependency on hibernate-annotations from your maven pom file.

If you got this while building CAS server using the root pom file.

Try removing any spring related dependencies mentioned in the projects root POM file. Internally the CAS will download all the spring dependencies.

Also, add the corresponding Database driver jar file. Or add it to your pom's dependency.
e.g.:
For adding MySQL Server driver, the Maven's POM dependency would be:

  <dependency>

   <groupId>mysql</groupId>

   <artifactId>mysql-connector-java</artifactId>

   <version>5.1.13</version>

   <scope>runtime</scope>

  </dependency>

References:

Purging / Delete local maven (mvn) repository

Local mvn repository is nothing but a cache of part of the contents of online repository.
Sometimes it becomes messy with duplicate jars.
So, time to time we should clean the local maven repository (only when you should have internet access and can download again from online repositories):

maven repository is located in your systems, current users home / root path inside a directory named ".m2".

In windows it should be at : C:\Documents and Settings\<username>\

In Linux, it should be at :  ~  (root location)


in Unix, navigate to that directory and then delete the "repository" directory. and rebuild the pom.xml

Go to the root:
[root@www ~]# cd

List out the contents in root, with -a  attrribute, to show system, hidden files/directories too (basically files with all attributes will be listed):
[root@www ~]# ls -la
Result should show something like this below:






Delete the repository dir:
[root@www ~]# rm -rf ~/.m2/repository

[root@www ~]# cd .m2

[root@www .m2]# ls -l

total 0

Now again do a build of your project's pom file:
Navigate to your projects pom file directory:
# cd <projects workspace location containing pom.xml>
# mvn clean package

It should then download all required jars to the same repository again.

Otherwise you can use the command : mvn dependency:purge-local-repository
The default behaviour of the plugin is to first resolve the entire dependency tree, then delete the contents from the local repository, and then re-resolve the dependencies from the remote repository.

References:
http://maven.apache.org/plugins/maven-dependency-plugin/examples/purging-local-repository.html

Tuesday, June 25, 2013

dependencies.dependency.version is missing for org.hibernate hibernate-core jar and other hibernate jars

# mvn clean package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).


Project ID: rsi.ddms.cas:local-cas
POM Location: /opt/cas-workspace/local-cas/pom.xml
Validation Messages:

    [0]  'dependencies.dependency.version' is missing for org.hibernate:hibernate-core:jar
    [1]  'dependencies.dependency.version' is missing for org.hibernate:hibernate-entitymanager:jar


Reason: Failed to validate POM for project rsi.ddms.cas:local-cas at /opt/cas-workspace/local-cas/pom.xml


[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.reactor.MavenExecutionException: Failed to validate POM for project rsi.ddms.cas:local-cas at /opt/cas-workspace/local-cas/pom.xml
        at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:404)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:272)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.project.InvalidProjectModelException: Failed to validate POM for project rsi.ddms.cas:local-cas at /opt/cas-workspace/local-cas/pom.xml
        at org.apache.maven.project.DefaultMavenProjectBuilder.processProjectLogic(DefaultMavenProjectBuilder.java:1077)
        at org.apache.maven.project.DefaultMavenProjectBuilder.buildInternal(DefaultMavenProjectBuilder.java:880)
        at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:508)
        at org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBuilder.java:200)
        at org.apache.maven.DefaultMaven.getProject(DefaultMaven.java:604)
        at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:487)
        at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:391)
        ... 12 more

Basically, we get this error while doing maven build.
The reason is that, your pom xml file does not either have the version tag specified for that artifact to be downloaded. 
Or the jar is not found in the repositories mentioned there in.

Simple Solution is :

Add the version tag in your pom file as:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>3.6.10.Final</version>
</dependency>

Monday, June 24, 2013

How to Set Up Apache Virtual Hosts on CentOS 6

Sometimes when we want to run / host multiple domain (websites) on a single server with a single public IP address, we need to setup Virtual hosts using apache server to achieve the same.

Here is a very nice article on that:
https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-centos-6

Wednesday, June 19, 2013

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provid er.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I got this exception, while my demo java web application tried to communicate CAS application (deployed in tomcat) using SSL.




I have my tomcat server already configured using SSL certificates and using a keystore file to have the  security certificate.




I got below stacktrace of the errors in my console:
Jun 19, 2013 4:26:27 PM org.jasig.cas.client.util.CommonUtils getResponseFromServer
SEVERE: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1611)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1035)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:124)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1139)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:418)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at org.jasig.cas.client.util.CommonUtils.getResponseFromServer(CommonUtils.java:326)
at org.jasig.cas.client.util.CommonUtils.getResponseFromServer(CommonUtils.java:305)
at org.jasig.cas.client.validation.AbstractCasProtocolUrlBasedTicketValidator.retrieveResponseFromServer(AbstractCasProtocolUrlBasedTicketValidator.java:50)
at org.jasig.cas.client.validation.AbstractUrlBasedTicketValidator.validate(AbstractUrlBasedTicketValidator.java:207)
at org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:169)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.jasig.cas.client.authentication.AuthenticationFilter.doFilter(AuthenticationFilter.java:116)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:881)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:674)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:541)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:619)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:285)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:191)
at sun.security.validator.Validator.validate(Validator.java:218)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1014)
... 33 more


Below is my tomcat's "server.xml" section having SSL configuration details:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               address="216.113.229.31"
               maxThreads="150" scheme="https" secure="true"
               truststoreFile="/usr/local/apache-tomcat-6.0.37/conf/cacerts.jks" truststorePass="changeit"
               keystoreFile="/usr/local/apache-tomcat-6.0.37/conf/myServerKeystore.jks" keystorePass="changeit"
               clientAuth="false" sslProtocol="TLS" />

Also, I have imported server Root CA certificate into my browsers.

The reason of the above error, I could figured out is that:
Though I have configured the tomcat to use, "myServerKeystore.jks" java keystore file.
But the Java web applications seems to use by default the security certificates available in the "cacerts" file (located at $JAVA_HOME/jre/lib/security/).

The 1st solutions is:
step 1.  
Copy your "cacerts" file (located at $JAVA_HOME/jre/lib/security/ ) to some safe backup location in case to be able to revert back to original.

step 2. 
Export the security certificates from your keystore file (in my case its "myServerKeystore.jks")  into  "cacerts" (located at $JAVA_HOME/jre/lib/security/ ) .

Using Below command in Linx (Similarly you can achieve it in Windows too) to import ssl certificate from one keystore into another keystore using keytool:

# keytool -importkeystore  -destkeystore /usr/java/default/jre/lib/security/cacerts  -srckeystore myServerKeystore.jks

For windows above can be some thing like this:
C:\certs> keytool -importkeystore  -destkeystore C:\Program Files\Java\jdk1.6.0_24\jre\lib\security\cacerts  -srckeystore  myServerKeystore.jks

Assuming "myServerKeystore.jks" is at "C:\certs"  or accordingly provide the path above for your keystore.
Result will be something like below:

Enter destination keystore password: [enter password here, default is "changeit"]
Enter source keystore password: [enter password here, default is "changeit"]
Entry for alias localhostservcert successfully imported.
Import command completed:  1 entries successfully imported, 0 entries failed or cancelled

Marked in bold above are, meant to be changed if required as per your settings.

Now, restart your server and try again.
Above exception should have been resolved.



If still the issue has not resolved yet, Please consider below importing the root certificate into "cacerts" :

The 2nd solutions is:

step 1.  
Copy your "cacerts" file (located at $JAVA_HOME/jre/lib/security/ ) to some safe backup location in case to be able to revert back to original.

step 2.  
Sometimes, the certificate to be imported MUST be a DER-encoded file. If the contents of the certificate file are binary, it's likely DER-encoded; if the file begins with the text ---BEGIN CERTIFICATE---, it is PEM-encoded and needs to be converted to DER encoding.
So if your root certificate is a PEM encoded, Convert your to a DER format using below command:

# openssl x509 -in casRootCAcert.crt -out casRootCAcert.der -outform DER

Where "casRootCAcert.crt" is my original root CA certificate (the one you used while creating server certificates). As I created in this tutorial.
And where as "casRootCAcert.der" is the new DER formated root CA.

step 3.
 Now Export the DER formatted Root CA certificate  into  "cacerts" (located at $JAVA_HOME/jre/lib/security/ ).

# keytool -import -keystore $JAVA_HOME/jre/lib/security/cacerts -file casRootCAcert.der -alias myservercert

Now, restart your server and try again.
Above exception should have been resolved.

step 4.
List out to see if the $JAVA_HOME/jre/lib/security/cacerts  has your trusted certificate alias:
# keytool -list -keystore $JAVA_HOME/jre/lib/security/cacerts

Look for your server certificate alias name, like above, look for "myservercert" or by default it creates an alias named as "mykey".
If it exist, then time to test your ssl connection again.

Now, restart your server and try again.
Above exception should have been resolved.



If you are looking for how to automatically create certificates and import it into keystore, for your development environment, please follow this post.

References used:
https://wiki.jasig.org/display/CASUM/SSL+Troubleshooting+and+Reference+Guide
http://stackoverflow.com/questions/9619030/resolving-javax-net-ssl-sslhandshakeexception-sun-security-validator-validatore?rq=1


Creating KeyStore file using "InstallCert.java" to configure SSL on Development Env

This post describes how to Generate / Create and Test a KeyStore file using "InstallCert.java" to configure SSL (https) on local Development Environment.

If you landed on this page because of the error "sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provid er.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target", while using SSL configuration on your server for your java application, please follow this post:

I used the  "InstallCert.java" java class,  mentioned at this link to create and add a certificate into javakeystore which I could use in my development environment's tomcat server to achieve SSL.

Assuming you have the "InstallCert.java" file downloaded to your local system and compiled it.
In my case, I have compiled it to a location "D:\MyEclipse8_WS\compAproj\src":

Run the java command, passing the server's  hostname, (in my case, its "localhost", for the development env):
D:\MyEclipse8_WS\compAproj\src> java InstallCert localhost

[You could have passed some think like this also:
D:\MyEclipse8_WS\compAproj\src> java InstallCert www.xyz.com
where "www.xyz.com"  is your test env domain/host name.]

You will get a Result like below:
Loading KeyStore C:\Program Files\Java\jre7\lib\security\cacerts...
Opening connection to localhost:443...
Starting SSL handshake...

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building f
ailed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certificatio
n path to requested target
        at sun.security.ssl.Alerts.getSSLException(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
        at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
        at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
        at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
        at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
        at sun.security.ssl.Handshaker.processLoop(Unknown Source)
        at sun.security.ssl.Handshaker.process_record(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
        at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
        at InstallCert.main(InstallCert.java:100)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provid
er.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

        at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
        at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
        at sun.security.validator.Validator.validate(Unknown Source)
        at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
        at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
        at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
        at InstallCert$SavingTrustManager.checkServerTrusted(InstallCert.java:195)
        at sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(Unknown Source)
        ... 9 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certific
ation path to requested target
        at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
        at java.security.cert.CertPathBuilder.build(Unknown Source)
        ... 17 more

Server sent 1 certificate(s):

 1 Subject CN=localhost, OU=DDMS, O=RSI, L=Bangalore, ST=Karnatak, C=IN
   Issuer  CN=localhost, OU=DDMS, O=RSI, L=Bangalore, ST=Karnatak, C=IN
   sha1    6e ee e0 c7 19 5f ee ab 6f e0 bd 60 db 56 fa 7f 9a 82 dc 08
   md5     31 b6 06 9f 77 58 33 3b b8 ad 79 9b 44 77 a9 b0

Enter certificate to add to trusted keystore or 'q' to quit: [1]
1

[
[
  Version: V3
  Subject: CN=localhost, OU=DDMS, O=RSI, L=Bangalore, ST=Karnatak, C=IN
  Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5

  Key:  Sun RSA public key, 1024 bits
  modulus: 92659808969929865129336241341967971654025457738531240931492821310253581021652160736911057
8703736995831932144701336033660310891386958539146005637308769188367103225061070068772345915142571293
8993861368030004277914233863759887059296889665823492198040834084491251919373806193796848922810680430
7637917119048358073
  public exponent: 65537
  Validity: [From: Mon Jun 10 17:00:58 GMT+05:30 2013,
               To: Sun Sep 08 17:00:58 GMT+05:30 2013]
  Issuer: CN=localhost, OU=DDMS, O=RSI, L=Bangalore, ST=Karnatak, C=IN
  SerialNumber: [    51b5b8f2]

]
  Algorithm: [SHA1withRSA]
  Signature:
0000: 65 4F 4F 86 21 1C CF A6   50 BD B0 29 CE C8 6F F9  eOO.!...P..)..o.
0010: DE C1 99 47 29 21 0F 8F   24 36 43 0C 3B 75 21 D6  ...G)!..$6C.;u!.
0020: 81 D2 15 E0 F3 5E 9F 30   33 EC 0F 65 28 2D 0E F1  .....^.03..e(-..
0030: F0 76 3D A0 C0 D1 18 41   5B FB 1B C5 FB 7B B8 52  .v=....A[......R
0040: 62 CE A7 34 32 06 A2 F7   2E BB 78 55 1A CE B0 50  b..42.....xU...P
0050: A3 2E 3E 32 68 7F EE 6C   83 D4 9E 76 E7 14 B7 C0  ..>2h..l...v....
0060: 91 C6 22 B2 C6 A9 CC 2F   E0 06 3A F1 50 92 15 FC  .."..../..:.P...
0070: C5 F6 1A 12 4E 52 38 31   99 32 E1 66 D2 7D 49 EB  ....NR81.2.f..I.

]

Added certificate to keystore 'jssecacerts' using alias 'localhost-1'


To List out the keystore to see if our certificate (named as 'localhost-1' along with other certificates imported from %JAVA_HOME%\jre\lib\security\cacerts)  is in there:
D:\MyEclipse8_WS\compAproj\src>keytool -list -keystore jssecacerts

So, we have the keystore generated for us.
Now we have two ways to use the generated keystore file:
1st way:
Configure the keystore to be used as the default keystore using some environment variable settings as per the  java documentation.

Or, 2nd way:
Do below steps:
1.   copy your "cacerts" file (located at %JAVA_HOME%\jre\lib\security\ ) to some safe backup location.
2. rename the "jssecacerts" file (generated above) as "cacerts"
3. copy the newly renamed file "cacerts" into location %JAVA_HOME%\jre\lib\security\
     And if asked to overwrite, say Yes.

Now,
For the 2nd time, run the Java command, to test/verify that, your SSL is configured correctly to be used with your java web applications :

D:\MyEclipse8_WS\compAproj\src> java InstallCert localhost

This time there should be no errors. That means Java application can do a proper SSL handshake with the server.
Congrats !!


You can follow these posts as references, which might be helpful to you : http://nodsw.com/blog/leeland/2006/12/06-no-more-unable-find-valid-certification-path-requested-target
Or
http://www.java-samples.com/showtutorial.php?tutorialid=210

http://www.novell.com/communities/node/13621/cacerts-dummies