I want to deploy my servlet to GAE but getting following error
HTTP ERROR 500
Problem accessing /barcodes. Reason:
java.awt.Rectangle is a restricted class. Please see the Google App Engine developer's guide for more details.
Caused by:
java.lang.NoClassDefFoundError: java.awt.Rectangle is a restricted class. Please see the Google App Engine developer's guide for more details. at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:50) at com.barcodelib.barcode.a.b.a.(a.java) at com.barcodelib.barcode.a.b.c.(c.java) at com.barcodelib.barcode.a.i.(i.java) at com.barcodelib.barcode.PDF417.a(PDF417.java) at com.barcodelib.barcode.AbstractBarcode.renderBarcode(AbstractBarcode.java) at PDF417Barcodes.doGet(PDF417Barcodes.java:49) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
servlet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException
{
try {
PDF417 barcode = new PDF417();
barcode.setData("PDF417");
ServletOutputStream servletoutputstream = response.getOutputStream();
response.setContentType("image/jpeg");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// Generate PDF-417 barcode & output to ServletOutputStream
barcode.renderBarcode(servletoutputstream);
} catch (Exception e) {
throw new ServletException(e);
}
}
It working fine with tomcat but not working with GAE, Please help me.
Your barcode library uses java.awt.Rectangle
, and as the error message states, it's a restricted class. This restriction applies to GAE only, it's not a general restriction which is why it works in Tomcat.
This page https://cloud.google.com/appengine/docs/standard/java/jrewhitelist lists all the allowed JRE classes, so if you're using directly or indirectly a class not listed there it will fail.
You can either not use GAE, or try to find a library that advertises to be GAE "safe" (disclaimer: I do not know if such a library exists).