struts2 project is not deploying properly in tomcat7 - linux

My project runs perfectly in eclipse.
But when I export its war file to the tomcat7 on my linux server, it is not unpacking the war file.
Even after I do it manually, it says the requested resource is not available
The other war file also had the same problem.But when unpack it manually it worked.
I'm not sure what the problem is.
My Web.xml is
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>-1</session-timeout>
</session-config>
</web-app>
And my struts.xml is
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration
2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="" extends="struts-default">
<action name="effort" class="EffortAction">
<result name="success">index.jsp</result>
</action>
<action name="Finance_Report" class="EffortAction">
<result name="success">Report.jsp</result>
</action>
<action name="Pivot" class="Downloads">
<result name="success" type="stream">
<param name="contentType">application/octet-stream</param>
<param name="inputName">fileInputStream</param>
<param name="contentDisposition">attachment;filename="Finance_Pivot.xls"</param>
<param name="bufferSize">1024</param>
</result>
</action>
</package>
</struts>
The library files that I use are
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.3.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
sqljdbc4.jar
struts2-core-2.3.16.1.jar
SX.jar
xwork-core-2.3.16.1.jar
My catalina.out do not show anything for todays date. But showed something like the below on a previous date.
INFO: Undeploying context [/FinanceReport]
May 27, 2014 1:42:48 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/FinanceReport] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
May 27, 2014 1:42:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/FinanceReport] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal#18a2c34]) and a value of type [com.opensymphony.xwork2.inject.ContainerImpl] (value [com.opensymphony.xwork2.inject.ContainerImpl#1feb1c3]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
May 27, 2014 1:42:48 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/FinanceReport] created a ThreadLocal with key of type [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1] (value [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1#1bd63cb]) and a value of type [com.microsoft.sqlserver.jdbc.ActivityId] (value [66662bbe-1458-4ce9-b739-16fd806f8c7a-2]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.InternalError: Malformed class name
at java.lang.Class.getSimpleName(Class.java:1317)
at java.lang.Class.getCanonicalName(Class.java:1386)
at org.apache.catalina.loader.WebappClassLoader.getPrettyClassName(WebappClassLoader.java:2601)
at org.apache.catalina.loader.WebappClassLoader.checkThreadLocalMapForLeaks(WebappClassLoader.java:2571)
at org.apache.catalina.loader.WebappClassLoader.checkThreadLocalsForLeaks(WebappClassLoader.java:2507)
at org.apache.catalina.loader.WebappClassLoader.clearReferences(WebappClassLoader.java:2013)
at org.apache.catalina.loader.WebappClassLoader.stop(WebappClassLoader.java:1908)
at org.apache.catalina.loader.WebappLoader.stopInternal(WebappLoader.java:661)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5702)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1028)
at org.apache.catalina.startup.HostConfig.undeploy(HostConfig.java:1478)
at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1406)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1626)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:328)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
at java.lang.Thread.run(Thread.java:745)
I have checked similar question under stackoverflow, but I am unable to figure out what goes wrong in my case.

I have found a workaround.
I have deleted the war file and the folder that I created manually, and then restarted the server. Now I deployed the war once again, and it worked. But I am not sure what was the reason that blocking me previously.
Hope this helps someone.

Related

BeanLocator has not been set for servlet context My_portlet when using Service builder (Liferay)

Working on a MVC spring Liferay 6.2 portlet.
I have built a service xml file and built the project. It manages an entity (let's say MyEntity ).
When I call my addMyEntity(long id) method from my controller, an exception is thrown saying:
15:53:04,135 ERROR [http-bio-8080-exec-60][PortletBeanLocatorUtil:42] BeanLocator is null for servlet context My_portlet
com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set for servlet context My_portlet
It looks the portal cannot access to some beans resources.
My web.xml file includes the following:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context/portlet-application-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
portlet-application-context.xml only includes these beans:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
</bean>
I think what the server is looking for are these beans that are stored in a portlet-spring.xml file:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" default-destroy-method="destroy" default-init-method="afterPropertiesSet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="com.company.project.servicebuilder.dao.service.MyEntityLocalService" class="com.company.project.servicebuilder.dao.service.impl.MyEntityLocalServiceImpl" />
<bean id="com.company.project.servicebuilder.dao.service.MyEntityService" class="com.company.project.servicebuilder.dao.service.impl.MyEntityServiceImpl" />
<bean id="com.company.project.servicebuilder.dao.service.persistence.MyEntityPersistence" class="com.company.project.servicebuilder.dao.service.persistence.MyEntityPersistenceImpl" parent="basePersistence" />
</beans>
However, I see no reference to portlet-spring.xml in other files so I m afraid that these beans are never declared when the portlet is deployed.
Should it be referenced somewhere?
Any other suggestion than my hypothesis?
thx in advance.
Thanks to user "So Te" and to some wide research I solve this problem specifying pluginName in pom.xml in configuration tag and running service-builder again.
<configuration>
<autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
<appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
<appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
<appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
<liferayVersion>${liferay.version}</liferayVersion>
<pluginType>portlet</pluginType>
<pluginName>${project.artifactId}-${project.version}</pluginName>
</configuration>
The message in the log file could be a bit misleading.
One possible condition when this message would occur: if using ServiceBuilder and the Liferay portlet plugin project name does not match the configured context root. If you trace the ServiceBuilder template logic for generating the ClpSerializer.java class and the runtime execution stack, you could make the connection. This is my experience in LR6.2 CE.
Try matching your context root (in Eclipse - right-click project name/Properties/Web Project Settings) and make it the same as your Liferay portlet project name - e.g. "test-portlet". Re-build your service and deploy it.
Post your degree of success.
This was my solution to the above issue, as I was importing existing projects and not paying attention to the project settings. After matching the two values I was able to deploy successfully and execute the portlet logic.
Cheers!
Try to remove the portlet and deploy it again, normal this problems are errors on the deploy.
I had this error when building my JUnit tests cases. I was having this error because Mockito standalone doesn't support static calls. To solution it, I had to use Mockito with PowerMock in order to allow static calls.

Spring aop scoped-proxy not working on linux installation

I have a bean which is declared as session scoped. I had to enable aop in my configuration to use it in other beans (singletons by default).
confi
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
">
...
<bean id="localeResolver" class="com.my.pack.MySessionLocaleResolver" scope="session">
<property name="defaultLocale" value="en" />
<aop:scoped-proxy/>
</bean>
While I am starting it from eclipse, on my Windows desktop computer, it works just well, as it is declared.
But, when I'm publishing it on a my test, linux environment, it somehow does ignores aop thing, and throws an error
exception in linux environment
11:09:24,928 ERROR {localhost-startStop-1} [org.springframework.web.servlet.FrameworkServlet:initServletBean] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.localeResolver': Scope 'session' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:343)
There are no additional errors in log files. Nor in a web-app log, nor in a catalina.out.
I'am using spring 3.2.4, on tomcat 7.0.42 and "CentOS release 6.5".
Read those error messages carefully, the always contain a reason why it fails.
In this case:
Scope 'session' is not active for the current thread
which means you don't have an active HTTP session when the bean is requested.

WS-Security is not working with CXF - endpoint address

I am trying to add UsernameToken based security in web services written using apache cxf version 2.2.12.
Once I deploy my application in weblogic, I am getting two URL's from which I can access my WSDL.
http://localhst:8080/myapp/services/MyService?wsdl
http://localhost:8080/myapp/MyService?wsdl
I am trying to consume webservice using soapUI client and problem is If I use 2nd URL, everything works fine, my ejb is getting injected properly etc but WSS4JInterceptor is not getting called at all.
If I change the URL in soapUI to use 1st one, then Interceptor is getting called but then my services is not getting injected and I am getting NULL as service object.
I have configured WSS4JInterceptor in my spring configuration file. I need to call this Interceptor before each request so that I can verify user token from request header.
Here is my beans.xml
<bean id="wss4jInConfiguration" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
<property name="properties">
<map>
<entry key="action" value="UsernameToken Timestamp"/>
<entry key="passwordType" value="PasswordText" />
<entry>
<key>
<value>passwordCallbackRef</value>
</key>
<ref bean="passwordCallback"/>
</entry>
</map>
</property>
</bean>
<bean id="passwordCallback" class="my.interceptors.callbacks.handlers.PasswordCallbackHandler"/>
<jaxws:endpoint id="myservice" implementor="my.sample.application.MyServiceImpl"
address="/MyService">
<jaxws:ininterceptors>
<ref bean="wss4jInConfiguration" />
</jaxws:ininterceptors>
</jaxws:endpoint>
Here is my web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:WEB-INF/beans.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
I don't have currently access to my WSDL but here is the tag looks like.
<soap:address location="http://localhost:8080/MyServiceSoapPort" />
Any pointer what i am doing wrong.
NOTE: My services are working fine without call back on URL without /services/
My guess is that the Web service is actually deployed twice, once by CXF as configured in your beans.xml file and once by Weblogic as a Java EE 5 Web service. CXF doesn't perform injection (I assume that you are using #EJB), and Weblogic doesn't know anything about your WS-Security configuration.

How to develop https site with Spring 3.x?

I am a newbie in Spring based web development.
Our site is Spring based and is currently http based (so quite insecure).
Since, the site is not live yet, we are sending login/password also through a normal JSON request to server and have focussed mostly on JSP, UI design, SQL queries etc.
Now, we want to shift to focus on security and shift to https as a first step.
I have read a no. of web-pages and some spring books but none seems to provide a clear answer on how Spring can be used to provide https security.
Can some one please help me in achieving the above?
Please let me know if my question is not clear. I will try to add more details ASAP.
Our web.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
"
id="WebApp_ID" version="2.5">
<display-name>Spring3MVC</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<!--> Mapping for serving static web-content <-->
<!--> The resources folder must be in parallel to WEB-INF <-->
<!--> The mvc:resources gives "not bound" exception unless bound to a namespace as above for xmlns:mvc <-->
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:resources mapping="/scripts/**" location="/scripts/" />
</web-app>
There is only one controller right now for which, spring-servlet.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan
base-package="console.controllerpkg" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
Thanks a lot in advance!
P.S. If you can recommend me a good example based site/book on spring, it would be much appreciated. Most of the sites/books I have seen lay much emphasis on theory but very little examples. That has left me a little confused.
As Dave says, you need to configure your container to serve SSL, and then deploy your spring app into that container. Learn about configuring Tomcat for SSL.
Alternately, and more flexibly you can front your container using Apache, and enable SSL there.
Spring is not 100% responsible for configuring SSL. For that you need to configure the container (jetty, tomcat, etc) to handle SSL.
Thanks for all the help guys.
I will re-iterate what I did just for my own record purposes.
First of all, the link provided by nont about 'Tomcat for SSL' was really helpful.
I read all about SSL and Tomcat there and this is what I did:
On the command prompt, enter:
keytool -genkey -alias tomcat -keyalg RSA
The above command asked me some simple questions needed for a Certificate. I used the password 'changeit' wherever asked (as that is the default password).
On finishing with the above command, it generated a keystore file in C:/Documents and Settings//.keystore
I copied this .keystore file to tomcat/conf/myKeyStore.jks
Then I added the following to conf/server.xml :
<Connector protocol="org.apache.coyote.http11.Http11Protocol"
port="8443" minSpareThreads="5"
maxSpareThreads="75"
enableLookups="true"
disableUploadTimeout="true"
acceptCount="100"
maxThreads="200" debug="5"
scheme="https" secure="true" SSLEnabled="true"
keystoreFile="${catalina.home}/conf/myKeyStore.jks"
keystoreType="JKS" keystorePass="changeit"
truststoreFile="${catalina.home}/conf/cacerts"
truststoreType="JKS" truststorePass="changeit"
SSLVerifyClient="require" SSLEngine="on" SSLVerifyDepth="2"
sslProtocol="TLS" />
And that's it!!
Next time, I ran tomcat my old http link did not work.
Then I tried adding sweet 's' to http with a port number of 8443 and lo! everything was up and running again.
Thanks nont for the wonderful link!!
Configure two different web sites, one for http and one for https, the one for http will have just a redirect to the https site.

English error messages in JSF 2.0.3 (not validation)?

I had configured JSF 1.2 successfully to display English error messages that come from the server. Now I was making the transition to JSF 2.0, but the error messages seem to be back to German. Localized error messages are a real pain if you want to google up anything (I have no idea who decided localized error messages to be a good thing BTW!).
Here's the faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<!-- view handler only for JSF 1.2 -->
<!--view-handler>com.sun.facelets.FaceletViewHandler</view-handler-->
<locale-config>
<default-locale>en</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>en_US</supported-locale>
</locale-config>
</application>
</faces-config>
I'm using JSF 2.0.3 as shipped with JBAS 6, plus Seam and RichFaces.
Does anyone know how to get error messages in English language? Maybe config from the deployer or JBAS 6 itself?
Edit: the error messages appear at server startup as launched from inside Eclipse.
The message comes from your container, not from JSF.
You can change your regional settings or add the JVM parameter -Duser.language=en when you start the container.

Resources