On Mon, Mar 7, 2016 at 5:36 PM, Mark Eggers <its_toas...@yahoo.com.invalid> wrote:
> Sean, > > See comment at the end. > > On 3/7/2016 2:11 PM, Sean Dawson wrote: > > On Sun, Mar 6, 2016 at 12:48 PM, Sean Dawson <seandawson2...@gmail.com> > > wrote: > > > >> > >> Tomcat 8_32 > >> Windows 7 > >> Java 8_51 > >> RestEasy 3.0.11.Final > >> GWT 2.7.0 (Jetty jetty-9.3.5.v20151012) > >> > >> Servlet code makes a RestEasy call to another servlet (same container) - > >> second servlet sets the 'Warning' HTTP header on response. Would like > to > >> access that in first servlet but when running in Tomcat, that header is > not > >> included. > >> > >> Code to get header in first servlet: > >> > >> Object headers = ((ClientResponseFailure) > >> e).getResponse().getResponseHeaders().get("Warning"); > >> > >> Also tried: getHeaders(), getStringHeaders(), and getHeaderString(). > >> > >> When running GWT in superdev mode in IntelliJ (15.0.4) using Jetty, the > >> above returns a List with one item that contains the warning string. > When > >> remote debugging Tomcat, that call returns null. > >> > >> Added this to web app xml, and also tried Tomcat conf/web.xml... > >> > >> <filter> > >> <filter-name>CorsFilter</filter-name> > >> > <filter-class>org.apache.catalina.filters.CorsFilter</filter-class> > >> <init-param> > >> <param-name>cors.exposed.headers</param-name> > >> <param-value>Warning</param-value> > >> </init-param> > >> </filter> > >> <filter-mapping> > >> <filter-name>CorsFilter</filter-name> > >> <url-pattern>/*</url-pattern> > >> </filter-mapping> > >> > >> Also tried cors.allowed.headers. > >> > >> Any pointers? > >> > >> > > > > Alright, lets try this again. Simple reproducible testcase... > > > > - download latest Tomcat 8 for Windows 64-bit zip > > > http://mirrors.ocf.berkeley.edu/apache/tomcat/tomcat-8/v8.0.32/bin/apache-tomcat-8.0.32-windows-x64.zip > > - extract somewhere > > - delete everything in webapps folder > > - build project below, put in webapps folder > > - go to: http://localhost:8080/one > > - check response headers... no Warning header > > > > ** pom.xml ** > > > > <project xmlns="http://maven.apache.org/POM/4.0.0" > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 > > http://maven.apache.org/maven-v4_0_0.xsd"> > > <modelVersion>4.0.0</modelVersion> > > > > <groupId>test</groupId> > > <artifactId>tcTest</artifactId> > > <packaging>war</packaging> > > <version>1.0-SNAPSHOT</version> > > > > <name>tcTest Maven Webapp</name> > > <url>http://maven.apache.org</url> > > > > <dependencies> > > <dependency> > > <groupId>org.glassfish</groupId> > > <artifactId>javax.servlet</artifactId> > > <version>3.1.1</version> > > </dependency> > > <dependency> > > <groupId>org.jboss.resteasy</groupId> > > <artifactId>resteasy-client</artifactId> > > <version>3.0.11.Final</version> > > </dependency> > > </dependencies> > > > > <build> > > <finalName>ROOT</finalName> > > </build> > > </project> > > > > > > ** web.xml ** > > > > > > <!DOCTYPE web-app PUBLIC > > "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" > > "http://java.sun.com/dtd/web-app_2_3.dtd" > > > > > <web-app> > > <display-name>Archetype Created Web Application</display-name> > > > > <servlet> > > <servlet-name>One</servlet-name> > > <servlet-class>pkg.ServletOne</servlet-class> > > </servlet> > > > > <servlet-mapping> > > <servlet-name>One</servlet-name> > > <url-pattern>/one/*</url-pattern> > > </servlet-mapping> > > > > <servlet> > > <servlet-name>Two</servlet-name> > > <servlet-class>pkg.ServletTwo</servlet-class> > > </servlet> > > > > <servlet-mapping> > > <servlet-name>Two</servlet-name> > > <url-pattern>/two/*</url-pattern> > > </servlet-mapping> > > </web-app> > > > > > > ** index.html ** > > > > > > <html> > > <body> > > <h2>Hello World!</h2> > > </body> > > </html> > > > > > > ** Caller interface ** > > > > > > package pkg; > > > > import javax.ws.rs.GET; > > import javax.ws.rs.Path; > > > > public interface Caller > > { > > @GET > > @Path("two") > > String makeCall(); > > } > > > > > > > > ** Servlet one ** > > > > > > package pkg; > > > > import java.io.IOException; > > > > import javax.servlet.ServletException; > > import javax.servlet.http.HttpServlet; > > import javax.servlet.http.HttpServletRequest; > > import javax.servlet.http.HttpServletResponse; > > import javax.ws.rs.core.MediaType; > > > > import org.jboss.resteasy.client.ProxyBuilder; > > > > public class ServletOne extends HttpServlet > > { > > Caller caller; > > > > @Override > > public void init() throws ServletException > > { > > caller = ProxyBuilder.build(Caller.class, > > "http://localhost:8080").now(); > > } > > > > @Override > > protected void doGet(HttpServletRequest request, > > HttpServletResponse response) throws ServletException, IOException > > { > > String result = caller.makeCall(); > > response.getWriter().println(result); > > } > > } > > > > > > ** Servlet two ** > > > > > > package pkg; > > > > import java.io.IOException; > > > > import javax.servlet.ServletException; > > import javax.servlet.http.HttpServlet; > > import javax.servlet.http.HttpServletRequest; > > import javax.servlet.http.HttpServletResponse; > > > > public class ServletTwo extends HttpServlet > > { > > @Override > > protected void doGet(HttpServletRequest request, > > HttpServletResponse response) throws ServletException, IOException > > { > > addHeader(response); > > response.getWriter().println("Ok"); > > } > > > > void addHeader(HttpServletResponse response) > > { > > response.setHeader("Warning", "This is a warning"); // also > > tried addHeader() > > } > > } > > > > <dependency> > <groupId>org.glassfish</groupId> > <artifactId>javax.servlet</artifactId> > <version>3.1.1</version> > </dependency> > > This is wrong and will include the servlet API in your WAR file. > > Thanks for your reply Mark. Minor oversight. I added provided to the servlet dependency and tried it again - same result (ie. no Warning response header). These are all I see: 1. HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Length: 6 Date: Mon, 07 Mar 2016 22:43:00 GMT I didn't use cors in this example, but it's the same result as the larger app with cors in the web.xml for both tomcat and the webapp. You at least need: > > <dependency> > <groupId>org.glassfish</groupId> > <artifactId>javax.servlet</artifactId> > <version>3.1.1</version> > <scope>provided</scope> > </dependency> > > I actually use the following in my Jersey applications: > <properties> > <version.jersey>2.22.1</version.jersey> > <version.jdk>1.7</version.jdk> > <version.servlet.api>3.1.0</version.servlet.api> > <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> > </properties> > > <!-- chunk of dependencies --> > <dependency> > <groupId>javax.servlet</groupId> > <artifactId>javax.servlet-api</artifactId> > <version>${version.servlet.api}</version> > <scope>provided</scope> > </dependency> > <dependency> > <groupId>javax.servlet.jsp</groupId> > <artifactId>javax.servlet.jsp-api</artifactId> > <version>2.3.0</version> > <scope>provided</scope> > </dependency> > <!-- JSTL because scriptlets are evil --> > <dependency> > <groupId>javax.servlet.jsp.jstl</groupId> > <artifactId>javax.servlet.jsp.jstl-api</artifactId> > <version>1.2.1</version> > <!-- the above brings in servlet spec 2.5 so it MUST be excluded --> > <exclusions> > <exclusion> > <groupId>javax.servlet</groupId> > <artifactId>servlet-api</artifactId> > </exclusion> > <exclusion> > <groupId>javax.servlet.jsp</groupId> > <artifactId>jsp-api</artifactId> > </exclusion> > </exclusions> > </dependency> > <!-- standard tag libraries - apache version --> > <dependency> > <groupId>org.apache.taglibs</groupId> > <artifactId>taglibs-standard-impl</artifactId> > <version>1.2.5</version> > </dependency> > <!-- other dependencies go here - including Jersey --> > > I don't know if this will help solve your problem, but getting the > servlet api out of your WAR file is a good start. > > . . . just my two cents > /mde/ > >