Struts2 and Comet url pattern conflict - url

I am trying to integrate comet chat into my struts2+hibernate application .First I have tested comet chat in separate web application. It works fine .Ihave download it from http://skillshared.blogspot.in/2012/10/facebook-similar-chat-for-your-java-web.html after then I try to implement in my application
My problem in web.xml here is my web.xml file
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<display-name>Cometd Test WebApp</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Portability Filter, needed only to run on non Jetty
or non Servlet-3.0 containers like Tomcat-->
<filter>
<filter-name>continuation</filter-name>
<filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>continuation</filter-name>
<url-pattern>/cometd/*</url-pattern>
</filter-mapping>
<!-- Cometd Servlet -->
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.annotation.AnnotationCometdServlet</servlet-class>
<init-param>
<param-name>timeout</param-name>
<param-value>20000</param-value>
</init-param>
<init-param>
<param-name>interval</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>maxInterval</param-name>
<param-value>10000</param-value>
</init-param>
<init-param>
<param-name>maxLazyTimeout</param-name>
<param-value>5000</param-value>
</init-param>
<init-param>
<param-name>long-polling.multiSessionInterval</param-name>
<param-value>2000</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>transports</param-name>
<param-value>org.cometd.websocket.server.WebSocketTransport</param-value>
</init-param>
<init-param>
<param-name>services</param-name>
<param-value>com.semika.cometd.ChatService</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
from above code application works fine but chat not working. I saw so posts regarding this problem , I have a solution
<URL-pattern>*.action</URL-pattern>
when I am trying to do this chat works fine but application doesn't work. When I have place application only working.
<url-pattern>/*</url-pattern>
I have tried this one also in struts.xml but no use.
<constant name="struts.action.excludePattern" value="/cometd/*,/cometd/.*"/>
What can be the cause of the problem ?

The whole thing depends on your Struts version. If you have an old version, you should migrate to a new version for many reasons, especially security fixes.
However, considering that:
With Struts >= 2.1.3, the FilterDispatcher is deprecated, and the new StrutsPrepareAndExecuteFilter must be used. Read more
With Struts <= 2.1.6, the struts.action.excludePattern doesn't exist. Read more
your code can't possibly work ;)

Related

JFrog Artifactory tfs integration. Build info page "JFrog Artifactory" tab page shows "Loading..." forever.

Please take a look at scenario I've writen here: https://github.com/jroquelaure/jfrog-vso-extension/issues/3
is there any workaround?
This page uses Ajax to call the REST API and display the build info, therefore, you have to enable CORS requests on the reverse proxy or tomcat of your Artifactory server.
To enable it in your tomcat, add the following to $TOMCAT_HOME/webapps/artifactory/WEB-INF/web.xml:
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,OPTIONS,PUT,DELETE</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,accept,Origin,Authorization</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>10</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Deploy Grails 2.3.0 to Glassfish Server

I have an application build with Grails 2.3.0 and type command 'grails war' to generate a war file.
I type following command to deploy the application :
asadmin deploy APP_PATH/target/myapp.war
But I get the following error:
remote failure: Error occurred during deployment: Exception while deploying the app [myapp] : org.xml.sax.SAXParseException; lineNumber: 137; columnNumber: 15;
Deployment descriptor file WEB-INF/web.xml in archive [myapp]. cvc-complex-type.2.4.a: 從元素 'init-param' found invalid content。expect '{"http://java.sun.com/xml/ns/javaee":run-as, "http://java.sun.com/xml/ns/javaee":security-role-ref, "http://java.sun.com/xml/ns/javaee":multipart-config}'。. Please see server.log for more details.
I use Grails 2.3.0 and get the same error on both Glassfish 3.1.2.2 and Glassfish 4.
How can I fix this error ?
Any help would be appreciate.
-- Update
I use grails command "grails install-templates" to generate web.xml, and move web.xml to web-app/WEB-INF, but still got the same error message. Following is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
metadata-complete="true"
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_3_0.xsd">
<display-name>/#grails.project.key#</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>#grails.project.key#</param-value>
</context-param>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter</filter-class>
</filter>
<filter>
<filter-name>charEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>characterEncodingFilter</param-value>
</init-param>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>charEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<listener>
<listener-class>org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener</listener-class>
</listener>
<!-- Grails dispatcher servlet -->
<servlet>
<servlet-name>grails</servlet-name>
<servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
<init-param>
<param-name>dispatchOptionsRequest</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<!-- The Groovy Server Pages servlet -->
<servlet>
<servlet-name>gsp</servlet-name>
<servlet-class>org.codehaus.groovy.grails.web.pages.GroovyPagesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>gsp</servlet-name>
<url-pattern>*.gsp</url-pattern>
</servlet-mapping>
<session-config>
<!-- 30 minutes -->
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<!--
The order of the welcome pages is important. JBoss deployment will
break if index.gsp is first in the list.
-->
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.gsp</welcome-file>
</welcome-file-list>
</web-app>

Using PrettyFaces 3.3.1-SNAPSHOT

i downloaded the 3.3.1-SNAPSHOT version to make generic url
regarding this post:
Pretty Faces: Generic URL mapping
my configuration is as follows:
my web.xml:
<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>myapp</display-name>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:META-INF/spring/applicationContext.xml
classpath:META-INF/spring/applicationSecurity.xml
</param-value>
</context-param>
<!-- Activating the Expression Language -->
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<welcome-file-list>
<welcome-file>users</welcome-file>
</welcome-file-list>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- Spring Security -->
<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>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<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>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>/icefaces/*</url-pattern>
</servlet-mapping>
</web-app>
my pretty-config.xml:
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.0
http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.0.xsd">
<url-mapping id="generic">
<pattern value="/*" />
<view-id value="/faces/$1.xhtml" />
</url-mapping>
</pretty-config>
the following line keeps repeating in terminal:
at com.ocpsoft.pretty.faces.config.annotation.WebClassesFinder.processDirectory(WebClassesFinder.java:183)
at
Mika,
This is not something that PrettyFaces supports using the URL-mapping construct, you must instead use a custom rewrite rule:
<rewrite match="/(.*)" substitute="/faces/$1.xhtml" />
However, consider the impact of such a rule (similar to the one you defined above.) Of course there will be an infinite loop, because "*" also matches "/faces/XXX.xhtml". You need to make your match pattern more restrictive.
<rewrite match="^/(.*)(?<!\.xhtml)$" substitute="/faces/$1.xhtml" />
I also suggest you read up on Regular expressions, because "/*" is not a regular expression that will do what you seem to think it will do: http://ocpsoft.com/opensource/guide-to-regular-expressions-in-java-part-2/#lookaround
However, if you want a URL-rewriting tool which was designed specifically to perform tasks like this, then I suggest you look at OCPsoft Rewrite: http://ocpsoft.com/rewrite/, a much more powerful (but more difficult to use) URL-rewriting tool.
It allows you to do things like this:
.addRule(Join.path("/{page}")
.to("/pages/{page}.xhtml")
.when(Resource.exists("/pages/{page}.xhtml"))
.where("page").matches("(?!RES_NOT_FOUND)[^/]+"))

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