开发者

gwt RPC is not working

开发者 https://www.devze.com 2023-02-08 00:59 出处:网络
what is the wrong in my code.. Public MyServiceAsync my=GWT.create(MyService.class); HTML serverResponseLabel = new HTML();

what is the wrong in my code..

Public MyServiceAsync my=GWT.create(MyService.class);
    HTML serverResponseLabel = new HTML();
    public void onModuleLoad() {
        final Label errorLabel = new Label();
        RootPanel rootPanel = RootPanel.get();
        rootPanel.setSize("100%", "100%");
        rootPanel.add(errorLabel);
        serverResponseLabel=new HTML();
        rootPanel.add(serverResponseLabel);

        Button btnSearch = new Button("Search");
        rootPanel.add(btnSearch, 558, 110);
        btnSearch.setSize("63px", "29px");
                 btnSearch.addClickHandler(this);


    }
    @Override
    public void onClick(ClickEvent event) {
        // TODO Auto-generated method stub
        System.out.println("clicked");
        my.myMethod("ka",new AsyncCallback<String>() {
            public void onFailure(Throwable caught) {
                serverResponseLabel.setHTML(SERVER_ERROR);
            }

            public void onSuccess(String result) {
                serverResponseLabel.setHTML(result);
            }
        });
}

Sync
public interface MyService extends RemoteService {
  public String myMethod(String s);
}
Async
public interface MyServiceAsync {
  public void myMethod(String s, AsyncCallback<String> callback);
}

synImple
public class MyServiceImpl extends RemoteServiceServlet implements MyService {

  public String myMethod(String s) {

    return s+"example";
  }
}

i am getting an uncaught exception escaped error.....

com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
    at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:214)
    at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103)
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:96)
    at co开发者_Python百科m.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:107)
    at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
    at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:155)
    at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1308)
    at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1264)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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:157)
    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:126)
    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.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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:157)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.user.client.rpc.ServiceDefTarget$NoServiceEntryPointSpecifiedException: Service implementation URL not specified
    at com.google.gwt.user.client.rpc.impl.RemoteServiceProxy.doPrepareRequestBuilderImpl(RemoteServiceProxy.java:326)
    at com.google.gwt.user.client.rpc.impl.RemoteServiceProxy.doInvoke(RemoteServiceProxy.java:265)
    at com.test.test.client.MyService_Proxy.myMethod(MyService_Proxy.java:37)
    at com.test.test.client.Test.onClick(Test.java:70)
    at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:54)
    at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:1)
    at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:204)
    at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103)
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:96)
    at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:107)
    at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
    at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:155)
    at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1308)
    at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1264)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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:157)
    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:126)
    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.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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:157)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
    at java.lang.Thread.run(Unknown Source)


You need to add @RemoteServiceRelativePath("some.path") to you interface.

See this tutorial.


When running your RPC call, development mode displays an exception NoServiceEntryPointSpecifiedException: Service implementation URL not specified. This error means that you did not specify a @RemoteServiceRelativePath in your service interface, and you also did not manually set target path by calling ServiceDefTarget.setServiceEntryPoint().

ServiceDefTarget target = (ServiceDefTarget) yourService;
target.setServiceEntryPoint(GWT.getModuleBaseURL() + "yourpath");

Also note this one that's closely related to above one, If invoking your RPC call fails with a 404 StatusCodeException, your web.xml may be misconfigured. Make sure you specified a @RemoteServiceRelativePath and that the specified in your web.xml matches this value, prepended with the location of your GWT output directory within the war directory.

For every annotation definition given above, corresponding entry for service impl should be given in web deployment descriptor i.e web.xml. As an example,

<servlet>
    <servlet-name>sampleServlet</servlet-name>
    <servlet-class>samples.gwt.SampleServiceImpl</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>sampleServlet</servlet-name>
    <url-pattern>/sample-gwt-module/sampleService</url-pattern>
</servlet-mapping>

where

sample-gwt-module

is the (alternate) name of the sample GWT module as defined in module definition as

0

精彩评论

暂无评论...
验证码 换一张
取 消