Problems with deploying GWT with RPC to tomcat (web.xml problem probably) - gwt

My gwt app that uses mysql database runs normaly in eclipse when debugging. When i run it on tomcat, it displays correctly but when i click on a button that makes a RPC (executes servlet and contacts the database) i get an error. I checked my tomcat log and i see 404 error when clicking on a button:
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/Bazica.html HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/Bazica.css HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/bazica/bazica.nocache.js HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/bazica/ F0C186B415ADBD43522C686552368517.cache.html HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:32:39 +0200] "GET /Bazica/war/bazica/gwt/standard/images/hborder.png HTTP/1.1" 304 -
0:0:0:0:0:0:0:1 - - [22/Jul/2010:10:33:29 +0200] "POST /Bazica/war/bazica/greet HTTP/1.1" 404 1024
I guess this is a problem with web.xml file and url-pattern. I guess i don't understand this url-pattern, where should it point to?
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<!-- Servlets -->
<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.test.baze.server.GreetingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/bazica/greet</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Bazica.html</welcome-file>
</welcome-file-list>
</web-app>
My interface has an annotation RemoteServiceRelativePath("greet"), i think it's relevant:
package com.test.baze.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
* The client side stub for the RPC service.
*/
#RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
String greetServer(String name) throws IllegalArgumentException;
}
I tried changing url-pattern to the folder of my service implementation /WEB-INF/classes/com/test/baze/server but my app hangs with no message.
Could you please help me change my web.xml or sth. else to get my app working on a Tomcat. Tnx.

If you take a look at the docs, your URL pattern should be:
<url-pattern>/module_name/greet</url-pattern>
But in your web.xml, you've set the module name to "bazica". Are you renaming the module in your GWT module file (.gwt.xml file) to bazica? If you're not, you'll either have to rename it or use the full path to the GWT module file.

Related

Can't access a Java servlet through its URL

I'm trying to set up a very basic JEE project with Eclipse+Tomcat using a single servlet and JSP. However I'm getting a HTTP 500 Internal Server Error when trying to access its URL http://localhost:8080/test/toto. The exception message being displayed is:
Cannot invoke "javax.servlet.RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)" because the return value of "javax.servlet.ServletContext.getRequestDispatcher(String)" is null.
Here is my Test servlet code:
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Test extends HttpServlet {
public void doGet( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException{
this.getServletContext().getRequestDispatcher( "/WEB-INF/test.jsp" ).forward( request, response );
}
}
The test.jsp file should just display a message : "Generated by a JSP"
Here's the content of web.xml for reference :
<?xml version="1.0" encoding="UTF-8"?>
<web-app
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_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>com.sdzee.servlets.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/toto</url-pattern>
</servlet-mapping>
</web-app>
The corresponding Tomcat log reads :
0:0:0:0:0:0:0:1 - - [10/Dec/2020:14:29:47 +0100] "GET /test/toto HTTP/1.1" 500 1606
This is the project arborescence
Edit: Other things I recently tried: Reinstall Eclipse+Tomcat on another pc and start again, move test.jsp directly to WebContent and access http://localhost:8080/test/test.jsp: results in a HTTP 404 ressource not found error.
I've just noticed that before I create my servlet I can access whatever file I create under WebContent at http://localhost:8080/test/whatever.jsp but I can't do that anymore once I add the servlet and establish the mapping in web.xml
I was editing the web.xml file of the Tomcat server and not the one of the project, that's why nothing was working as expected.

BaseX REST API: Set custom HTTP response header

I want to include the following HTTP header to all responses by the BaseX REST API:
Access-Control-Allow-Origin: *
Is this possible?
BaseX uses Jetty below the hood. You can modify the web.xml file to make Jetty send CORS headers, but either
use at least BaseX 8.6.3 which added the jetty-servlets library or
have to add the jetty-servlets jar to your $CLASSPATH (BaseX already ships jetty-servlet, which is a different class; and be sure to fetch the appropriate version matching what's included in BaseX).
Include following directives to the web.xml file:
<web-app>
<!-- add those before the closing web-app tag: -->
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Be aware that Jetty does not seem to support posting a wildcard header Access-Control-Allow-Origin: *: while the default is already
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param>
(put that into the <filter/> element), Jetty uses this to construct a regular expression and always returns the value of the Origin: request header if matching, but that should also serve you well.
An example request:
$ curl -v -H "Origin: http://foo.example" http://admin:admin#localhost:8984/rest
* Trying ::1...
* Connected to localhost (::1) port 8984 (#0)
* Server auth using Basic with user 'admin'
> GET /rest HTTP/1.1
> Host: localhost:8984
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.50.1
> Accept: */*
> Origin: http://foo.example
>
< HTTP/1.1 200 OK
< Content-Type: application/xml; charset=UTF-8
< Content-Length: 152
< Server: Jetty(8.1.18.v20150929)
<
<rest:databases xmlns:rest="http://basex.org/rest" resources="1">
<rest:database resources="1" size="96234589">test</rest:database>
</rest:databases>
* Connection #0 to host localhost left intact
Given this seems a rather reasonable request and thing to do, you might be successful opening an issue to include the library by default, and maybe even enabling CORS by default. (the library is now included by default)

Web App Returns Same Content Regardless of Request

Using Eclipse's internal representation of Tomcat8 (do not know if that is relevant), the following is a series of page requests. This comes from the file:
C:\Users\BS\Eclipse\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\logs\localhost_access_log.2016-04-25.txt:
"GET /ProjK/ HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Css/v02/openElement.css?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/Templates/BaseLayer.css?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/index.css?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Client/jQuery/migrate.js?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Client/Common/oe.min.js?v=50491098000 HTTP/1.1" 200 16354
"GET /ProjK/Files/Image/Template/Top.png HTTP/1.1" 200 16354
"GET /ProjK/Files/Image/Template/Logo.png HTTP/1.1" 200 16354
"GET /ProjK/Files/Image/BioTransparent.png HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Image/WEImage/PuceImg-3f204a74.png HTTP/1.1" 200 16354
"GET /ProjK/WEFiles/Image/empty.png HTTP/1.1" 200 16354
Observe that each response is the same byte count. The browser receives the content of the same file regardless of the request.
The content is from "index.html" that has been renamed to "index.ftl" and renamed back to "index.html". I have been making simple edits to this file hoping to see any change in what the browser shows.
I see that the file "index.html" has been updated with the new content in both the workspace and the /tmp0/webapps/ folder.
Yet, there are no changes in what is delivered to the browser.
A number of conversations suggests that Tomcat caching be dealt with. I would have to wonder why, during app development, this is an actual consideration.
But caching does not explain why every page and page resource request is served the same unchanging content.
What common mistake would a new java web app developer be making with respect to the setup/configuration of Tomcat and/or Eclipse and or the webapp that would explain this behavior?

SRVE0295E error on integrating Bluemix application with SSO service using cloud directory

I am facing an issue with SSO integration (cloud directory) with a Liberty for Java application.
I have Liberty application which is integrated with SSO service using Cloud directory. I have followed the steps mentioned here
When I access the homepage of the application, I am getting "Error 500: SRVE0295E: Error reported: 500 " error message. Logs aren't providing any useful information.
The steps that I followed are listed below
Created a simple Liberty for Java webapp, named SSODemo and deployed on Bluemix. I could access home page of the application
Created SSO service. Created Cloud directory and added a couple of users and saved
Added the following in web.xml file of SSODemo
SSODemoSecurity
Secured
/
/
/
/SSODemo/
GET
PUT
HEAD
TRACE
POST
DELETE
OPTIONS
TESTROLE
Copied ssodemo.war file to folder c:\deploy2bluemix\apps
Created server.xml file in c:\deploy2bluemix. Added role. server.xml would look as below
<featureManager>
<feature>jsp-2.2</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<applicationMonitor updateTrigger="mbean"/>
<application type="war" id="SSODemo" name="SSODemo" location="SSODemo.war" context-root="/">
<application-bnd>
<security-role name="TESTROLE">
<special-subject type="ALL_AUTHENTICATED_USERS"/>
</security-role>
</application-bnd>
</application>
Pushed SSODemo app from c:\deploy2bluemix
Bound the SSO service created with SSODemo app
restaged SSODemo app
Saved the default details populated on Integrate tab of SSO Service
Now, when I launch SSODemo app, it asks for user id and password. On providing valid user id and password it throws "Error 500: SRVE0295E: Error reported: 500 " error message
Following is the log entry when the above error message is thrown
bmssodemo-mc.mybluemix.net - [10/02/2016:03:36:26 +0000] "GET /oidcclient/redirect/GIC5KC6sbK?scope=openid&code=lS9jAkiKSPmC8VNJw0NFULgqMkXEpP&state=f0hvnV7R4iSsUDwU5hzr HTTP/1.1" 500 0 42 "https://ssoq3-gikup9q8qk-cp16.iam.ibmcloud.com/idaas/mtfim/sps/authsvc?PolicyId=urn:ibm:security:authentication:asf:basicldapuser" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0" 192.155.237.118:32103 x_forwarded_for:"125.16.236.150" x_forwarded_proto:"https" vcap_request_id:4844e729-a9d6-4efb-579a-a5c6449db8ff response_time:0.227078783 app_id:7b8c1d84-2cb0-420a-8735-198ee50dcf62 x_global_transaction_id:"40112183"
Any guidance here to resolve the issue will be very helpful. Thank you.
Actually the Bluemix status page is reporting a notification opened on Feb 5th about an issue of SSO service with the liberty runtime.
Check on
https://developer.ibm.com/bluemix/support/#status
Liberty for Java runtime provided an urgent update for this issue today. I don't think you need the workaround now. Please give it a try.

Dispatcher not showing results from an AJAX call to an OSGi bundle

In my project, we have a component that includes a JavaScript file & in that file, we are making an AJAX call to a Servlet (defined in an OSGi bundle).
When the package is installed in the Publish instance (along with the OSGi bundle), I'm able to see results after I click on a link which is bound to the AJAX call.
When accessing the same page through the Dispatcher however, the page is getting displayed but the link which should show content from the OSGi bundle is not working. The same link is working fine when accessed directly via the Publish instance
Updated:
The access.log in Dispatcher (Apache Web Server)
Success log of dispatcher
domain - - [11/Jul/2014:15:25:11 +0530] "GET /content/sample.html HTTP/1.1" 200 25805
Failure log on one of the links on the above page
domain - - [11/Jul/2014:15:25:12 +0530] "GET /bin/servlet/SampleServlet?action=GET_SAMPLE_USAGE HTTP/1.1" 404 230
It is not finding GET_SAMPLE_USAGE servlet, but the same is already available in the OSGi bundle and is working perfectly fine via the Publish instance (logs below).
Publisher access.log
domain - admin 11/Jul/2014:15:24:31 +0530 "GET /content/sample.html HTTP/1.1" 200 25805 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0"
domain - admin 11/Jul/2014:15:24:31 +0530 "GET /bin/servlet/SampleServlet?action=GET_SAMPLE_USAGE HTTP/1.1" 200 - [this is not a link] ( "domain:4503/content/sample.html" ) "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0"