use of com.linkedin.restli.server.UnstructuredDataReactiveResult in project rest.li by linkedin.
the class GreetingUnstructuredDataCollectionResourceReactive method get.
@Override
public void get(String key, @CallbackParam Callback<UnstructuredDataReactiveResult> callback) {
if (key.equals("callbackError")) {
callback.onError(new NoPermissionException("missing access permission"));
return;
}
Writer<ByteString> writer = chooseGreetingWriter(key);
String contentType;
if (key.equals("goodNullContentType")) {
contentType = null;
} else {
contentType = MIME_TYPE;
}
UnstructuredDataReactiveResult result = new UnstructuredDataReactiveResult(EntityStreams.newEntityStream(writer), contentType);
callback.onSuccess(result);
}
use of com.linkedin.restli.server.UnstructuredDataReactiveResult in project rest.li by linkedin.
the class FeedDownloadResourceReactive method get.
@Override
public void get(Long key, @CallbackParam Callback<UnstructuredDataReactiveResult> callback) {
ChunkedByteStringWriter writer = new ChunkedByteStringWriter(CONTENT, 2);
callback.onSuccess(new UnstructuredDataReactiveResult(EntityStreams.newEntityStream(writer), CONTENT_TYPE));
}
use of com.linkedin.restli.server.UnstructuredDataReactiveResult in project rest.li by linkedin.
the class UnstructuredDataReactiveCollectionResource method get.
@Override
public void get(String key, @CallbackParam Callback<UnstructuredDataReactiveResult> callback) {
Writer<ByteString> writer = new SingletonWriter<>(ByteString.copy(UNSTRUCTURED_DATA_BYTES));
UnstructuredDataReactiveResult result = new UnstructuredDataReactiveResult(EntityStreams.newEntityStream(writer), MIME_TYPE);
callback.onSuccess(result);
}
use of com.linkedin.restli.server.UnstructuredDataReactiveResult in project rest.li by linkedin.
the class RestLiMethodInvoker method doInvoke.
@SuppressWarnings("deprecation")
private void doInvoke(final ResourceMethodDescriptor descriptor, final ResourceMethodConfig methodConfig, final RestLiCallback callback, final Object resource, final ServerResourceContext resourceContext, final Object... arguments) throws IllegalAccessException {
final Method method = descriptor.getMethod();
final RequestContext requestContext = resourceContext.getRawRequestContext();
TimingContextUtil.endTiming(requestContext, FrameworkTimingKeys.SERVER_REQUEST_RESTLI.key());
TimingContextUtil.endTiming(requestContext, FrameworkTimingKeys.SERVER_REQUEST.key());
TimingContextUtil.beginTiming(requestContext, FrameworkTimingKeys.RESOURCE.key());
try {
switch(descriptor.getInterfaceType()) {
case CALLBACK:
int callbackIndex = descriptor.indexOfParameterType(ParamType.CALLBACK);
arguments[callbackIndex] = new Callback<Object>() {
@Override
public void onError(Throwable e) {
callback.onError(e instanceof RestLiServiceException ? e : new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, e));
}
@Override
public void onSuccess(Object result) {
if (result instanceof UnstructuredDataReactiveResult) {
UnstructuredDataReactiveResult reactiveResult = (UnstructuredDataReactiveResult) result;
resourceContext.setResponseEntityStream(reactiveResult.getEntityStream());
resourceContext.setResponseHeader(RestConstants.HEADER_CONTENT_TYPE, reactiveResult.getContentType());
callback.onSuccess(new EmptyRecord());
} else {
callback.onSuccess(result);
}
}
};
method.invoke(resource, arguments);
// App code should use the callback
break;
case SYNC:
Object applicationResult = method.invoke(resource, arguments);
callback.onSuccess(applicationResult);
break;
case PROMISE:
if (!checkEngine(callback, descriptor)) {
break;
}
int contextIndex = descriptor.indexOfParameterType(ParamType.PARSEQ_CONTEXT_PARAM);
if (contextIndex == -1) {
contextIndex = descriptor.indexOfParameterType(ParamType.PARSEQ_CONTEXT);
}
// run through the engine to get the context
Task<Object> restliTask = withTimeout(createRestLiParSeqTask(arguments, contextIndex, method, resource), methodConfig);
// propagate the result to the callback
restliTask.addListener(new CallbackPromiseAdapter<>(callback));
addListenerFromContext(restliTask, resourceContext);
runTask(restliTask, toPlanClass(descriptor));
break;
case TASK:
if (!checkEngine(callback, descriptor)) {
break;
}
// addListener requires Task<Object> in this case
@SuppressWarnings("unchecked") Task<Object> task = withTimeout((Task<Object>) method.invoke(resource, arguments), methodConfig);
if (task == null) {
callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Error in application code: null Task"));
} else {
task.addListener(new CallbackPromiseAdapter<>(callback));
addListenerFromContext(task, resourceContext);
runTask(task, toPlanClass(descriptor));
}
break;
default:
throw new AssertionError("Unexpected interface type " + descriptor.getInterfaceType());
}
} catch (InvocationTargetException e) {
// InvocationTargetException wrapped around the root cause.
if (RestLiServiceException.class.isAssignableFrom(e.getCause().getClass())) {
RestLiServiceException restLiServiceException = (RestLiServiceException) e.getCause();
callback.onError(restLiServiceException);
} else {
callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, _internalErrorMessage, e.getCause()));
}
}
}
use of com.linkedin.restli.server.UnstructuredDataReactiveResult in project rest.li by linkedin.
the class GreetingUnstructuredDataAssociationResourceReactive method get.
@Override
public void get(CompoundKey key, @CallbackParam Callback<UnstructuredDataReactiveResult> callback) {
Writer<ByteString> writer = new SingletonWriter<>(ByteString.copy(UNSTRUCTURED_DATA_BYTES));
callback.onSuccess(new UnstructuredDataReactiveResult(EntityStreams.newEntityStream(writer), MIME_TYPE));
}
Aggregations