Example usage for com.google.gwt.autobean.shared AutoBeanCodex decode

List of usage examples for com.google.gwt.autobean.shared AutoBeanCodex decode

Introduction

In this page you can find the example usage for com.google.gwt.autobean.shared AutoBeanCodex decode.

Prototype

public static <T> AutoBean<T> decode(AutoBeanFactory factory, Class<T> clazz, String payload) 

Source Link

Document

Decode an AutoBeanCodex payload.

Usage

From source file:com.acme.gwt.server.TvViewerJsonBootstrap.java

License:Apache License

public String getViewerAsJson() {
    SimpleRequestProcessor p = new SimpleRequestProcessor(ServiceLayer.create(isld));
    TvViewer user = viewerProvider.get();
    if (user == null) {
        return "";
    }/*  ww  w . j  a  v a  2 s .co  m*/

    MessageFactory factory = MessageFactoryHolder.FACTORY;
    AutoBean<IdMessage> id = factory.id();
    try {
        id.as().setServerId(Base64Utils.toBase64(user.getId().toString().getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
        return "";
    }
    id.as().setStrength(Strength.PERSISTED);
    id.as().setTypeToken(TvViewerProxy.class.getName());

    AutoBean<RequestMessage> msg = factory.request();
    msg.as().setInvocations(new ArrayList<InvocationMessage>());
    InvocationMessage invocation = factory.invocation().as();
    invocation.setOperation("com.google.gwt.requestfactory.shared.impl.FindRequest::find");
    invocation.setParameters(new ArrayList<Splittable>());
    invocation.getParameters().add(AutoBeanCodex.encode(id));
    msg.as().getInvocations().add(invocation);

    String value = p.process(AutoBeanCodex.encode(msg).getPayload());

    ResponseMessage response = AutoBeanCodex.decode(factory, ResponseMessage.class, value).as();
    OperationMessage opMsg = response.getOperations().get(0);
    DefaultProxyStore store = new DefaultProxyStore();
    store.put(TvViewerProxy.STORE_KEY, AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(opMsg)));

    return store.encode();
}