how do i override the url-pattern in a struts servlet mapping? - struts

I am using Struts 1.2.7 and have the standard servlet mapping that uses *.do for my URLs.
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
I need to have a few custom URLs that do not use .do at the end, e.g., /monitor/lb-healthcheck. Is there a way to override the mapping, or add these specific paths to the web.xml file to map to specific Actions? This is a mature application, and it's not feasible at this point to change the mapping to / as the url-pattern.

Have you try adding a mapping just before that action mapping?
<servlet-mapping>
<servlet-name>monitor</servlet-name>
<url-pattern>/monitor/lb-healthcheck</url-pattern>
</servlet-mapping>

Related

Swagger UI integration with Camel ...not able to access index.html on port

I'm using Camel to integrate Swagger. I downloaded dist folder renamed to swagger and updated index.html but I'm not able to access ui it through my application port: http://localhost:${port}/${contextPath}/swagger/index.html
but if I type http://localhost:${port}/api-doc, I get the swagger json dump.
I can access index.html if go to the file and open it manually with browser. How do i access index.html using my application port?
http://localhost:${port}/${contextPath}/swagger/index.html
You need to expose an endpoint that would return your index.html file. Try adding the following to your RouteBuilder:
rest("/swagger")
.produces("text/html")
.get("/index.html")
.responseMessage().code(200).message("Swagger UI").endResponseMessage()
.to("direct://get/swagger/ui/path");
from("direct://get/swagger/ui/path")
.routeId("SwaggerUI")
.setBody().simple("resource:classpath:/swagger/index.html");
The first route defines a restful endpoint /swagger/index.html that accepts a GET request and returns text/html.
The second route uses Camel's Simple component to read the actual index.html into the Exchange Message Body.
So if you go to localhost:${port}/${contextPath}/swagger/index.html, it should load the index.html file correctly.
Note that inside indext.html you need to substitute the URL that would return the JSON dump of your API so that the Swagger UI can render it.
I am using Camel Jetty as the REST component. For jetty you just need add an additional ResourceHandler to handle SwaggerUI resource. Below using Spring xml language to configure REST:
<restConfiguration component="jetty" host="{{rest_hostname}}" port="{{rest_listen_port}}"
bindingMode="off" apiContextPath="api-docs" apiContextListing="true"
enableCORS="true">
<!--ResourceHandler to handle Swagger UI contents on the jetty-->
<endpointProperty key="handlers" value="swaggerUIHandler"/>
......
......
</restConfiguration>
I use swaggerUI in a jar provided by webjars. Configure handler bean:
<bean id="swaggerUIHandler" class="com.yifanwu.examples.camel.JettyResourceHandlerFactory" factory-method="buildResourceHandler">
<!--your resource path is just "swagger" assuming it is on the classpath-->
<constructor-arg name="resourcePath" value="META-INF/resources/webjars"/>
</bean>
Bean factory:
public class JettyResourceHandlerFactory {
public static ResourceHandler buildResourceHandler(String resourcePath) throws Exception {
ResourceHandler rh = new ResourceHandler();
rh.setResourceBase(JettyResourceHandlerFactory.class.getClassLoader()
.getResource(resourcePath)
.toURI().toString());
return rh;
}
}
Full example Here: github
An easier solution would be to add a web.xml file, move your resources to your /webapp directory, adding the following filter in web.xml
<filter>
<filter-name>RestSwaggerCorsFilter</filter-name>
<filter-class>org.apache.camel.swagger.servlet.RestSwaggerCorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RestSwaggerCorsFilter</filter-name>
<url-pattern>/api-docs/*</url-pattern>
<url-pattern>/rest/*</url-pattern>
</filter-mapping>
See the Camel Swagger documentation for details: http://camel.apache.org/swagger-java.html

Create Registration form in Mule

I am a newbie to MuleESB. I want to create a registration form using Mule but I am stuck.
I don't know how to display index.jsp on start-up of your application. I already gone through BookStore example but couldn't get efficient information.
I created a web.xml under src->main->app->webapps->WEB-INF->web.xml
*<web-app....>
<listener>
<listener-class>org.mule.config.builders.MuleXmlBuilderContextListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>*
Any Help or suggestions.
You're missing a web application context directory under: src->main->app->webapps->WEB-INF->web.xml, ie you should have something like: src->main->app->webapps->my-context->WEB-INF->web.xml.
Follow the BookStore example carefully and you should have no difficulty reaching your goal.

GWT Fileupload Using Servlet with GUICE

We are using GWTP with Guice. I want to upload a file. For that I have written a Servlet.
I am using this GWT File UPload Example. But Servlet is not getting called. I think its the problem with GuiceFilter.
Below is my web.xml entry.
Web.xml
<listener>
<listener-class>com.nextenders.server.guice.GuiceServletConfig</listener-class>
</listener>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>FileUploadServlet</servlet-name>
<servlet-class>com.nextenders.server.guice.actions.FileUploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FileUploadServlet</servlet-name>
<url-pattern>/upload/fileUpload</url-pattern>
</servlet-mapping>
Any pointers would be great help.
If you're using Guice, you mush use Guice ServletModule class to set up your servlets.
Ex:
serve("/upload/pictures").with(PictureUploader.class);
Documentation:
http://code.google.com/p/google-guice/wiki/ServletModule
Cheers,
I found out the problem and solved on my own.
Here is the answer:
It was not the problem with the GUICE Servlet Filter.
The problem was with Coade statements placing. FileUpload com.google.gwt.user.client.ui.FileUpload should be used with FormPanel.
FileUpload must be used with FormPanel if it is to be submitted to a server.
I had used GWT file upload earlier but skipped thorough my mind.

url rewriting in Struts1

I am developing a web application using Struts1 as web framework. My url pattern in web.xml is:
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
I want to get rid of .do pattern in urls. So if my url is
http://localhost:38330/MyProject/editFunction.do?function=1
i want it to be like http://localhost:38330/MyProject/editFunction/ . How do I acheive this type of url rewriting ?
Thanks for any help
You can use a filter before calling the struts request processor, and this project it's very helpful: http://www.tuckey.org/urlrewrite/
You can map your <url-pattern> to allow prefix, like
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>/action/*</url-pattern>
</servlet-mapping>
Then if you do (e.g.) http://localhost:38330/MyProject/action/editFunction/, your struts action will be called (if mapped correctly on struts-config.xml).

Velocity framework servlet

I have a module written in servlets and needs to be recently moved to velocity framework
So in the process I am rewriting the web.xml to create velocity servlet object whcih calls
our original servlet .
Now if this has to be moved to
<servlet>
<servlet-name>VeloServlet</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
</servlet>
How can we acheive this and what are all changes need to use the existing servlet as it is.
My Existing servlet looks like
<servlet-name>DataBridgeServlet</servlet-name>
<servlet-class>com.jda.pwm.databridge.framework.common.DataBridgeServlet</servlet-class>
<init-param>
<param-name>jda.databridge.config.path</param-name>
<param-value>d:/usr/databridge/conf</param-value>
</init-param>
This is loaded using the url http://localhost:8080/databridge/databridgeservlet
So in the newer case how velocity servlet calls this servlet
Have you looked at the VelocityViewServlet in the Velocity Tools project? This is a useful way of quickly getting Velocity pages on the web.
http://velocity.apache.org/tools/devel/view.servlet.html
You can subclass this for more customizability if desired. And if nothing else, you can look at the source and use this as inspiration to make your own servlet.
You should take a look at: jpublish.org (I am the maintainer, therefore biased :) and replace your Servlet with a simple Action; scripting (BSH, JS) or Java, as you feel fit. My 0.2CAD