How to integrate tucky URL rewrite with Angular and Tomcat 7 - url-rewriting

iam using a Tomcat 7 server and copied my angular 5 project into the ROOT directory. Deep links does not work at the moment. I have tried to use tucky URL rewrite.
I created a WEB-INF folder in the ROOT directory. Therein i created a folder named lib and saved the file "urlrewritefilter-4.0.3 .jar" there.
The WEB-INF folder also contain a urlrewrite.xml file and a web.xml.
I hope that someone may help me to solve this issue.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<!--
Configuration file for UrlRewriteFilter
http://www.tuckey.org/urlrewrite/
-->
<urlrewrite>
<rule match-type="regex">
<note>
Redirect all http requests to angulars index. html except /tcc/* cause its needed for backend operations
</note>
<condition name="request-uri" operator="notequal">^/tcc/*</condition>
<from>^.*$</from>
<to type="permanent-redirect" last="true">http://localhost:8080</to>
</rule>
</urlrewrite>
web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>

I was not able to get Tucky to run. I changed the routing method of Angular to the # routing to fit my needs. Another working aproach to get this running is to update to tomcat 8 and use the inbuild mechanisms.

Related

Lucee Not Serving index.cfm By Default

I have a dev machine running Lucee with Tomcat on Mac OS X El Capitan. Lucee is running fine, but when I bring up my dev site, mapped to admin.local, I have to type in "admin.local:8080/index.cfm". For some reason entering the URL as "admin.local:8080" just brings up a 404. Is there something I need to do to get Lucee/Tomcat to serve index.cfm by default?
UPDATE:
The web.xml for Tomcat does include the following:
<servlet-mapping>
<servlet-name>CFMLServlet</servlet-name>
<url-pattern>*.cfc</url-pattern>
<url-pattern>*.cfm</url-pattern>
<url-pattern>*.cfml</url-pattern>
<url-pattern>/index.cfc/*</url-pattern>
<url-pattern>/index.cfm/*</url-pattern>
<url-pattern>/index.cfml/*</url-pattern>
<!-- url-pattern>*.cfm/*</url-pattern !-->
<!-- url-pattern>*.cfml/*</url-pattern !-->
<!-- url-pattern>*.cfc/*</url-pattern !-->
<!-- url-pattern>*.htm</url-pattern !-->
<!-- url-pattern>*.jsp</url-pattern !-->
</servlet-mapping>
In order for your web server to handle the index.cfm files without specifying it in the URL you will need to add that as a default document for your web server. You mentioned you are using Apache, one approach for that web server is to add index.cfm to the DirectoryIndex within the httpd.conf file.
Here is an example of how to do that - https://stackoverflow.com/a/7977774/1636917
I just added index.cfm to welcome file list in web.xml, it helps
<web-app ...
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.cfm</welcome-file>
</welcome-file-list>
</web-app>

How to set Spring root context path

I am a Spring newbie and am putting together a Spring web-app (not Spring-boot - how much difference does this make?). Deployment is on a Tomcat 7 server.
The app is up and running. My problem is that is only accessible via the standard URL:
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT/index.html
The following do not work:
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT
http://mycompany.com:8081/cwing-0.0.3-SNAPSHOT/
even though my web.xml lists index.html as the welcome page.
An additional symptom of the problem is that all sorts of links within the application need to be specified as relative, rather than with a prepended '/'.
But even these urls are not what I really want.
I would rather specify
http://mycompany.com:8081/cwing
and have it bring up the index.html.
Following the lead of Add context path to Spring Boot application
I created an application.xml file in src/main/resources with the following content:
server.contextPath=/cwing
server.port=8081
This doesn't work. http://mycompany.com:8081/cwing brings up a blank page, with a 404 error on the server, as does http://mycompany.com:8081/cwing/index.html.
I must be missing something. What else is needed to get this to work as I want it to work?
UPDATE: as asked, here is the web.xml (irrelevant details removed).
<?xml version="1.0"?>
<web-app 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"
version="3.0">
<display-name>cwing</display-name>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/context.xml
/WEB-INF/spring/datasource.xml
/WEB-INF/spring/security.xml
</param-value>
</context-param>
<servlet>
<servlet-name>d</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/context.xml
/WEB-INF/spring/datasource.xml
/WEB-INF/spring/security.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>d</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Disables Servlet Container welcome file handling. Needed for compatibility
with Servlet 3.0 and Tomcat 7.0 -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<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>
...
</web-app>
This is not related to Spring MVC but to specific server, by default Tomcat gets your WAR name as context root. If you want to change this, you can always rename your WAR file or I recommends to change your pom.xml to build your WAR file with final name, here is how to do this:
<build>
<finalName>finalName</finalName>
. . .
</build>

http status 404 hello.jsp (apache tomcat 6)

im new to using apache and spring framework and i've been using this tutorial for learning: http://docs.spring.io/docs/Spring-MVC-step-by-step/part1.html
i made an .jsp file however my browser tells me "The requested resource is not available."
the .jsp file is pretty simple
<html>
<head><title>Hello :: Spring Application</title></head>
<body>
<h1>Hello - Spring Application</h1>
<p>Greetings.</p>
</body>
</html>
entering http://localhost:8080/project/hello.htm gives me a 404.
my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<servlet>
<servlet-name>project</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>project</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
any idea how to fix this?
404 error means the requested resource is not in the server.
Your problem can be either
1. Not properly matching hello.htm to any controller
bean id="/hello.htm" class="foo.controller" or
2. You have to put your hello.jsp in webcontent folder, along with index.jsp. Not in WEB-INF folder. Refer tutorial.

Cannot access my application on Heroku - no context path

For the last two days I was struggling to get my Struts2 application (just one simple page for testing - no database or anything fancy for now) up and running on Heroku with Jetty Runner. I finally did it - it deployed successfully, however there is an error when I try to access it.
On my local development machine I access my app (named TestMaven) like this:
http://localhost:8080/TestMaven/
And it works. However when I try to access my app on Heroku (myappname.herokuapp.com) I get this error:
There is no Action mapped for namespace [/] and action name [] associated with context path [].
This looks like Heroku has no idea about context path which is TestMaven.
This is 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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>Nebula</display-name>
<context-param>
<param-name>org.apache.tiles.definition.DefinitionsFactory.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>
<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>
</web-app>
And struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="front" extends="struts-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="" class="com.eleeist.TestMaven.action.Index">
<result name="success" type="tiles">/index.tiles</result>
</action>
</package>
</struts>

Apache CXF and Spring but no WSDL (recursive links)

I have written a small sample web service, using Apache CXF (CXFServlet) and Spring (ContextLoaderListener) I have registered the CXFServlet to listen on the / url. And I am declaring my beans in beans.xml.
When I start the web service with tomcat and go to the service url, then I can see the web service definition (e.g. methods, endpoint, wsdl link). But the problem is that when I click on the wsdl link, then I do not get the WSDL file, but instead I am recursively forwarded back to the same page, but each time the name of the web service address is appended:
localhost:8080/Test/accountEndpoint
localhost:8080/Test/accountEndpointaccountEndpoint
localhost:8080/Test/accountEndpointaccountEndpointaccountEndpoint
The service is a "code-first" service which a #WebService annotated java interface and a implementation class.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Test</display-name>
<servlet>
<servlet-name>cxf</servlet-name>
<display-name>cxf</display-name>
<description>Apache CXF Endpoint</description>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
beans.xml
<?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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<bean id="account" class=".....AccountImpl" />
<jaxws:endpoint id="accountEndpoint" implementor="#account"
address="accountEndpoint" />
</beans>
As I understand it, CXF should automatically generate the WSDL file and provide it to me, when I click on the link, so I do not understand why that is not happening.
Specify the address this way, with a leading slash:
<jaxws:endpoint id="accountEndpoint" implementor="#account"
address="/accountEndpoint" />
Sorry, making a change, the above is not correct:
You are right, I am able to replicate the behavior with mapping CXFServlet to the "default" servlet path mapping of /, the fix that I could get to work for myself is to map it to /* instead:
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

Resources