Using gwt logs jar I am able to display logs on my console. But now I wanted to add logs in my olgs file from cient side, as we do using log4j on server side. So i reffered to http://code.google.com/p/gwt-log/wiki/GettingStarted this link but i dont see any client side logs getting generated in my log file.
Following is my gwt.xml file
<inherits name="com.allen_sauer.gwt.log.gwt-log-DEBUG" />
<set-property name="log_DivLogger" value="DISABLED" />
<!-- In gwt-log-3.0.3 or later -->
<inherits name="com.allen_sauer.gwt.log.gwt-log-RemoteLogger" />
<set-configuration-property name="log_pattern" value="%d [%t] %p - %m
%n" />
Following is my web.xml file
<servlet>
<servlet-name>gwt-log-remote-logger-servlet</servlet-name>
<servlet-class>com.allen_sauer.gwt.log.server.RemoteLoggerServiceImpl</servlet-class>
<!--
The `symbolMaps` parameter specifies the server directory
containing the GWT compiler symbol maps output, which is used
for stack trace deobfuscation
-->
<init-param>
<!-- This value assumes a GWT compile with '-deploy war/WEB-INF/deploy/' -->
<param-name>symbolMaps</param-name>
<!--
Modify the param-value based on your server environment. Some web servers
use your `war` directory as the 'current working dir', while other
vendors will do something different. You may use trial and error. Specify the
relative path you think should work, then check the server log after forwarding
the first client log message to the server. If the directory cannot be found,
gwt-log will report the full path which it tried.
-->
<param-value>WEB-INF/deploy/detectfiles/symbolMaps/</param-value>
</init-param>
<!--
Additional or alternate directories may be specified via additional parameter
which also begin with `symbolMaps`. This may be useful if you deploy to multiple
server environments which use different directory structures or have a different
notion of what the 'current working directory' is.
-->
<init-param>
<param-name>symbolMaps_2</param-name>
<param-value>WEB-INF/deploy/detectfiles/symbolMaps/</param-value>
</init-param>
<!-- Optionally enable CORS (http://www.w3.org/TR/cors/)
<init-param>
<param-name>Access-Control-Allow-Origin</param-name>
<param-value>http://your-applications-origin</param-value>
</init-param>
-->
</servlet>
<servlet-mapping>
<servlet-name>gwt-log-remote-logger-servlet</servlet-name>
<url-pattern>/com.renault.detectfiles/gwt-log</url-pattern>
</servlet-mapping>
I have added log on clinet side as follows
Log.debug("Hi this is a debug log");
First of all, make sure that you compile your GWT application with the additional parameter -deploy war/WEB-INF/deploy/.
Second, make sure that symbol maps exist in the directory
WEB-INF/deploy/detectfiles/symbolMaps/. I observed that symbolMaps go to the directory WEB-INF/deploy/<module-name>/symbolMaps/ when I compiled. Here, detectfiles does not look like your module name. Because, in the url-pattern, you have specified com.renault.detectfiles as the module name.
These might be the possible cause of not seeing the log.
Related
I'm trying to set up a dynamic web app using Eclipse Juno and Tomcat 7. My problem is that i can only get my servlet to run if my file structure is
MyProject/Java Rescources/src/(default package)/MyServlet.java
I've read i should avoid using the default package (don't know why) but when i try to use a different package:
MyProject/Java Resources/src/myPackage/MyServlet.java
I get the error message:
HTTP Status 404 - /MyProject/MyServlet
The requested resource is not available
Its only a small test project so i can start a new workspace and create the project anew if necessary. I suppose i have to change a path somewhere but i don't know where or how.
I got it working using the following in web.xml
<servlet>
<servlet-name>QNumInput</servlet-name>
<servlet-class>myPackage.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>QNumInput</servlet-name>
<url-pattern>/QNumInput/QNumReq.do</url-pattern>
</servlet-mapping>
The index.html file calls this with the tag:
<form name="getQNumForm"
action="http://localhost:8080/MyProject/QNumInput/QNumReq.do"
METHOD = "POST">
<B>Enter Question Number 1 to 200</B>
<INPUT TYPE="TEXT" NAME="qNumber">
<INPUT TYPE="SUBMIT" VALUE="Request Question Text">
</form>
It did not work at first so i cleaned the tomcat work directory by right clicking on the server (not sure if this is necessary) It still did not work so i gave up and exited Eclipse. This must have saved the new settings because when i fired up Eclipse again and tried it again it worked ok.
Thanks for the help.
DG
You will need to make sure your <servlet-mapping> and <servlet> elements in web.xml are correctly set.
I am in the process of converting an already exisiting Java Web application into a RESTful web application using Spring MVC and Groovy.
One of the main features I wanted to achieve was HOT DEPLOYMENT.
I chose groovy because I did not want to make changes to the already implemented Business logic(handlers) and also if I had to ever make changes to the groovy code after deployment, I could easily do that without restarting the server(ie. at runtime).
This can be done because Spring supports Dynamic reloading of groovy scripts(beans). It reloads classes of dynamic languages if they are changed.
I am using Spring annotations to map request URL's to controller methods and the application is deployed in tomcat 6.0.35.
This is the web.xml file
//web.xml
<?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_2_5.xsd" version="2.5">
<!-- Spring Dispatcher -->
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<!-- Loads application context files in addition to ${contextConfigLocation} -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Set session timeout to 30 minutes -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
This groovy file is the controller to which the DispatcherServlet maps the request.
// UserController.groovy
#Controller
class UserController
{
// This is the method to which the HTTP request is submitted to based on the mapping of the
// action field of the form ie. /service/user/login/auth.json
#RequestMapping(value="/user/login/auth.{extension:[a-zA-Z]+}", method=RequestMethod.POST)
#ResponseBody
public String authenticate(
#PathVariable String extension,
#RequestParam(value="username", required=true) String username,
#RequestParam(value="password", required=true) String password)
{
// UserResource makes the backend calls, authenticates a user and returns the result.
def user = new UserResource()
def result = user.login(name:username, userPassword:password)
// Output the result of the query. Method makeView makes a JSON response of the result
// and sends to the client(browser)
def builder = makeView(extension)
{
it.login(action:result.action, message:result.message)
}
}
}
The Spring configuration file is as follows where I have used the "lang:groovy" tag which supports dynamic languages. I have also mentioned the refresh time to be 5 seconds, so that any changes made to those groovy files at runtime can be seen every 1 second and the classes are reloaded.
//applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang-3.1.xsd">
<context:annotation-config/>
<context:component-scan base-package="app.controller,app.resource" />
<lang:groovy id="user" script-source="classpath:controller/UserController.groovy" refresh-check-delay="1000"></lang:groovy>
<!-- To enable #RequestMapping process on type level and method level -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<!-- Resolves view names to template resources within the directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"/>
<property name="suffix" value=".html"/>
</bean>
</beans>
I have configured my Buildpath and groovy compiler accordingly, so that all the groovy scripts directly get copied to the target folder instead of getting compiled to class files.
THE MAIN PROBLEM
When I deploy this project in a tomcat server, it loads all the Spring beans required including the ScriptProcessor. Now, when I go to my browser, load the form, and try to submit the authentication form, I get the following error in Tomcat log:
15:20:09 WARN - No mapping found for HTTP request with URI [/service/user/login/auth.json] in DispatcherServlet with name 'rest'
I have also made changes in $TOMCAT_DIR/conf/context.xml to antilock resources and JARS
<Context antiResourceLocking="true" antiJARLocking="true" reloadable="true" privileged="true">
.
.
.</Context>
However, if I configure my project to compile those groovy scripts into bytecode classes, comment out the "lang:groovy" tag in applicationContext.xml, and then restart the server, the groovy scripts get compiled into class files and the request is serviced perfectly. Authentication takes place.
Also, if I configure the dynamic beans in my applicationContet.xml using the following two lines instead of the tag, my beans DO get created dynamically at runtime and the URLs do get mapped to the respective controller methods because of the annotations.
<bean class="org.springframework.scripting.support.ScriptFactoryPostProcessor" />
<bean id ="User" class="org.springframework.scripting.groovy.GroovyScriptFactory">
<constructor-arg value="classpath:controller/UserController.groovy" />
</bean>
But I do not know how to create the bean refreshing functionality with this style. So I guess there is an issue with the way the tag processes the groovy scripts.
I would really appreciate some help on this. I have searched all over the internet and read an infinite number of tutorials, and followed the exact procedure mentioned there. But I cant find out whats going wrong.
Please help me solve this problem.
Thank you.
Try creating the controller with Java/Groovy that is compiled and let it get injected the Groovy 'script' as a dependency to do the actual work. I seem to remember doing this before and it might be the annotations or the way Spring loads controllers that makes the 'script' not work for you properly.
Currently we have the following working example with a messy "war" prefix in path:
<servlet>
<servlet-name>gwt-log-remote-logger-servlet</servlet-name>
<servlet-class>com.allen_sauer.gwt.log.server.RemoteLoggerServiceImpl</servlet-class>
<init-param>
<param-name>symbolMaps</param-name>
<param-value>war/WEB-INF/deploy/APPNAME/symbolMaps/</param-value>
</init-param>
</servlet>
Jetty is configured, for testing purposes, with WebApp directory "war", because it is a single installation. I tried with /WEB-INF and some other combinations, does not work...
How to set the path independent from installation? So that we do not need to fix it in the build process?
There is a solution if using a own customized build of GWT log. The current version does generic search for the symbolMaps.
See here https://code.google.com/p/gwt-log/issues/detail?id=73&colspec=ID%20Type%20Status%20Priority%20Milestone%20Stars%20Summary
I use Eclipse GWT Plug-in to build a GWT app. Later on, I'll have to deploy this as a Tomcat webapp. I have read many pages on how to do it and it looks dead simple but it doesn't work here.
If I create a new Web application using the plug-in and that I copy the war directory content to de tomcat_install/webapps folder it works right out the box, I get the application and all the things get loaded correctly.
If I do the same with the application I'm working on for a couple of weeks now, I get nothing, there is just the plain html file I use as welcome page that loads. If I inspect the page I can see it has correctly loaded the .nocache.js but no controls whatsoever show up on my page.
Everything works in development, my servlet are correctly mapped.
Here is my app.gwt.xml :
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='VirtualLabPortal'>
<inherits name="com.google.gwt.user.User" />
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<inherits name="com.google.gwt.i18n.I18N"/>
<set-property name="gwt.logging.enabled" value="FALSE"/>
<define-property name="webkitVariant" values="safari, chrome" />
<collapse-all-properties />
<extend-property name="locale" values="en"/>
<extend-property name="locale" values="fr" />
<set-property-fallback name="locale" value="fr"/>
<entry-point
class="com.banctecmtl.ca.vlp.view.webview.client.VirtualLabPortal" />
<source path='view/webview/client' />
<source path='shared' />
<source path='model' />
</module>
My web,xml, where my two servlet are mapped looks like this :
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>VlpControllerService</servlet-name>
<servlet-class>com.banctecmtl.ca.vlp.view.webview.server.VlpControllerServiceImpl</servlet-class>
</servlet>
<servlet>
<servlet-name>UserAccessService</servlet-name>
<servlet-class>com.banctecmtl.ca.vlp.view.webview.server.UserAccessServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VlpControllerService</servlet-name>
<url-pattern>/VirtualLabPortal/VlpController</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UserAccessService</servlet-name>
<url-pattern>/VirtualLabPortal/UserAccess</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>VirtualLabPortal.html</welcome-file>
</welcome-file-list>
</web-app>
Note that in my services interfaces I use #RemoteServiceRelativePath("VlpController") and #RemoteServiceRelativePath("UserAccess") to ensure a correct mapping.
This is the content of my entrypoint, that I made plain simple just to see if I could get it to work on deployment :
public class VirtualLabPortal implements EntryPoint {
/**
* Entry point method.
*/
public void onModuleLoad() {
RootPanel.get().add(new Label("This"));
}
}
Since the body of my html page is empty, a white page shows up, the javascript should write the test label on that page, but nothing happens. As I said, my VirtualLabPortal.nocache.js is loaded in the html page.
Is there something I'm completely missing here?
EDIT :
I think i just got it, I removed two properties my partner added to the gwt.xml file to reduce the number of permutations and it seems to be fixed so far:
<set-property name="gwt.logging.enabled" value="FALSE"/>
<define-property name="webkitVariant" values="safari, chrome" />
<collapse-all-properties />
Do you compile your project via :
project right clic > google > gwt compile
and then
project right clic > export > WAR file
this is the way I proceed, it works !
check this one:
Deploying GWT app from GAE to Tomcat
After long hours of searching and testing, I understtod how GWT bootstrapping process was working. I looked over my module.gwt.xml file and I found the following line added by one of my partners to reduce the number of permutations :
<collapse-all-properties />
Removing this line brought us back to 18 permutations and deploying the WAR folder to my tomcat webapps directory did the job. Compiling only once was not generating the file used required by my locale. Maybe if my browser language would have been in English it would have worked out the first time.
Well now it works as all the required files are correctly compiled.
I have web app, based on Spring 3.0.3, that I've been developing using Eclipse 3.4. While doing so I've been running the web app in Tomcat 6.0.18 from Eclipse. That is, I have Eclipse use the Tomcat installation meaning that Tomcat will, as need, modify files etc. (at least, that's my understanding of what it's doing).
My problem is specifying the values for the contextConfigLocations in the web.xml. When running from within Eclipse this worked fine:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
classpath:applicationContext-security.xml
</param-value>
</context-param>
However, when I package the app into a war file (ROOT.war) and then added it to Tomcat's webapp directory and the try to start Tomcat, I get an error that neither of these applicationContext files can be found. But when I change it to below, Tomcat can find the files:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/applicationContext.xml
/WEB-INF/config/applicationContext-security.xml
</param-value>
</context-param>
I should note that applicationContext.xml includes other applicationContext files that also use the classpath: short hand. When running within Tomcat, I need to drop all use of classpath: in favor of relative paths to get Tomcat to see these files.
Great. Tomcat and Eclise are getting along nicely. But JUnit 4.7 is no longer happy. For whatever reason, files specified using #ContextConfiguration in a test class can't be found unless the classpath: short hand is used. Here is an example:
#ContextConfiguration(locations = {"classpath:applicationContext.xml", "classpath:applicationContext-security.xml"})
public class UserDaoTest extends AbstractTransactionalJUnit4SpringContextTests {
#Test
public void testCreateUser() {
}
So applicationContext.xml and applicationContext-security.xml are found without a problem; however, property files that are specified in applicationContext.xml are not found.
<bean id="appProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="singleton" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>/WEB-INF/config/spring/base.spring-config.properties</value>
<value>/WEB-INF/config/spring/local.spring-config.properties</value>
</list>
</property>
</bean>
But if I specify the location of these files using the classpath: short hand, the property files are found. If I do this though, the files won't be found when running from a war file in Tomcat.
For now I've created a applicationContext-test.xml that is a cut-and-paste conglomeration of all of the other applicationContext files wherein I'm using the classpath: short hand. This seems hacky and error prone and I'm wondering what the issue might be across all of these technologies.
Feedback most welcome!
web.xml content should look like
<context-param>
<description>
Spring Context Configuration.
</description>
<param-name>contextConfigLocation</param-name>
<!-- spring loads all -->
<param-value>
classpath*:spring/*.xml,
classpath*:spring/persistence/*.xml,
classpath*:spring/webapp/*.xml</param-value>
</context-param>
see http://static.springsource.org/spring/docs/2.5.x/reference/resources.html#resources-app-ctx-wildcards-in-resource-paths for further reference
the junit config should follow the same convention with classpath*:
but beware spring might load .xml context files you don't want it to do