Jersey 2.3.1 on Google App Engine - google-app-engine

I wonder if last version of Jersey does have support of Google App Engine.
I have found 'gae-integration' project (https://github.com/jersey/jersey/tree/master/incubator/gae-integration) with a link to Jersey 2.3.1. Actually all my attempts failed but maybe someone was luckier?
Thanks in advance!

I struggled to get Jersey 2 to work with GAE but figured it out now.
Tested OK with GAE SDK 1.9.10 and Jersey 2.12, including multipart/form-data. See for instance this blog article.
In Jersey 2 you have to enable features in your web.xml which is automatically enabled in Jersey 1. For example the snippet below enables JSP page support and the multipart/form-data MIME type features. (I don't think the GaeFeature is required, but haven't tested without it).
<servlet>
<servlet-name>com.namibiaonthenet.www</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.namibiaonthenet.www</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.server.mvc.jsp.JspMvcFeature;
org.glassfish.jersey.server.gae.GaeFeature;
org.glassfish.jersey.media.multipart.MultiPartFeature;
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
To enable the multipart/form-data feature an additional short config. file is required in your project - for details see my and #yves' answers here.
If you still struggle, let me know in a comment to this answer.

Related

Production deployment issue on Google App engine

I am using Google App engine and deployed web application.
I tried to deploy code on local using App engine then it is working fine
but when I deployed on Production server then it caused error.
Request : POST 20180909t164211-dot-spry-autumn-140509.appspot.com/_ah/spi/BackendService.getApiConfigs
(View request) Status : 500 Internal Server Error, Updated Screen shots for error and web.xml configration.
Web.xml configration:
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value />
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
Production error :
Please suggest me some solutions for same.
Endpoints v1 has been shut down. You must migrate your application to Endpoints v2. See migration instructions.

Jersey with Appengine Standard and CloudEndpoints

Our appengine application consists of several microservices deployed in a mix of standard and flex environments. Since we are using both flex and standard we chose jerse to implement our backend services as endpoint framework does not work with flex. We are not able to make this combination of Jersey + Appengine Standard + Endpoint work. When we deploy the swagger using gcloud cloud manager, it does not link with the backend services.
I could not find any documentation regarding how to integrate App engine standard and endpoint without using endpoint framework annotations.
Has anybody implemented the rest service backends using the combination
Jersey + App engine Standard + Cloud Endpoints. Is it possible to integrate Cloud endpoints and appengine standard without using endpoint framework annotations.
Pls note : We have tested Jersey + Flex + Endpoints and it works.
This is not tested or documented, so you are playing in a new area. It should work, and I'm happy to try and help you debug it. To use Endpoints on Standard with Flex, you have to do this:
Including this dependency:
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control-appengine-all</artifactId>
<version>${endpoints.management.version}</version>
</dependency>
Add this configuration to your web.xml, then add a filter-mapping to go in front of jersey:
<filter>
<filter-name>endpoints-api-controller</filter-name>
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
<init-param>
<param-name>endpoints.projectId</param-name>
<param-value>${endpoints.project.id}</param-value>
</init-param>
<init-param>
<param-name>endpoints.serviceName</param-name>
<param-value>echo-api.endpoints.${endpoints.project.id}.cloud.goog</param-value>
</init-param>
</filter>
Upload your OpenAPI specification using gcloud service-management deploy.
In appengine-web.xml, add an environment variable definition:
<env-variables>
<env-var name="ENDPOINTS_SERVICE_NAME" value="echo-api.endpoints.${endpoints.project.id}.cloud.goog" />
</env-variables>

Invoking JSP inside Google App Engine application results in 404 error on production server, works on development server

I am running into a problem with invoking JSP files inside a Google App Engine application. Here is an equivalent version of the relevant configuration in web.xml:
<servlet>
<servlet-name>SomeServlet</servlet-name>
<jsp-file>SomeServlet.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>SomeServlet</servlet-name>
<url-pattern>/prefix</url-pattern>
</servlet-mapping>
When I try accessing SomeServletin the development environment at http://localhost:8888/prefixthis works fine, however if I try it in production at http://someapp.appspot.com/prefix I get HTTP error 404 (Not Found). It's war/SomeServlet.jsp in the file system. There is no further information in the server logs. I have also tried various access control configurations but to no avail.
What could be the reason for this failure?
You should use:
<jsp-file>/SomeServlet.jsp</jsp-file>
From the documentation:
Note: The <jsp-file> must start with a forward slash (/) if the JSP is
in the application's root directory.

Servlet works on debug mode but fails to work when deployed to AppEngine (Appspot)

I have a gwt application that have some servlet on it. During development mode, the servlet can be accessed properly but when deployed I can't access it like:
Debug mode:
http://127.0.0.1:8888/mygwtapp/greet (Works)
Deployed in Appspot.com
http://mygwtapp123456.appspot.com/mygwtapp/greet (Does not work)
What could be the problem?
Here's the mapping on the web.xml
<servlet>
<servlet-name>greet</servlet-name>
<servlet-class>com.mygwtapp.server.GreetServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greet</servlet-name>
<url-pattern>/mygwtapp/greet</url-pattern>
</servlet-mapping>
Why aren't you using http://mygwtapp123456.appspot.com/mygwtapp/greet when deployed, when this is what you mapped in your web.xml?
Are you sure you've updated your default version in appengine control panel? If you updated version id in appengine-web.xml, but haven't set that as default, your appspot could be serving a web.xml that doesn't have your updated servlet.
If this is not the issue, please respond with any additional logging / error messages you encounter.

Tomcat, web.xml, exclude path

In my application, i need to process all the requests from users in a single servlet, however, i happen to have a folder with static content, which i would like to also serve statically.
In my web.xml file, i have the following:
<servlet>
<servlet-name>all</servlet-name>
<servlet-class>a.b.c.WidgetlistXml</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>all</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Is there a way i can exclude, say, all .zip files from this?
PS. I know this has been asked on StackOverflow before, but the latest posts were from about 2006, and they also concerned Spring or other frameworks. I use none, and since 2006 something could have changed in url-patterns. By the way, finding the docs on web.xml is not that simple either.
Thank you in advance.
Set a DefaultServlet for your static contents. Here is an example:
http://tomcat.apache.org/tomcat-7.0-doc/default-servlet.html#where

Resources