File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes GWT and the fly likes Saving a file under my GWT project's '/war' path - Security Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "Saving a file under my GWT project Watch "Saving a file under my GWT project New topic
Author

Saving a file under my GWT project's '/war' path - Security Exception

Berkan Sesen
Greenhorn

Joined: Oct 04, 2011
Posts: 12
Hello,

I am designing a web application using GWT. I use an OWL ontology, stored under the 'war/WEB-INF/Ontology' path in my war folder.
I can access this ontology through my UI on the clientside wihtout any problems.

When a user modifies the details of an ontology entry through my UI and clicks on 'Save', I want the server side to save the updated ontologyto the same path ('war/WEB-INF/Ontology').
However, when I try to do this, I get the error below:

I am badly stuck.

Any help would be greatly appreciated!

Thanks,
berkan

---------




---------
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Welcome to the Ranch.
Looks like you got a GWT+GAE project. You cannot open sockets or write files on GAE.
http://code.google.com/appengine/docs/whatisgoogleappengine.html Check out the Sandbox section


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Berkan Sesen
Greenhorn

Joined: Oct 04, 2011
Posts: 12
Thank you very much Maneesh! Yes, I use GAE and after reading the link you've sent, I believe that is the reason I get the security exception.

Would it be possible for me to deploy a GWT applciation outsde the GAE then? Would that mean I have to set up my own server?

Do you know of any tutorials on this maybe?

I am a newbie in web applications so I will appreciate any pointers on this.

Best,
Berkan
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Berkan Sesen wrote:Would it be possible for me to deploy a GWT applciation outsde the GAE then? Would that mean I have to set up my own server?

Yes it is definitely possible. One important point to remember is if you are using any GAE features, you will of course need to code that part yourself.

For development mode, you need not set up any server. Presuming you are using Eclipse
1) I am not sure it will work, if you edit your existing project and uncheck the box. I haven't tried it so no idea. If not, create a GWT only project (uncheck the user GAE box).
2) Write code, test, fix bugs, test etc.
3) Once done, follow the steps mentioned here to package your war
4) Once packaged, you can deploy it on any server just like any other web application. Depending on your server, deployment steps might vary. In case you are using Tomcat, check out this page.
Berkan Sesen
Greenhorn

Joined: Oct 04, 2011
Posts: 12
Thanks again Maneesh,

I believe I am close to the solution now. I am applying what you've said to a trial Eclipse-GWT project called GWTSimple, which was created with "Use Google App Engine" option checked.

1 - I have unchecked it under Project Properties -> Google -> App Engine.

2- I have completed until step 3 and have created my GWTSimple.war file

3- Futhermore, I believe I have managed to setup a tomcat server to run in Eclipse. I have attached a screenshot of how it looks in my Eclipse environment.
I can click and Start this Tomcat v7.0 server .



Now, I have never deployed a web application before, what would be my next step? Do I have to right click my GWTSimple Project -> Run As -> 4 Web Application (Running on External Server)?
I have looked at a few web pages that explain setting up and running TomCat on Eclipse, such as: http://greatwebguy.com/programming/eclipse/make-eclipse-and-tomcat-play-nice-together/ . However, I don't believe what they explain on this page is applicable to a GWT project.

Best,
Berkan
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Berkan Sesen wrote:Futhermore, I believe I have managed to setup a tomcat server to run in Eclipse. I have attached a screenshot of how it looks in my Eclipse environment.
I can click and Start this Tomcat v7.0 server .

You don't really need this because the GWT plugin will run it on Jetty for you (Jetty is installed along with the plugin)
Just right click->Debug as web application. The eclipse console view will tell if when it's up.
Open your favorite browser and point it to http://localhost:8888

For running on external server, please refer http://code.google.com/webtoolkit/doc/latest/DevGuideCompilingAndDebugging.html#How_do_I_use_my_own_server_in_development_mode_instead_of_GWT's
I never bother with it. Jetty suits me just fine.
Berkan Sesen
Greenhorn

Joined: Oct 04, 2011
Posts: 12
When I right click on my Project (GWTSimple), which also contains the GWTSimple.war and click Debug As -> Web Application, I get this error below:
( Of course, when I re-check the "Use GAE" option of the project, Debug As Web Applciation works fina as usual, but under the GAE.)


Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Looks like you are missing some jars.
Project->RIght Click->Properties->Java Build Path->Libraries tab
Do you see the GWT SDK Lib entry? Any others?


[Thumbnail for buildPath.png]

Berkan Sesen
Greenhorn

Joined: Oct 04, 2011
Posts: 12
Hello Maneesh,

Yes, I see the GWT SDK Lib. I have attached the screenshot. I thought the reason I was getting the error was because I uncheck the "Use GAE" tickbox. The moment I check it, the project runs and debugs fine - albeit in GAE .

Berkan

[img]
http://img254.imageshack.us/img254/4154/gwtsimplebuildpath.png[/img]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Remove all the jars except the GWT SDK and JRE libraries and try again
Berkan Sesen
Greenhorn

Joined: Oct 04, 2011
Posts: 12
Hi Maneesh,

OK, I think it almost worked. I cleaned the jars and when I 'Debugged as Web Application', I got the URL displayed at the Development Mode view (see below).



Instead of double clicking on the URL in the development view, I typed http://localhost:8888 in my browser and got this error pop-up window: "GWT module 'gwtsimple' may need to be (re)compiled". I think this means that the server actually worked but there was some other problem with the project.

So, I searched and found this warning (quote - below) on http://blog.elitecoderz.net/gwt-and-tomcat-create-war-using-eclipse-to-deploy-war-on-tomcat/2009/12/ about this 'recompilation' error message.

It is important to note, that prior to performing any of the jar / war creation steps, you need to (in Eclipse):
1- perform a clean on the project making sure the “Start a build automatically ” checkbox is NOT checked;
2- right click on the project and select Google, followed by GWT Compile
3- Then build the jar and war file as described above.
Otherwise, after you deploy the war to Apache Tomcat the error “gwt module may need to be (re)compiled” will appear, when you click on the application to bring it up in a browser.


Now, I have indeed repeated the .war creation process with recompiling the project (as in Step 2 above). However, it did not work.

I am hoping it is because I skipped the first step. Do you know how I can 'perform a clean on the project' and how I can deactivate 'Start a build automatically' for a single project ? I got a bit confused about the Step 1.

Thank you very much,
Berkan
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

For dev mode, you do not need a clean build. Just double click the link on the console. If you are running the GWT in dev mode from your browser, it will prompt you to install the browser plugin. Follow on screen instructions and you should be ready to go.
Berkan Sesen
Greenhorn

Joined: Oct 04, 2011
Posts: 12
Dear Maneesh,

Thank you so very much! I am really grateful, it is finally resolved. When I create the .war file (as described in the link you've given) and uncheck 'Run with GAE' under project properties, I can now Run or Debug through Jetty (without GAE) under Development Mode, just by clicking on the URL. Also as you said, when I run thorugh Jetty (without GAE), I can actually write files to my war/Web-INF folder!

The good thing is when I re-check 'Run with GAE', I can run the application in GAE without having to change anything.

I have a quick question though, regarding 'debugging'. When I am running through Jetty (without GAE), I thought Jetty runs the application through the <projectname>.war file I have created. Therefore, I did not expect the changes I make to my code (classes) under the /src folder to be reflected on the applciation before I recreate another <projectname>.war file. In other words, I thought real-time debugging was not going to be possible. However, whatever change I make to my /src classes, I can see their effect immediately, without having to recreate the .jar or .war files. Could you explain why this is possible?

Best,
Berkan
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

Thats what I meant when I was referring to the dev mode.
When you run your application in the IDE, it by default uses Jetty. Like you have already noticed, it hot deploys the changes, provided you are using the browser plugin (ULR with the codesvr part)
In general, you should follow this pattern

1) Create project
2) Code
3) Run/Debug as web application
4) Use the browser plugin (double clicking the URL in the console)
5) Test/Debug etc.
6) Confirm you are done with all development
This is the end of development phase. Note you never needed to build the war. The eclipse plugin handles everything for you.

When you want to deploy it on some production server like Tomcat, only then you need to create the war. Build the war and deploy the war on the production server.
Berkan Sesen
Greenhorn

Joined: Oct 04, 2011
Posts: 12
Hi Maneesh,

Brilliant. It is all clear now. Again, can't thank you enough for your kind and persistent help.
I do have some other questions but now they are related to server deployment, etc. So will not post them under the GWT forum.

Best wishes,
Berkan
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

You are welcome. Glad I could help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving a file under my GWT project's '/war' path - Security Exception
 
Similar Threads
database connection problem in gwt
Greetings Eclipse Gwt Project - jdbc connection problems java.lang.ExceptionInInitializerError
Error starting Applikation in Eclipse Developer Mode
Problems connecting to a database
GWT with database connection