this isn't my first RPC try. All others worked well, but I can't figure out, why this doesn't.
public void confirmRequest(String requestId, boolean confirmWithDefault, List<String> values, final String laneId){
AsyncCallback<Void> callback = new AsyncCallback<Void>(){
#Override
public void onFailure(Throwable caught)
{
// TODO Auto-generated method stub
}
#Override
public void onSuccess(Void result)
{
Window.alert("jo");
ServiceCalls.this.mainmenu.getSlidePanel().getLaneMenu().getProperLanes().get(laneId)
.getDefaultButton().setText("");
statusFor();
}
};
getLaneProxy().confirmRequest(requestId, confirmWithDefault, values, laneId, callback);
}
When I run the programm, it does not even throw an exception. It just doesn't do what it should do. Then I debugged it and saw that a ClassNotFoundException was thrown at this point.
AsyncCallback< Void> callback = new AsyncCallback<Void>()
Assuming you're using GWT 2.5.0, this is a known issue; upgrade to 2.5.1-rc1 where this is fixed.
I had the same Problem, and found the solution with gridDragon's help.
My problem was that the servlet configuration in web.xml was wrong and so my Impl class couldn't be found.
Related
I am trying to implement swiperefreshlayout and I am getting error at "this"
public class viewBets_activity extends ActionBarActivity {
SwipeRefreshLayout swipeLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewbets);
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorScheme(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
}
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
swipeLayout.setRefreshing(false);
}
}, 5000);
}
}
I am getting error at swipeLayout.setOnRefreshListener(this); screenshot below
Well, now that you added the screenshot, the error is clear.
You're passing the wrong argument into setOnRefreshListener()! And of course, this makes sense, if you think about it. Your class is a ActionBarActivity. You're trying to set the OnRefreshListener as an ActionBarActivity...doesn't make any sense! You need to change your code to this:
swipeLayout.setOnRefreshListener(new OnRefreshListener()
{
#Override
public void onRefresh()
{
// what you want to happen onRefresh goes here
}
});
Here, you're creating a new OnRefreshListener object which you're adding as the listener.
For the future, in general, any time you have a setOn______Listener() method, the argument you'll be passing will be a On_____Listener object that you've customized. You can either created separately, or create it right in the set method the way I did in my answer.
Your class is missing
implement SwipeRefreshLayout.OnRefreshListener
This allows the listener to refer to the overridden method onRefresh when passing through this as the argument for setOnRefreshListener
I use the GWT RequestBuilder, and for testing purposes, I'd like to load a json file in the server.
It works perfectly with the DevMode, but throw a 404 error with GWTTestCase.
With RPC, there is a fix adding <servlet path=".." class="..."/>, but what can I do with static content ?
I could easily use #TextResource, but it's not the goal of my UnitTest (which is in fact a functionnal test)
Static resources can be bundled with a module by putting them in the module's public path.
I used (once again) Thomas's answer to resolve the problem. My module is io.robusta.fora.comments.Comment.gwt.xml and I've put my user.json file in the io.robsuta.fora.comments.resources package.
I had so to add in Comment.gwt.xml file : <public path="resources"/>
Then the GWTTestCase is straightforward :
public class GwtRestClientTest extends GWTTestCase{
#Override
public String getModuleName() {
return "io.robusta.fora.comments.Comments";
}
public void testGET(){
String base = GWT.getModuleBaseURL();
System.out.println(base); //-> http://192.168.0.10:53551/io.robusta.fora.comments.Comments.JUnit/
GwtRestClient client = new GwtRestClient(base); //base url
AsyncCallback<String> cb = new AsyncCallback<String>() {
#Override
public void onSuccess(String result) {
System.out.println(result);//->{id:1,email:"jo#robusta.io"}
finishTest();
}
#Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
}
};
client.GET("user.json", null, cb);//fetch my json file with no params
delayTestFinish(3000);
}
}
I create a new Web Application Project with the standard GWT example. Then i want to test the greetingserviceimpl with the following test class. I don't know where is the problem. I also upload the project: http://ul.to/1pz1989y
public class RPCTest extends GWTTestCase {
#Override
public String getModuleName() {
// TODO Auto-generated method stub
return "de.GreetingTest";
}
public void testGreetingAsync() {
GreetingServiceAsync rpcService = (GreetingServiceAsync) SyncProxy.newProxyInstance(GreetingServiceAsync.class,"http://127.0.0.1:8888/GreetingTest.html?gwt.codesvr=127.0.0.1:9997");
rpcService.greetServer("GWT User", new AsyncCallback<String>() {
public void onFailure(Throwable ex) {
ex.printStackTrace();
fail(ex.getMessage());
}
public void onSuccess(String result) {
assertNotNull(result);
finishTest();//
}
});
delayTestFinish(1000);
}
}
Validating newly compiled units
Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
[ERROR] Line 17: No source code is available for type com.gdevelop.gwt.syncrpc.SyncProxy; did you forget to inherit a required module?
[ERROR] Unable to find type 'de.client.RPCTest'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
Your rpc service is async - it doesn't finish by the time that the testGreetingAsync method returns. GWTTestCase (but you are extending TestCase, you should probably change this) has support for this though - call delayTestFinish at the end of the method to indicate that the test is async. Then, call finishTest once you are successful.
public class RPCtest extends GWTTestCase {
public void testGreetingAsync() {
GreetingServiceAsync rpcService = (GreetingServiceAsync) SyncProxy.newProxyInstance(GreetingServiceAsync.class,"http://127.0.0.1:8888/Tests.html?gwt.codesvr=127.0.0.1:9997");
rpcService.greetServer("GWT User", new AsyncCallback() {
public void onFailure(Throwable ex) {
//indicate that a failure has occured
ex.printStackTrace();
fail(ex.getMessage());//something like this
}
public void onSuccess(Object result) {
//verify the value...
assertNotNull(result);
//Then, once sure the value is good, finish the test
finishTest();//This tells GWTTestCase that the async part is done
}
});
delayTestFinish(1000);//1000 means 'delay for 1 second, after that time out'
}
}
Edit for updated question:
The test class 'de.RPCTest' was not found in module 'de.GreetingTest'; no compilation unit for that type was seen
Just like your regular GWT code must be in a client package, so must your GWTTestCase code - this also gets run as JavaScript so it can properly be tested as if it were in a browser. Based on the error, I'm guessing your EntryPoint, etc are in de.client - this test should be there too.
I've tried to follow the GWT RPC sample codes, and i don't understand how the AsyncCallback's Onsuccess method result is being set. Anyone help me to understand the flow.
Thanks.
AsyncCallback<YourReturnType> callback = new AsyncCallback<YourReturnType>() {
#Override
public void onSuccess(YourReturnType result) {
//to do something with the result
}
#Override
public void onFailure(Exception ex) {
//to do something with exceptions
}
}
#Rajesh, I'm providing a link here. I hope this may help you.
I have example project StockWatcher using requestbuilder to communicate with servlet (this example). I want to make servlet asynchronous. I have added the following lines to the doGet method:
final AsyncContext ac = request.startAsync();
ac.setTimeout(1 * 60 * 1000);
ac.addListener(new AsyncListener() {
#Override
public void onError(AsyncEvent arg0) throws IOException {
System.out.println("onError");
}
public void onComplete(AsyncEvent event) throws IOException {
System.out.println("onComplete");
queue.remove(ac);
}
public void onTimeout(AsyncEvent event) throws IOException {
System.out.println("onTimeout");
queue.remove(ac);
}
#Override
public void onStartAsync(AsyncEvent arg0) throws IOException {
System.out.println("onStartAsync");
}
});
queue.add(ac);
added asynchronous annotation: #WebServlet(asyncSupported=true)
and changed the rest of doGet method with:
PrintWriter out = ac.getResponse().getWriter();
out.println("Something");
out.flush();
Now there is nothing returning. What do I wrong? Have to change something in client side? Glassfish 3 does not show any errors.
You are not doing anything wrong. GWT uses servlet 2.5 and it blocks if you try something async. I've the same problem right now although I use Vaadin (which uses GWT). A link I've found on the topic: http://comments.gmane.org/gmane.org.google.gwt/48496
There is a page claiming to have the problem solved: http://blog.orange11.nl/2011/02/25/getting-gwt-to-work-with-servlet-3-async-requests/
I have not been able to try this out yet.