Struts2 convention plugin (m2eclipse/geronimo) - struts2

Using convention-plugin seems really easy but im not able to make it work :(
I'm using struts2 version 2.2.3
I have a package named com.medicis.actions with a UserAction extending ActionSupport.
I don't have any struts.xml file
I have the convention-plugin depency set on my maven configuration (i also checked the generated war file)
There is my web.xml :
<display-name>Starter</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
<!-- Filters -->
<filter>
<filter-name>action2-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter>
<filter-name>action2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>action2-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jspSupportServlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>5</load-on-startup>
</servlet>
<!-- Welcome file lists -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
I tried with and without the init param for the action2 filter:
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.medicis.actions</param-value>
</init-param>
I have this property set on my struts.propertie file :
struts.action.extension=action
Still i'm unable to launch my action using localhost:8080/starter/user.action :
There is no Action mapped for namespace / and action name user
I really don't know what's going wrong, I even downloaded a simple example without any result either.
Could it be a configuration problem due to eclipse, m2eclipse, maven wtp or geronimo ???
If you need more information just tell me and i'll provide you that asap.

Create struts.properties in "src" folder
Copy and paste code from below:
struts.convention.package.locators = actions
struts.convention.action.suffix = Controller
struts.convention.action.mapAllMatches = true
Create class called IndexController in com.example.actions
Copy and paste code from below:
package com.example.actions;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import com.opensymphony.xwork2.ActionSupport;
public class UserController extends ActionSupport {
public String index(){
return SUCCESS
}
}
You also need to create jsp file in WEB-INF/content/user/index.jsp

Related

Wicket error pages not working

Problems with error pages in the Wicket.
We use the Wiket(8.0.0-M8) and spring security(4.2.3.RELEASE).
I have an idea about how to set up my error pages, but standard pages also do not work (I get error pages tomcat, instead of mine).
getApplicationSettings().setInternalErrorPage(InternalErrorPage.class);
getApplicationSettings().setAccessDeniedPage(AccessDeniedPage.class);
The peculiarity is that the page 500 (Internal Error) can be specified. But the rest do not.
Spring Security does not have a page 403 (access denied page), and if you specify in spring and mountPage in the Wicket, it will send to 404.
How to declare 404 is also not entirely clear.
UPD: web.xml:
<display-name>project</display-name>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>transactionFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>transactionFilter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>transactionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>wicket.project</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationFactoryClassName</param-name>
<param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>
</init-param>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>ru.company.project.web.WicketApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>wicket.project</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Here is how to do it with Spring Boot:
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.boot.web.servlet.ErrorPageRegistrar;
import org.springframework.boot.web.servlet.ErrorPageRegistry;
import org.springframework.http.HttpStatus;
public class MyErrorPageRegistrar implements ErrorPageRegistrar {
#Override
public void registerErrorPages(final ErrorPageRegistry registry) {
registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,
MyApplication.PAGE_NOT_FOUND_MOUNT_PATH));
}
}
In MySpringConfiguration.java:
#Bean
public ErrorPageRegistrar errorPageRegistrar(){
return new MyErrorPageRegistrar();
}
In MyApplication.java:
String PAGE_NOT_FOUND_MOUNT_PATH = "/not/found";
...
#Override public void init() {
super.init();
...
mountPage(PAGE_NOT_FOUND_MOUNT_PATH, Error404Page.class);
}

Trouble integrating prettyfaces with jsf

I need to integrate pretty faces with my jsf 2.0, primefaces application, but its giving some troubles.
As mentioned in the getting started i placed following in my web.xml, added the required jar in the lib folder
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
other items in my web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>org.primefaces.extensions.DELIVER_UNCOMPRESSED_RESOURCES</param-name>
<param-value>false</param-value>
</context-param>
But i am getting following Error:
Invalid content was found starting with element 'async-supported'. One of '{"http://java.sun.com/xml/ns/javaee":init-param}' is expected
If i remove <async-supported> from the project builds, project compiles but the mapping doesnt work.
pretty-config.xml is same as in the getting started.
Do i need to mention in my web.xml the name/path of the mapping file i.e pretty-config.xml?
EDIT:
I am using Glassfish server 3.
It is very important to check the version attribute you are using in your web.xml. If you have version="2.5" set, you have to add this to your web.xml:
<filter>
<filter-name>Pretty Filter</filter-name>
<filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Pretty Filter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
Please not that <async-supported>true</async-supported> is NOT set here, because it is only supported in Servlet 3.0.
If you have version="3.0" set in your web.xml, you don't have to add anything to your web.xml. In this case PrettyFaces automatically registers the filter using the web-fragment.xml that is included in prettyfaces-jsf2.jar.
You don't have to specify the location of pretty-config.xml anywhere. Just place it in your WEB-INF folder and PrettyFaces will find it.
You should also add one mapping to your pretty-config.xml, so you can check if everything works correctly. If you have for example a page that you typically access using an URL like:
http://localhost:8080/myapp/faces/login.xhtml
Then you can add this mapping:
<url-mapping id="login">
<pattern value="/login" />
<view-id value="/faces/login.xhtml" />
</url-mapping>
Now you should be able to access the page using this link:
http://localhost:8080/myapp/login

Jruby rails application on Tomcat. War generated through warbler

I am using warbler to create war of my Jruby application. It creates a war without any problem, but when I deploy it in tomcat (webapps) it gives me following exception:
SEVERE: Parse error in application web.xml file at jndi:/localhost/POC_Rails_1_3_1_/WEB-INF/web.xml
org.xml.sax.SAXParseException: Comment must start with "<!--".
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1231)
Generated (WEB-INF/web.xml) is below. Let me know if I have forgotten to configure something.
<!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>public.root</param-name>
<param-value>/</param-value>
</context-param>
<context-param>
<param-name>rails.env</param-name>
<param-value>developement</param-value>
</context-param>
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener>
</web-app>
<!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>public.root</param-name>
<param-value>/</param-value>
</context-param>
<context-param>
<param-name>rails.env</param-name>
<param-value>developement</param-value>
</context-param>
<filter>
<filter-name>RackFilter</filter-name>
<filter-class>org.jruby.rack.RackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RackFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.jruby.rack.rails.RailsServletContextListener</listener-class>
</listener>
</web-app>
As the first commentor mentioned the xml is invalid because of duplicate <web-app> and <!DOCTYPE. The parser error is related to <!. <! is meant for declaring documenttype and it can appear only before the start of the root element. Any subsequent appearances will be treated as start of a comment. And the comment needs -- after <!

Accessing second servlet when grails is configured in web.xml

How can you have a grails application as well as other servlets defined in your web.xml?
I want to have it so that some url patterns are handled by a servlet while all others are handled by Sitemesh/grails.
The default configuration of web.xml generated by grails is:
<filter-mapping>
<filter-name>charEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>grailsWebRequest</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>urlMapping</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>grails</servlet-name>
<servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
I then added the configuration to web.xml for my 2nd servlet:
<servlet>
<servlet-name>Tracepoints</servlet-name>
<servlet-class>com.mydomain.Tracepoints</servlet-class>
<init-param>
<param-name>hostName</param-name>
<param-value>http://www.mydomain.com/</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Tracepoints</servlet-name>
<url-pattern>*.tpoints</url-pattern>
</servlet-mapping>
But the above doesn't allow me to access my non grails servlet (with the url: domain.com/hello.tpoints) and trying it gets me a 404. I do know that the servlet's class files are deployed with the war because they exist in WEB-INF/classes directory.
You need to give the Grails servlet a more specific url-pattern in the mapping, e.g. /grails/* or *.grails or so (you're free to choose), so that only the URL's matching those patterns invokes the Grails servlet.

Velocity + Struts2 + Sitemesh + Spring +Hibernate Integration How to configur web.xml?

I needed to create an application using Struts2 as MVC,Hibernate for data access and spring in the business logic.
And also I needed to use Velocity for presentaion and sitemesh for templating.
Integrating Hibernate and Spring is done easily but integrating spring, sitemesh and velocity together with Struts2
is not clear for me but I can use velocity,spring and sitemsh individually with Struts2.
Of course as illustrated in this example http://www.rkcole.com/articles/struts/crudTutorial/step4.html
sitemesh and spring can be integrated with struts2 configuring web.xml as
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Now my task is to integrate velocity with this combination...............
Normally to integrate Velocity and struts2 I use the following
<servlet-class>
org.apache.velocity.tools.view.servlet.VelocityViewServlet
</servlet-class>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
.............................................................................................
Now my question is how to set `
<servlet-mapping>
`, its only for velocity, or simemesh or has to be set differently
Please let me know how to proceed,if can please reply with complete web.xml and others steps to be followed.
Regards
T.Thamilvaanan
Ya, finally I got this web.xml after lots of reading and searching............
<?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">
<!-- A part in Spring Integration-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
</context-param>
<!-- All the filters starts here-->
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.StrutsPrepareFilter</filter-class>
</filter>
<!-- This is used to integrate sitemesh with Struts2-->
<!--
I am using Velocity to create sitemesh decorators so I have to use
VelocityPageFilter to integrate
Sitemesh (i.e. Sitemesh in velocity) + Struts2
In the web.xml, the VelocityPageFilter should be placed between the
ActionContextCleanUp (StrutsPrepareFilter since 2.1.3 ) and
and the FilterDispatcher (StrutsExecuteFilter since 2.1.3)
-->
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.apache.struts2.sitemesh.VelocityPageFilter</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring Integration-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--Finally since I am velocity pages in struts2 MVC I am using
VelocityViewServlet to Integrate struts2 with Velocity -->
<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>org.apache.velocity.tools.view.VelocityViewServlet
</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/tools.xml</param-value>
</init-param>
<init-param>
<param-name>org.apache.velocity.properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param>
</servlet>
<!-- Map *.vm files to Velocity -->
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.vm</welcome-file>
</welcome-file-list>
</web-app>
Hope this is fine,will test and let you know.
Cheers............
Regards
Thamilvaanan

Resources