gwtrequestfactory

Error:ConstraintViolation in GWt requestfactory


Hi I am trying to use requestfactory and see if its a better choice than RPC.

I am facing an error whenever I am trying to run my GWT application as-

[ERROR] [exampledataextractrf] Uncaught exception escaped

com.google.web.bindery.event.shared.UmbrellaException: Exception caught: The call failed on the server due to a ConstraintViolation
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.violation(AbstractRequestContext.java:799)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$StandardPayloadDialect.processPayload(AbstractRequestContext.java:369)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$5.onTransportSuccess(AbstractRequestContext.java:1161)
    at com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport$1.onResponseReceived(DefaultRequestTransport.java:136)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:259)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
    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:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
    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:347)
    at sun.reflect.GeneratedMethodAccessor38.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:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: The call failed on the server due to a ConstraintViolation
    at com.google.web.bindery.requestfactory.shared.Receiver.onFailure(Receiver.java:44)
    at com.google.web.bindery.requestfactory.shared.Receiver.onViolation(Receiver.java:66)
    at com.google.web.bindery.requestfactory.shared.Receiver.onConstraintViolation(Receiver.java:107)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequest.onViolation(AbstractRequest.java:138)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.violation(AbstractRequestContext.java:779)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$StandardPayloadDialect.processPayload(AbstractRequestContext.java:369)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$5.onTransportSuccess(AbstractRequestContext.java:1161)
    at com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport$1.onResponseReceived(DefaultRequestTransport.java:136)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:259)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
    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:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
    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:347)
    at sun.reflect.GeneratedMethodAccessor38.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:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Unknown Source)

Following is the onClick code I am tryng to use

final Button buttonMessage = new Button("Click to get the complete list of Employees!!!");
    txtName.setWidth("200");
    logger.info(txtName.getValue());
    buttonMessage.addClickHandler(new ClickHandler() {  
          public void onClick(ClickEvent event) {
              buttonMessage.setEnabled(false);
              dataFlexTable.removeAllRows();
              dataFlexTable.setText(0, 0, "Employee ID");
              dataFlexTable.setText(0, 1, "Employee Name");
              dataFlexTable.setText(0, 2, "Department name");
              context.findAllEmployees().fire(
                      new Receiver<List<EmployeeProxy>>(){
                          @Override
                          public void onSuccess(List<EmployeeProxy> emp){
                              logger.info("Inside onSuccess");
                              addEmployee(emp);
                              txtName.setEnabled(true);
                              txtName.setText("");
                          }
                      });

          }});

And my EmployeeRequestfactory class goes as follows-

public interface EmployeeRequestFatory extends RequestFactory {
    @Service(value=EmployeeDAO.class, locator=DaoLocator.class)
    public interface EmployeeRequestContext extends RequestContext{
        Request<List<EmployeeProxy>> findAllEmployees();
        Request<List<EmployeeProxy>> findEmployee(String name);
    }
    EmployeeRequestContext context();
}

And findAllEmployees() method is as follows-

public List<Employee> findAllEmployees(){
        System.out.println("Inside Main Method");
        Connection con = null;
        ResultSet rs = null;
        Statement stmt=null;
         List<Employee> emp=new ArrayList<Employee>();
            try{  
                con = connectionUtil.getConnection();
                stmt = con.createStatement();
                rs = stmt.executeQuery("select * from Employee");
//              logger.log(Level.INFO,rs.toString());
                if(rs!=null){        
                    while(rs.next()) {
                        Employee employee=new Employee();
                        employee.setId(rs.getLong("EMP_ID"));
                        employee.setName(rs.getString("EMP_NAME"));
                        employee.setDepName(rs.getString("DEPT_NAME"));
                        emp.add(employee);
                    }
                }
        } catch (Exception e){
//          logger.log(Level.INFO,e.toString());
                e.printStackTrace(); 
        }finally{
            connectionUtil.closeResources(con, stmt, rs);
        }
            return emp;

    }

Any help will be appreciated :)


Solution

  • On the client-side, Receiver#onConstraintViolation is called “if an object sent to the server could not be validated”.

    That means you have something else in your code that leads to sending an object to the server (basically, a call to create() or edit() on your RequestContext, but it could also be a call to another of your methods than findAllEmployees that takes arguments), and on the server you have a JSR-303 validator (e.g. Hibernate Validator) that judges that the object is invalid. This is done before your server-side findAllEmployees is even called.

    To debug this, set a breakpoint inside ReflectiveServiceLayer#validate (server-side) and look for non-null return values.
    On the client-side, you might want to set a breakpoint inside AbstractRequestContext#takeOwnership and look at the callstack to determine what in your code leads to sending an object to the server.