/** * Return a JSON object literal with the contents of the store. */ public String encode() { // Backwards-compat: never store a '0' (see constructor) assert nextId >= 0; messageBean.as().setSyntheticId(nextId + 1); return AutoBeanCodex.encode(messageBean).getPayload(); }
domainReturnValue = AutoBeanCodex.encode(createFailureMessage(e)); ok = false;
private Splittable nonCollectionEncode(Object obj) { if (obj instanceof Collection) { // TODO: Allow for the encoding of nested collections. See issue 5974. // Once we do this, this can turn into an assert. throw new RuntimeException( "Unable to encode request as JSON payload; Request methods must have parameters of the form List<T> or Set<T>, where T is a scalar (non-collection) type."); } Splittable value; if (obj instanceof Enum && getAutoBeanFactory() instanceof EnumMap) { value = ValueCodex.encode(((EnumMap) getAutoBeanFactory()).getToken((Enum<?>) obj)); } else if (ValueCodex.canDecode(obj.getClass())) { value = ValueCodex.encode(obj); } else { // XXX user-provided implementation of interface? value = AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(obj)); } return value; } }
public String makePayload() { RequestData data = state.invocations.get(0).getRequestData(); AutoBean<JsonRpcRequest> bean = MessageFactoryHolder.FACTORY.jsonRpcRequest(); JsonRpcRequest request = bean.as(); request.setVersion("2.0"); request.setApiVersion(data.getApiVersion()); request.setId(payloadId++); Map<String, Splittable> params = new HashMap<String, Splittable>(); for (Map.Entry<String, Object> entry : data.getNamedParameters().entrySet()) { Object obj = entry.getValue(); Splittable value = encode(obj); params.put(entry.getKey(), value); } if (data.getRequestResource() != null) { params.put("resource", encode(data.getRequestResource())); } request.setParams(params); request.setMethod(data.getOperation()); return AutoBeanCodex.encode(bean).getPayload(); }
/** * Assemble all of the state that has been accumulated in this context. This includes: * <ul> * <li>Diffs accumulated on objects passed to {@link #edit}. * <li>Invocations accumulated as Request subtypes passed to {@link #addInvocation}. * </ul> */ public String makePayload() { // Get the factory from the runtime-specific holder. MessageFactory f = MessageFactoryHolder.FACTORY; List<OperationMessage> operations = makePayloadOperations(); List<InvocationMessage> invocationMessages = makePayloadInvocations(); // Create the outer envelope message AutoBean<RequestMessage> bean = f.request(); RequestMessage requestMessage = bean.as(); requestMessage.setRequestFactory(getRequestFactory().getFactoryTypeToken()); if (!invocationMessages.isEmpty()) { requestMessage.setInvocations(invocationMessages); } if (!operations.isEmpty()) { requestMessage.setOperations(operations); } return AutoBeanCodex.encode(bean).getPayload(); }
private void serializeOneProxy(SimpleProxyId<?> idForSerialization, AutoBean<? extends BaseProxy> bean) { AutoBean<OperationMessage> op = makeOperationMessage(serializedId(BaseProxyCategory.stableId(bean)), bean, false); store.put(getRequestFactory().getHistoryToken(idForSerialization), AutoBeanCodex.encode(op)); } }
resp.setInvocations(Collections.singletonList(invocation)); resp.setOperations(operations); return AutoBeanCodex.encode(bean);
/** * Process a payload sent by a RequestFactory client. * * @param payload the payload sent by the client * @return a payload to return to the client */ public String process(String payload) { RequestMessage req = AutoBeanCodex.decode(FACTORY, RequestMessage.class, payload).as(); AutoBean<ResponseMessage> responseBean = FACTORY.response(); try { process(req, responseBean.as()); } catch (ReportableException e) { // Create a new response envelope, since the state is unknown responseBean = FACTORY.response(); responseBean.as().setGeneralFailure(createFailureMessage(e).as()); } // Return a JSON-formatted payload return AutoBeanCodex.encode(responseBean).getPayload(); }
/** * EntityCodex support. */ public Splittable getSerializedProxyId(SimpleProxyId<?> stableId) { AutoBean<IdMessage> bean = MessageFactoryHolder.FACTORY.id(); IdMessage ref = bean.as(); ref.setServerId(stableId.getServerId()); ref.setTypeToken(getRequestFactory().getTypeToken(stableId.getProxyClass())); if (stableId.isSynthetic()) { ref.setStrength(Strength.SYNTHETIC); ref.setSyntheticId(stableId.getSyntheticId()); } else if (stableId.isEphemeral()) { ref.setStrength(Strength.EPHEMERAL); ref.setClientId(stableId.getClientId()); } return AutoBeanCodex.encode(bean); }
/** * EntityCodex support. This method is identical to * {@link IdFactory#getHistoryToken(SimpleProxyId)} except that it * base64-encodes the server ids and adds client ids for stable ids * that were ephemeral. * <p> * XXX: Merge this with AbstsractRequestContext's implementation */ public Splittable getSerializedProxyId(SimpleProxyId<?> stableId) { AutoBean<IdMessage> bean = MessageFactoryHolder.FACTORY.id(); IdMessage ref = bean.as(); ref.setTypeToken(service.resolveTypeToken(stableId.getProxyClass())); if (stableId.isSynthetic()) { ref.setStrength(Strength.SYNTHETIC); ref.setSyntheticId(stableId.getSyntheticId()); } else if (stableId.isEphemeral()) { ref.setStrength(Strength.EPHEMERAL); ref.setClientId(stableId.getClientId()); } else { if (stableId.wasEphemeral()) { ref.setClientId(stableId.getClientId()); } ref.setServerId(SimpleRequestProcessor.toBase64(stableId.getServerId())); } return AutoBeanCodex.encode(bean); }
/** * Return a JSON object literal with the contents of the store. */ public String encode() { // Backwards-compat: never store a '0' (see constructor) assert nextId >= 0; messageBean.as().setSyntheticId(nextId + 1); return AutoBeanCodex.encode(messageBean).getPayload(); }
@Override public String serialize(Object message) throws SerializationException { try { AutoBean<Object> bean = AutoBeanUtils.getAutoBean(message); return AutoBeanCodex.encode(bean).getPayload(); } catch (RuntimeException e) { throw new SerializationException(e); } }
/** * Return a JSON object literal with the contents of the store. */ public String encode() { // Backwards-compat: never store a '0' (see constructor) assert nextId >= 0; messageBean.as().setSyntheticId(nextId + 1); return AutoBeanCodex.encode(messageBean).getPayload(); }
@Override public String serialize(Object message) throws SerializationException { try { AutoBean<Object> bean = AutoBeanUtils.getAutoBean(message); return AutoBeanCodex.encode(bean).getPayload(); } catch (RuntimeException e) { throw new SerializationException(e); } }
/** * Return a JSON object literal with the contents of the store. */ public String encode() { // Backwards-compat: never store a '0' (see constructor) assert nextId >= 0; messageBean.as().setSyntheticId(nextId + 1); return AutoBeanCodex.encode(messageBean).getPayload(); }
private void serializeOneProxy(SimpleProxyId<?> idForSerialization, AutoBean<? extends BaseProxy> bean) { AutoBean<OperationMessage> op = makeOperationMessage(serializedId(BaseProxyCategory.stableId(bean)), bean, false); store.put(getRequestFactory().getHistoryToken(idForSerialization), AutoBeanCodex.encode(op)); } }
private void serializeOneProxy(SimpleProxyId<?> idForSerialization, AutoBean<? extends BaseProxy> bean) { AutoBean<OperationMessage> op = makeOperationMessage(serializedId(BaseProxyCategory.stableId(bean)), bean, false); store.put(getRequestFactory().getHistoryToken(idForSerialization), AutoBeanCodex.encode(op)); } }
private void serializeOneProxy(SimpleProxyId<?> idForSerialization, AutoBean<? extends BaseProxy> bean) { AutoBean<OperationMessage> op = makeOperationMessage(serializedId(BaseProxyCategory.stableId(bean)), bean, false); store.put(getRequestFactory().getHistoryToken(idForSerialization), AutoBeanCodex.encode(op)); } }
/** * Process exception and convert it to JSON object * @param phase * @param payload * @param e * @return */ private String processException(String phase, String payload, Throwable e) { AutoBean<ResponseMessage> responseBean = FACTORY.response(); // Create a new response envelope, since the state is unknown responseBean = FACTORY.response(); responseBean.as().setGeneralFailure(createFailureMessage(e).as()); String ret = AutoBeanCodex.encode(responseBean).getPayload(); // Return a JSON-formatted payload return ret; }
/** * EntityCodex support. */ public Splittable getSerializedProxyId(SimpleProxyId<?> stableId) { AutoBean<IdMessage> bean = MessageFactoryHolder.FACTORY.id(); IdMessage ref = bean.as(); ref.setServerId(stableId.getServerId()); ref.setTypeToken(getRequestFactory().getTypeToken(stableId.getProxyClass())); if (stableId.isSynthetic()) { ref.setStrength(Strength.SYNTHETIC); ref.setSyntheticId(stableId.getSyntheticId()); } else if (stableId.isEphemeral()) { ref.setStrength(Strength.EPHEMERAL); ref.setClientId(stableId.getClientId()); } return AutoBeanCodex.encode(bean); }