I am setting the development environment for a product on which I have to work.
Into the tutorial I found that it say that I have to modify the TomCat web.xml configuration file adding these line into the section:
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>
What exactly do this setting?
Tnx
My understanding is this is a parameter that's nested inside a
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
According to a tutorial -
"If you wish, you can modify Tomcat's settings to reduce the amount of
white space in HTML that is created from JSPs (Java Server Pages).
White space is controlled by the trimSpaces parameter in the JSP
compiler."
Related
I have been trying (for about a day now) to figure out how to send a #POST request from my client to my web service but I am getting a 403 error and I have no idea why. I have tried editing my web.xml files to allow the correct authorization but it still isn't working. Below are my WEB-INF web.xml and Tomcat web.xml files. Any help would be greatly appreciated, this has been beyond frustrating. Also, I am very new to both Tomcat and Jersey so it very well could be a very stupid/simple error.
Specs
OS X El Capitan 10.11.2
Tomcat Version 7.0 Server
Eclipse JEE Kepler R Cocoa x86_64
Jersey 2.23.1
JRE 1.7
Postman as my client (Google chrome ext)
Server web.xml
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>readonly</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Accept,Accept-Encoding,Accept-Language,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization,Connection,Content-Type,Host,Origin,Referer,Token-Id,User-Agent, X-Requested-With</param-value>
</init-param>
<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, PUT, DELETE, OPTIONS, HEAD</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
WEB-INF web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<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">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.example.messenger</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
That should not happen. Your error is handled somewhere. Look these annotations:
#ControllerAdvice
#ResponseStatus(HttpStatus.FORBIDDEN)
#ExceptionHandler(YourException.class)
This example (https://wolfpaulus.com/journal/java-journal/jersey/) has a somewhat altered web.xml:
<display-name>Jersey Web Application</display-name>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
That example page seems to highlight your exact environment (except the author uses IntelliJ rather than Eclipse... but you can download the community edition for free, and Java 8 rather than 7) - so you may want to follow along with it to get up and running.
I have a webservlet with Jersey rest API configured. Now I have to convert the servlet to a liferay portlet. How to convert? Like what portlet-class should I specify in my portlet.xml? The below is the web.xml of my servlet.
<servlet>
<servlet-name>charts</servlet-name>
<!--<servlet-class>javax.servlet.http.HttpServlet</servlet-class>-->
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.charts.api.service</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>charts</servlet-name>
<url-pattern>/charts</url-pattern>
<url-pattern>/charts/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
How to configure my portlet.xml and use rest service with my portal? I have to deploy the portlet in liferay jboss server as well.
Why don't you use a delegate servlet in liferay?
You can create a liferay portlet and in web.xml define your delegate servlet.
Here you've got a definition example:
<servlet>
<servlet-name>buscador</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalDelegateServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>com.dummy.servlet.BuscadorServlet</param-value>
</init-param>
<init-param>
<param-name>sub-context</param-name>
<param-value>buscador</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
It will listens on http://yourliferay/delegate/buscador
Hope it helps
Currently i'm facing the problem that my thetransactioncompany corsfilter on an Tomcat 7 with Jersey 1.18 (can't update) works for the path /v2/users on PUT but not on /v2/plans. There is no difference between those - same package only the class is different. I also need to say that GET, POST works fine only PUT doesn't work.
My web.xml looks like this:
<!-- CORS FILTER FOR ALLOWING CROSS DOMAIN ACCESS -->
<filter>
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowSubdomains</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, POST, PUT, DELETE, OPTIONS, HEAD </param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.maxAge</param-name>
<param-value>-1</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
this should allow PUT on all paths after root - or am i wrong?
also the OPTIONS on /v2/plans would give me the allowed methods: GET, POST, PUT, DELETE, OPTIONS, HEAD
Found out that it was another Exception which was the root cause of the whole thing. Turned on a deeper Logging and found it was a Nullpointer.
So the solution is: look at the root cause - and turn on a better logging with more details in the specific problem.
I am learning Servlets.
In web.xml of an application, I found the following Servlet code.
Can somebody please explain me the significance of the code
<servlet id="Servlet_1060120206078">
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param id="InitParam_1060120206077">
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param id="InitParam_1060120206076">
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param id="InitParam_1069371544495">
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<init-param id="InitParam_1069371544496">
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
Thanks
Nirmalya
This is just defining a servlet (in this case a FrontController for Struts) that is used to handle requests. Later on in the file I'm sure you'll also find a servlet mapping that maps this servlet to http requests.
The <init-param> elements are key/value pairs that the servlet can read on startup. Struts uses these for configuration.
All the InitParam_XXX stuff is un-necessary, my guess is that it was machine generated by some editor.
Check this out for more details:
http://netbeans.org/kb/docs/web/quickstart-webapps-struts.html
Any of you guys have enabled SSI (ServerSide Includes) in JBoss? I guess it should be not difficult as it is built on top of a Tomcat instance.
Tomcat already includes in catalina.jar the org.apache.catalina.ssi.SSIServlet so just declare the servlet and attach it to a mapping URL, by setting this in the applications web.xml
<servlet>
<servlet-name>ssi</servlet-name>
<servlet-class>
org.apache.catalina.ssi.SSIServlet
</servlet-class>
<init-param>
<param-name>buffered</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>60</param-value>
</init-param>
<init-param>
<param-name>isVirtualWebappRelative</param-name>
<param-value>1</param-value>
</init-param>
<load-on-startup>4</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
I put all the parameters, you can see their definition in this Tomcat SSI reference.
As the doc says, SSI can bypass security policies so it must be privileged, do this changing the context.xml located in jboss-web.deploy inside the deploy folder. Just add privileged="true" to the root element.
<Context ... privileged="true">
The servlet will just act as a proxy for the files matching the URL of its mapping.