Access static file from onModuleLoad() method

142 views
Skip to first unread message

AThinerCoin

unread,
Aug 29, 2011, 10:45:54 PM8/29/11
to google-we...@googlegroups.com
I'd like to access a static file, let's say config.xml from my onModuleLoad method. 

It says on this webpage, that config.xml should live in the public sibling dir of my .gwt.xml file, but I've tried that and onModuleLoad function still gives me the error below.

It also suggests that I add a line to the .gwt.xml file like   <public path='public'/>  but that isn't working for me either.

http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html

I've tried searching for an example, but I don't see one.

com.google.gwt.xml.client.impl.DOMParseException: Failed to parse: error on line 1 at column 1: Document is empty

    at com.google.gwt.xml.client.impl.XMLParserImplSafari.throwDOMParseException(XMLParserImplSafari.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.xml.client.impl.XMLParserImplSafari.parseImpl(XMLParserImplSafari.java)
    at com.google.gwt.xml.client.impl.XMLParserImpl.parse(XMLParserImpl.java:278)
    at com.google.gwt.xml.client.XMLParser.parse(XMLParser.java:47)
    at com.java2s.gwt.client.client.GWTClient.loadConfig(GWTClient.java:56)
    at com.java2s.gwt.client.client.GWTClient.onModuleLoad(GWTClient.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
    at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:193)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Thread.java:680)

Thank you for your help!

Alexandre Ardhuin

unread,
Aug 30, 2011, 3:56:13 AM8/30/11
to google-we...@googlegroups.com
Hi,

You should have the following :
/MyModule.gwt.xml
/public/config.xml

Then, you can access file with the URL : GWT.getModuleBaseURL() + "config.xml"

An other way to load content is to use a TextResource with ClientBundle ( see http://code.google.com/webtoolkit/doc/latest/DevGuideClientBundle.html#TextResource )

Alexandre


2011/8/30 AThinerCoin <athin...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/hn3FEy1zmZAJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

AThinerCoin

unread,
Sep 1, 2011, 2:01:46 PM9/1/11
to google-we...@googlegroups.com
Thank you for your help.  This helped me get my source code to find my config.xml file.

For anyone else who has a similar problem, I also had to make a request for the file, then use the "getText" method, then I could read the file.  I could not just use the file based on the file's path.  See the example below.

        try {
            String fn = GWT.getModuleBaseURL() + "config.xml";
            RequestBuilder requestBuilder = new RequestBuilder(
                    RequestBuilder.GET, fn);
            try {
                requestBuilder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable exception) {
                        GWT.log("failed file reading", exception);
                    }

                    public void onResponseReceived(Request request,
                            Response response) {
                        result = response.getText();
                        Config graphConfig = new Config(result);
                        callToMethodThatUsesGraphConfig(graphConfig);
                    }
                });
            } catch (RequestException e) {
                GWT.log("failed file reading", e);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

kim young ill

unread,
Sep 1, 2011, 3:03:48 PM9/1/11
to google-we...@googlegroups.com
it's running in browser, so u have to access it via http, the servers filesystem is not available



        }
    }

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
Reply all
Reply to author
Forward
0 new messages