use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method batchFinder.
public ExampleRequestResponse batchFinder(String name) {
BatchFinderSchema batchFinderSchema = _resourceSchema.getBatchFinder(name);
if (batchFinderSchema == null) {
throw new IllegalArgumentException("No such batch finder for resource: " + name);
}
RecordDataSchema metadataSchema = null;
if (batchFinderSchema.hasMetadata()) {
metadataSchema = (RecordDataSchema) RestSpecCodec.textToSchema(batchFinderSchema.getMetadata().getType(), _schemaResolver);
}
Request<?> request = buildBatchFinderRequest(batchFinderSchema);
RestRequest restRequest = buildRequest(request);
try {
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), restRequest, new RequestContext());
DataList criteriaParams = (DataList) context.getStructuredParameter(batchFinderSchema.getBatchParam());
// Since batchFinder has 2 kinds of responses. One is successful CollectionResponse. The other one is ErrorResponse.
// When BatchFinderResponseBuilder cannot find a search criteria, it will return an ErrorResponse.
// To include only one criteria in BatchFinderResult will make the response example diverse.
// guarantee batchFinder request and response has a same criteria
AnyRecord batchFinderCriteria = new AnyRecord((DataMap) criteriaParams.get(0));
return buildRequestResponse(request, buildBatchFinderResult(metadataSchema, batchFinderCriteria), buildResourceMethodDescriptorForBatchFinder(name, batchFinderSchema.getBatchParam()));
} catch (RestLiSyntaxException e) {
throw new ExampleGenerationException("Internal error during example generation", e);
}
}
use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method buildResponse.
private RestResponse buildResponse(Object responseEntity, ResourceMethodDescriptor method, RestRequest restRequest) {
try {
RequestContext requestContext = new RequestContext();
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), restRequest, requestContext);
RestUtils.validateRequestHeadersAndUpdateResourceContext(restRequest.getHeaders(), Collections.emptySet(), context, requestContext);
method.setResourceModel(_resourceModel);
final RoutingResult routingResult = new RoutingResult(context, method);
RestLiResponseData<?> responseData = _responseHandler.buildRestLiResponseData(restRequest, routingResult, responseEntity);
RestLiResponse restLiResponse = _responseHandler.buildPartialResponse(routingResult, responseData);
return ResponseUtils.buildResponse(routingResult, restLiResponse);
} catch (RestLiSyntaxException e) {
throw new ExampleGenerationException("Internal error during example generation", e);
} catch (IOException e) {
throw new ExampleGenerationException("Unable to build example response", e);
}
}
Aggregations