PageRenderTime 107ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/example/src/main/java/example/test/Main.java

https://code.google.com/p/gwtrpccommlayer/
Java | 202 lines | 126 code | 31 blank | 45 comment | 0 complexity | 239c36da0d1bebcb5185944145172817 MD5 | raw file
  1. /*
  2. * Copyright 2010 Jeff McHugh (Segue Development LLC)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  5. * in compliance with the License. You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software distributed under the License
  10. * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  11. * or implied. See the License for the specific language governing permissions and limitations under
  12. * the License.
  13. */
  14. package example.test;
  15. import com.google.gwt.user.client.rpc.AsyncCallback;
  16. import com.googlecode.gwtrpccommlayer.client.GwtRpcService;
  17. import com.googlecode.gwtrpccommlayer.client.impl.GwtRpcCommLayerClient;
  18. import example.client.GreetingService;
  19. import example.client.GreetingServiceAsync;
  20. import example.shared.UserFormData;
  21. import java.net.URL;
  22. import java.util.ArrayList;
  23. public class Main
  24. {
  25. public Main()
  26. {
  27. }
  28. public void doAsynchronousCalls() throws Exception
  29. {
  30. GwtRpcService service = GwtRpcService.FACTORY.newInstance();
  31. System.out.println("doAsynchronousCalls --Start--");
  32. URL url = new URL("http://127.0.0.1:8888/example/greet?gwt.codesvr=127.0.0.1:9997");
  33. //GwtRpcCommLayerClient client = new GwtRpcCommLayerClient(url);
  34. /*
  35. * NOTE: to make use of asynchronous mode, pass in your GWT asynch class
  36. */
  37. //GreetingServiceAsync stub = (GreetingServiceAsync) client.createRemoteServicePojoProxy(GreetingServiceAsync.class);
  38. GreetingServiceAsync stub = service.create(url, GreetingServiceAsync.class);
  39. /*
  40. * REQUEST 1
  41. */
  42. UserFormData formData = new UserFormData();
  43. formData.setAccountId("jsmith@gmail.com");
  44. formData.setName("jake smith");
  45. formData.setAge(32);
  46. stub.addUserFormData(formData, new AsyncCallback<String>()
  47. {
  48. public void onSuccess(String result)
  49. {
  50. System.out.println("Asynch-Call #1 Result->" + result);
  51. }
  52. public void onFailure(Throwable caught)
  53. {
  54. System.out.println("Asynch-Call #1 Failure " + caught);
  55. }
  56. });
  57. System.out.println("Executed Asynch-Call #1 ");
  58. /*
  59. * REQUEST 2
  60. */
  61. UserFormData formData2 = new UserFormData();
  62. formData2.setAccountId("maryt@gmail.com");
  63. formData2.setName("mary taylor");
  64. formData2.setAge(27);
  65. stub.addUserFormData(formData2, new AsyncCallback<String>()
  66. {
  67. public void onSuccess(String result)
  68. {
  69. System.out.println("Asynch-Call #2 Result->" + result);
  70. }
  71. public void onFailure(Throwable caught)
  72. {
  73. System.out.println("Asynch-Call #2 Failure " + caught);
  74. }
  75. });
  76. System.out.println("Executed Asynch-Call #2 ");
  77. /*
  78. * REQUEST 3
  79. */
  80. stub.getUserFormDataCount(new AsyncCallback<Integer>()
  81. {
  82. public void onSuccess(Integer result)
  83. {
  84. System.out.println("Asynch-Call #3 Result->" + result);
  85. }
  86. public void onFailure(Throwable caught)
  87. {
  88. System.out.println("Asynch-Call #3 Failure " + caught);
  89. }
  90. });
  91. System.out.println("Executed Asynch-Call #3 ");
  92. /*
  93. * REQUEST 4
  94. */
  95. stub.getUserFormData(0,1,new AsyncCallback<UserFormData[]>()
  96. {
  97. public void onSuccess(UserFormData[] result)
  98. {
  99. ArrayList<UserFormData> list = new ArrayList<UserFormData>();
  100. list.addAll(java.util.Arrays.asList(result));
  101. System.out.println("Asynch-Call #4 Result->" + list);
  102. }
  103. public void onFailure(Throwable caught)
  104. {
  105. System.out.println("Asynch-Call #4 Failure " + caught);
  106. }
  107. });
  108. System.out.println("Executed Asynch-Call #4 ");
  109. System.out.println("doAsynchronousCalls --End--");
  110. }
  111. public void doSynchronousCalls() throws Exception
  112. {
  113. System.out.println("doSynchronousCalls --Start--");
  114. URL url = new URL("http://127.0.0.1:8888/example/greet?gwt.codesvr=127.0.0.1:9997");
  115. GwtRpcCommLayerClient client = new GwtRpcCommLayerClient(url);
  116. GreetingService stub = (GreetingService) client.createRemoteServicePojoProxy(GreetingService.class);
  117. /*
  118. * REQUEST 1
  119. */
  120. UserFormData formData = new UserFormData();
  121. formData.setAccountId("jsmith@gmail.com");
  122. formData.setName("jake smith");
  123. formData.setAge(32);
  124. String resp = stub.addUserFormData(formData);
  125. System.out.println("Response 1 ->> " + resp);
  126. /*
  127. * REQUEST 2
  128. */
  129. UserFormData formData2 = new UserFormData();
  130. formData2.setAccountId("maryt@gmail.com");
  131. formData2.setName("mary taylor");
  132. formData2.setAge(27);
  133. String resp2 = stub.addUserFormData(formData2);
  134. System.out.println("Response 2 ->> " + resp2);
  135. /*
  136. * REQUEST 3
  137. */
  138. Integer resp3 = stub.getUserFormDataCount();
  139. System.out.println("Response 3 ->> " + resp3);
  140. /*
  141. * REQUEST 4
  142. */
  143. UserFormData[] resp4 = stub.getUserFormData(0, resp3);
  144. ArrayList<UserFormData> list = new ArrayList<UserFormData>();
  145. list.addAll(java.util.Arrays.asList(resp4));
  146. System.out.println("Response 4 ->> " + list);
  147. System.out.println("doSynchronousCalls --End--");
  148. }
  149. public void run()
  150. {
  151. try
  152. {
  153. doSynchronousCalls();
  154. System.out.println("");
  155. System.out.println("");
  156. doAsynchronousCalls();
  157. }
  158. catch(Exception e)
  159. {
  160. e.printStackTrace();
  161. }
  162. }
  163. /**
  164. * @param args
  165. */
  166. public static void main(String[] args)
  167. {
  168. Main main = new Main();
  169. main.run();
  170. }
  171. }