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

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

Introduction

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

Prototype

public SimpleRequestProcessor(ServiceLayer serviceLayer) 

Source Link

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  ww  .  ja  v  a2s .com

    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();
}