Example usage for com.google.gwt.requestfactory.server SimpleRequestProcessor process

List of usage examples for com.google.gwt.requestfactory.server SimpleRequestProcessor process

Introduction

In this page you can find the example usage for com.google.gwt.requestfactory.server SimpleRequestProcessor process.

Prototype

public String process(String payload) 

Source Link

Document

Process a payload sent by a RequestFactory client.

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 "";
    }/*  w  w w  . jav a2  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();
}