GWT RequestFactory抛出java.lang.UnsupportedOperationException异常:< Proxy interface class>来自ValueCodex.getTypeOrDie [英] GWT RequestFactory throws java.lang.UnsupportedOperationException: <Proxy interface class> from ValueCodex.getTypeOrDie

查看:152
本文介绍了GWT RequestFactory抛出java.lang.UnsupportedOperationException异常:< Proxy interface class>来自ValueCodex.getTypeOrDie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,我们需要在GWT客户端和服务器之间共享域代码。正因为如此,我们正在为GWT代理和服务器端实体使用通用接口。这种方法曾由@ thomas-broyer在这里描述过: https://stackoverflow.com/a/15852887/187241



异常堆栈跟踪:

  ERROR com .google.web.bindery.requestfactory.server.SimpleRequestProcessor  - 处理请求时出错
com.google.web中的java.lang.UnsupportedOperationException:se.homework.hwbs.domain.shared.model.IAppointment
.bindery.autobean.shared.ValueCodex.getTypeOrDie(ValueCodex.java:388)
at com.google.web.bindery.autobean.shared.ValueCodex.decode(ValueCodex.java:312)
at com .google.web.bindery.requestfactory.shared.impl.EntityCodex.decode(EntityCodex.java:107)
at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor $ 3.visitReferenceProperty(SimpleRequestProcessor.java:633 )
,位于com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean .java:370)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:162)
at com.google.web.bindery.autobean.shared .impl.AbstractAutoBean.accept(AbstractAutoBean.java:97)
at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.processOperationMessages(SimpleRequestProcessor.java:623)

 <$ c 

$ c> public interface IAppointment {
IPlace getPlace();
}

public interface AppointmentProxy extends EntityProxy,IAppointment {
@Override
PlaceProxy getPlace();
}

public interface PlaceProxy extends EntityProxy,IPlace {
@Override
Long getId();
}

public interface IPlace extends IDatabaseEntity {
@Override
Long getId();
}

public interface IDatabaseEntity {
public Long getId();





$ b

如果我们正确地忽略了GWT代码,问题的原因来自 ProxyAutoBean

  for(方法method:beanType.getMethods()){
if(BeanMethod.GET.matches(method)){
toReturn.getters.add(method);

其中 beanType AppointmentProxy.class 。 Java反射为这样的接口返回两个方法(仅在超级开发模式下发生......)

  public ** abstract ** PlaceProxy AppointmentProxy.getPlace()
public ** default ** IPlace AppointmentProxy.getPlace()

第一个预期并被GWT RequestFactory代码接受,第二个不是......并且它导致 java.lang.UnsupportedOperationException:IAppointment 异常。非常奇怪的事实是,我们只有在编译过的GWT应用程序中才有这个问题。当我们使用超级开发模式从IDE启动应用程序时,第二个默认... 方法未列出,并且应用程序正常运行。

环境:




  • GWT 2.6 .1

  • Java版本1.8.0_66



有关如何解决或解决问题的想法?

https://github.com/gwtproject/gwt/issues/5925 已在2.7中修复。


In our application we need to share domain code between GWT client and server. Because of that we are using common interfaces for GWT proxies and server-side entities. This approach was once described by @thomas-broyer here: https://stackoverflow.com/a/15852887/187241

Exception stacktrace:

    ERROR com.google.web.bindery.requestfactory.server.SimpleRequestProcessor - Error while processing request 
    java.lang.UnsupportedOperationException: se.homework.hwbs.domain.shared.model.IAppointment
        at com.google.web.bindery.autobean.shared.ValueCodex.getTypeOrDie(ValueCodex.java:388)
        at com.google.web.bindery.autobean.shared.ValueCodex.decode(ValueCodex.java:312)
        at com.google.web.bindery.requestfactory.shared.impl.EntityCodex.decode(EntityCodex.java:107)
        at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor$3.visitReferenceProperty(SimpleRequestProcessor.java:633)
        at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.traverseProperties(ProxyAutoBean.java:370)
        at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.traverse(AbstractAutoBean.java:162)
        at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.accept(AbstractAutoBean.java:97)
        at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.processOperationMessages(SimpleRequestProcessor.java:623)

Shared code:

    public interface IAppointment {
        IPlace getPlace();
    }

    public interface AppointmentProxy extends EntityProxy, IAppointment {
        @Override
        PlaceProxy getPlace();
    }

    public interface PlaceProxy extends EntityProxy, IPlace {
        @Override
        Long getId();
    }

    public interface IPlace extends IDatabaseEntity {
        @Override
        Long getId();
    }

    public interface IDatabaseEntity {
        public Long getId();
    }

If we understtod GWT code correctly, the reason of the problem comes from ProxyAutoBean:

    for (Method method : beanType.getMethods()) {
        if (BeanMethod.GET.matches(method)) {
            toReturn.getters.add(method);

where beanType is AppointmentProxy.class. Java reflection returns two methods for such interface (happens only in Super Dev Mode...):

    public **abstract** PlaceProxy AppointmentProxy.getPlace()
    public **default** IPlace AppointmentProxy.getPlace()

The first one is expected and accepted by GWT RequestFactory code, the second one is not... And it causes java.lang.UnsupportedOperationException: IAppointment exception. The very weird fact is that we have this issue only in compiled GWT application. When we launch an application from IDE using Super Dev Mode, the second default ... method is not listed and application is working without errors.

Environment:

  • GWT 2.6.1
  • Java version 1.8.0_66

Do you have any ideas about how to fix or workaround the issue?

解决方案

This could be https://github.com/gwtproject/gwt/issues/5925 which has been fixed in 2.7.

这篇关于GWT RequestFactory抛出java.lang.UnsupportedOperationException异常:&lt; Proxy interface class&gt;来自ValueCodex.getTypeOrDie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆