send error from server to client

4 views
Skip to first unread message

robert_trudel

unread,
Sep 5, 2008, 5:56:17 AM9/5/08
to Google Web Toolkit
hi

i use gwt ans struts
i would like to send server error to the client

i created a small project

the console error i get when i call the method who suppose to return
me the error
[code]
com.google.gwt.user.server.rpc.UnexpectedException: S
ervice method 'public java.lang.String
org.yournamehere.action.WebErrorAction.myMethod(java.lang.String)
throws org.yournamehere.client.ErrorManager'
threw an unexpected exception:
java.lang.reflect.InvocationTargetException
[/code]

my action
[code]
public class WebErrorAction extends RemoteServiceServlet implements
GWTService {

public WebErrorAction() {
}

public String myMethod(String s) throws ErrorManager {
GWTServiceImpl serviceImpl = new GWTServiceImpl();
return serviceImpl.myMethod(s);
}
}
[/code]

my error class
[code]
public class ErrorManager extends Exception implements IsSerializable
{

private String errorManager;

public ErrorManager() {
}

public ErrorManager(String errorManager) {
this.errorManager = errorManager;
}

public String getErrorManager() {
return this.errorManager;
}
}
[/code]

my service
[code]
public interface GWTService extends RemoteService{
public String myMethod(String s) throws ErrorManager;
}
[/code]

service async
[code]
public interface GWTServiceAsync {
public void myMethod(String s, AsyncCallback callback);
}
[/code]



client side, we call the service
[code]
public void callService(String s) {
GWTServiceAsync service = (GWTServiceAsync)
GWT.create(GWTService.class);

AsyncCallback callback = new AsyncCallback() {

public void onSuccess(Object result) {
lblServerReply.setText((String) result);
}

public void onFailure(Throwable caught) {

String details = caught.getMessage();
if (caught instanceof ErrorManager) {
details = ((ErrorManager)
caught).getErrorManager() + " occured";
}
Window.alert("error " + details);
}
};

ServiceDefTarget endpoint = (ServiceDefTarget) service;
endpoint.setServiceEntryPoint("WebErrorAction.action");
service.myMethod(s, callback);
}
[/code]

implementation of the service method... i generate directely an error
to see if the server will send the error to the client...

[code]
public class GWTServiceImpl extends RemoteServiceServlet implements
GWTService {

public String myMethod(String s) throws ErrorManager {
throw new ErrorManager("error occured " + s);
}
}
[/code]

on the client side, onFailure is called

because i get this message

[code]
error: The call failed on the server; see server log for details
[/code]

it's like if ErrorManager would be unknow...

any idea?

robert_trudel

unread,
Sep 5, 2008, 6:51:14 AM9/5/08
to Google Web Toolkit
Reply all
Reply to author
Forward
0 new messages