Disable directory listing in jetty - webserver

I am using jetty to deploy my web application. I have changed the webdefault.xml dirAllowed parameter to false, still jetty is listing all the contexts path inside it whenever I will give IP:PORT.
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
Thanks in advance.

Don't modify the webdefault.xml directly, you have to provide your own copy of it, and specify its location in your context xml deployable ${jetty.base}/webapps/UserManagement.xml.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"
"http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="testWebapp" class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/UserManagement</Set>
<Set name="war">
<Property name="jetty.webapps"/>/UserManagement.war
</Set>
<Set name="defaultsDescriptor">
<Property name="jetty.base"/>/etc/mywebdefault.xml
</Set>
</Configure>
A simpler solution is to modify your WEB-INF/web.xml in your UserManagement.war as outlined in the previous answer ...
https://stackoverflow.com/a/43328817/775715

Related

Camel REST - Path based routing

I have to develop a Camel REST route with path-based routing.
The scenario is as follows: we have a business partner which provided a REST web service for displaying documents. The REST web service is deployed on 3 different servers, depending on the geographic location.
So we basically have 3 server like these:
http://north.acme.com/flowdocv2/rest/repository/attachment/{id}/findById
http://center.acme.com/flowdocv2/rest/repository/attachment/{id}/findById
http://south.acme.com/flowdocv2/rest/repository/attachment/{id}/findById
My aim is to develop a single Camel route to map these server, accepting the name of the server in the path. Something like this:
http://my.camel.com/center/repository/attachment/{id}/findById
http://my.camel.com/north/repository/attachment/{id}/findById
http://my.camel.com/south/repository/attachment/{id}/findById
My (simplified and not working) blueprint.xml:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<cm:property-placeholder persistent-id="my.config.file"/>
<reference id="sharedNettyHttpServer" interface="org.apache.camel.component.netty4.http.NettySharedHttpServer"/>
<camelContext id="my_context" xmlns="http://camel.apache.org/schema/blueprint">
<restConfiguration component="netty4-http">
<endpointProperty key="nettySharedHttpServer" value="#sharedNettyHttpServer"/>
</restConfiguration>
<rest path="/center/repository">
<get uri="/attachment/{attachmentId}/findById">
<route streamCache="true" trace="true">
<to uri="http://center.acme.com/flowdocv2/rest?bridgeEndpoint=true"/>
</route>
</get>
</rest>
<rest path="/north/repository">
<get uri="/attachment/{attachmentId}/findById">
<route streamCache="true" trace="true">
<to uri="http://north.acme.com/flowdocv2/rest?bridgeEndpoint=true"/>
</route>
</get>
</rest>
</camelContext>
</blueprint>
The problem is that I don't know how to remove /center, /north or /south from the path, so the header is forwared to the destination service, which doesn't know how to deal with it.
Invoking:
http://my.camel.com/center/repository/attachment/{id}/findById
results in the following URL being invoked on the destination server:
http://center.acme.com/flowdocv2/rest/center/repository/attachment/{id}/findById
How to get rid of center? I don't want to deploy 3 camel routes on different ports.
Thank you
I think it is actually a bit easier. As long as you do not hang onto netty and you are using Camel 2.11+ you can use camel-urlrewrite
Basically, you define a single rewrite rule in a configuration and add this to your route bundle.
<?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">
<urlrewrite>
<rule>
<name>Generic Proxy</name>
<note>
This rule completely rewrites the url to call.
Basically, in Camel's "to", you could write whatever you want
</note>
<from>^/(.*?)/(.*)</from>
<to>http://$1.acme.com/flowdocv2/rest/$2</to>
</rule>
</urlrewrite>
Now, you can utilize a rather simple route:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="myRewrite" class="org.apache.camel.component.urlrewrite.HttpUrlRewrite">
<property name="configFile" value="class/path/to/proxyrewrite.xml" />
</bean>
<camelContext id="my_context" xmlns="http://camel.apache.org/schema/blueprint">
<route id="proxyRoute">
<from uri="jetty:http://localhost:9090/proxy" />
<to uri="jetty:http://somewhere/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite" />
</route>
</camelContext>
</blueprint>
However, netty is not supported, so I chose the next best thing.
When you call http://localhost:9090/proxy/north/foo, the rewrite will actually change the url to call to http://north.acme.com/flowdoc2/rest/foo.
There are a few caveats with this. First, you have to use one of the supported components for UrlRewrite. Second, it seems that you have to have the rewrite config file in you classpath - so no blueprint-only route. Third: I did not test it, but I think you get the gist. I make this a community wiki answer, so that others, more capable than me, can expand on this answer.

Rest DSL restConfiguration way to dynamically inject Jetty port from jetty.xml

can you dynamically inject the port set in the jetty.xml config file?
I have multiple jboss fuse containers running, each has a different configuration of ports from rmiRegistryPort, to jetty.port. I would like to be able to just inject the port value from the jetty.xml. if i am using camel-jetty, do I need to worry about setting the port as it automatically takes if from this file???
restConfiguration()
.component("jetty")
.host("localhost")
.port(getPort())
.scheme("https")
.bindingMode(RestBindingMode.json)
.jsonDataFormat("json-jackson")
.dataFormatProperty("prettyPrint", "true");
I don't know myself, but the Camel REST DSL Docs say:
if you use servlet component then the port number configured here does not apply, as the port number in use is the actual port number the servlet component is using, e.g., if using Apache Tomcat its the tomcat HTTP port, if using Apache Karaf it's the HTTP service in Karaf that uses port 8181 by default etc. Though in those situations setting the port number here, allows tooling and JMX to know the port number, so its recommended to set the port number to the number that the servlet engine uses.
Based on this description I assume that:
Camel uses the actual jetty HTTP endpoint
Whatever port you set in the restConfiguration it is ignored for the jetty HTTP endpoint
JMX and other tools only work correct if you set the correct port in the restConfiguration
You have to provide the correct jetty port for the restConfiguration (no auto-magic)
You can use the port value inside an application.properties and read it to set the value.
thanks Victor, yeah, ... I was just wondering if there is some magic under the covers with the Jetty server, I will need to test this out I guess.
since there is a jetty.xml config file under etc/jetty.xml that defines the jetty config... but in every example I see the defining of a port ... it looks like it is possible if enabled ??? but I don't know. reason is I have 8 different JBoss Fuse containers running all having different etc/configs to keep from port conflicts.
inside jetty.xml
<!-- =========================================================== -->
<!-- Special server connectors -->
<!-- =========================================================== -->
<!-- This is a sample for alternative connectors, enable if needed -->
<!-- =========================================================== -->
<!--
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server">
<Ref refid="Server" />
</Arg>
<Arg name="factories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
<Arg name="config">
<Ref refid="httpConfig" />
</Arg>
</New>
</Item>
</Array>
</Arg>
<Set name="host">
<Property name="jetty.host" default="localhost" />
</Set>
<Set name="port">
<Property name="jetty.port" default="8285" />
</Set>
<Set name="idleTimeout">
<Property name="http.timeout" default="30000" />
</Set>
<Set name="name">jettyConn1</Set>
</New>
</Arg>
</Call>

How to expose activemq JMX MBeans via jboss web based jmx-console?

I have been trying to configure activemq such that the broker MBeans are available in jboss's web based jmx-console available at http://localhost:8080/jmx-console.
I have tried
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util" xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq- core.xsd">
<beans>
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true"
useShutdownHook="false">
<!-- Use the following to configure how ActiveMQ is exposed in JMX -->
<managementContext>
<!-- <managementContext createConnector="false" /> -->
<managementContext>
<MBeanServer>
<bean class="org.jboss.mx.util.MBeanServerLocator"
factory-method="locateJBoss" xmlns="" />
</MBeanServer>
</managementContext>
</managementContext>
</broker>
</beans>
When I deploy the war the piece of xml gives error
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'bean'.
Any idea how to make activemq MBeans integrate with jboss web based jmx-console?
Default settings with just createConnector=false won't work for me because jboss is configured to not use 1099 RMI port. LocateJboss factory-method call on org.jboss.mx.util.MBeanServerLocator is the only way (I know of) to get jboss MBeanServer handle.
According to the spring JMX doc, you could try something like this :
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="server">
<bean id="mBeanServerLocator" class="org.jboss.mx.util.MBeanServerLocator"
factory-method="locateJBoss" />
</property>
</bean>
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true"
useShutdownHook="false">
<!-- Use the following to configure how ActiveMQ is exposed in JMX -->
<managementContext>
<managementContext MBeanServer="exporter"/>
<!-- I am not sure what MBeanServer attribute is waiting for (a ref, an id, something else ...)-->
</managementContext>
</broker>

Alfresco Share: renaming label on workflow forms

I need to rename some labels on workflow forms. I think I've found the resource bundle that need to be edited. It's slingshot.properties file.
I changed values of workflow.field.message and workflow.field.comment to my preference and restarted Alfresco but nothing's changed. Did I miss something?
In $TOMCAT_HOME/webapps/share/WEB-INF/classes/alfresco/web-extension, create a new file called custom-slingshot-application-context.xml with the following content:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="mycustom.resources" class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>
<value>alfresco.web-extension.messages.mycustom</value>
</list>
</property>
</bean>
</beans>
In $TOMCAT_HOME/webapps/share/WEB-INF/classes/alfresco/web-extension/messages, create a file called mycustom.properties with the following content:
workflow.field.message=Whatever You Want
Restart Tomcat
Notes:
Please use something more descriptive than "mycustom" in both the
bean ID and the properties file name. This is just an example.
Create folders where they don't exist already.

The requested resource () is not available in sample spring mvc application

I'm new bee to spring. Just started my sample application in sprinv mvc. But, I can't able to view the page since it is showing "The requested resource () is not available." Cannot figure out where is the problem. I'm pasting the code below.
web.xml:
<?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>my</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>my</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
**
my-servlet.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean name="/index.html" class="mypackage.web.myController"/>
</beans>
**
MyController.java
**
package mypackage.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class myController implements Controller{
public ModelAndView handleRequest(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException{
String msg="Hello!!! I'm coming from Controller. You Catched me ";
ModelAndView mv = new ModelAndView("index");
mv.addObject("message",msg);
return mv;
}
}
index.jsp
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="i" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My First Application in Spring</title>
</head>
<body>
<p>Check Below</p>
<p>
<em>${message}</em>
</p>
</body>
</html>
It's almost configured correctly, so well done so far :-) There are a couple of minor problems here that are causing the problems you see. Firstly, the bean is currently defined with a lowercase m:
<bean name="/index.html" class="mypackage.web.myController"/>
Although this is allowed, it is not conventional, so Spring will not be able to find the correct bean without some additional configuration.
Also, it was not clear from the question which URL you are using, but it should be something of the form http://localhost:8080/<project>/myIndex.html
There is a good summary of the convention here.
So we have 2 options… either rename the class to MyController and save as MyController.java or modify the ControllerClassNameHandlerMapping bean to be case sensitive like so:
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="caseSensitive" value="true" />
</bean>
Furthermore, it is not the cause of the problem but if you use the ControllerClassNameHandlerMapping you can omit bean name, so you can just use:
<bean class="mypackage.web.MyController"/>
I guess the most annoying part is that the web application deploys without error. However if you examine the log, there is a marked difference:
Deployment of incorrectly configured webapp:
04-Jul-2011 09:13:58 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#5f0e7d: defining beans []; root of factory hierarchy
04-Jul-2011 09:13:58 org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'my': initialization completed in 157 ms
Deployment of correctly configured webapp:
04-Jul-2011 09:15:33 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#de537: defining beans [org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping#0,viewResolver,mypackage.web.MyController#0]; root of factory hierarchy
04-Jul-2011 09:15:49 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
INFO: Mapped URL path [/my*] onto handler 'mypackage.web.MyController#0'
04-Jul-2011 09:15:49 org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'my': initialization completed in 296 ms
Secondly, once the mapping is fixed, you may discover that the JSP is not found. In the sample I created, I added the views under /WEB-INF/jsp so I needed to update the prefix property in my-servlet.xml to <property name="prefix" value="/WEB-INF/jsp/"/>. However depending on the location of your views, you may not need to do this.
Personally I find the annotation based approach for MVC in Spring much easier to configure and follow, so I will recommend that you read REST in Spring 3: #MVC as you might find that easier to implement.
i was having the same problem because i was following step by step a tutorials thats up on the Netbeans official website, there it says and i quote "note that the JSTL (JavaServer Pages Standard Tag Library) library is added to the classpath during project creation by default. Deselect this option (as in the above screenshot), since you do not require JSTL for this tutorial. " once i tried leaving it checked i could be able to run my sample project, i really dont know anything more, hope this helps someone!