use of com.linkedin.restli.internal.server.RestLiInternalException in project rest.li by linkedin.
the class TestBatchCreateArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(String entity, String expectedExceptionMessage) {
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, entity, 1);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 1, null);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, null, 0);
RestLiArgumentBuilder argumentBuilder = new BatchCreateArgumentBuilder();
try {
argumentBuilder.extractRequestData(routingResult, request);
fail("Expected RestLiInternalException or ClassCastException");
} catch (RestLiInternalException e) {
assertTrue(e.getMessage().contains(expectedExceptionMessage));
} catch (ClassCastException e) {
assertTrue(e.getMessage().contains("java.lang.Integer cannot be cast to com.linkedin.data.DataList"));
}
verify(request, model, descriptor, routingResult);
}
use of com.linkedin.restli.internal.server.RestLiInternalException in project rest.li by linkedin.
the class Jsr330Adapter method scanInjectableConstructors.
private void scanInjectableConstructors(Class<?> beanClazz) {
int annotatedConstructors = 0;
for (Constructor<?> constructor : beanClazz.getConstructors()) {
Inject injectAnnotation = constructor.getAnnotation(Inject.class);
if (injectAnnotation != null) {
++annotatedConstructors;
if (annotatedConstructors > 1) {
throw new RestLiInternalException("Found multiple constructors annotated with @Inject in " + "class '" + beanClazz.getCanonicalName() + "'. At most one constructor can be annotated " + "with @Inject.");
}
Class<?>[] parameters = constructor.getParameterTypes();
Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
List<DependencyDecl> parameterDecls = new ArrayList<DependencyDecl>(parameters.length);
for (int i = 0; i < parameters.length; ++i) {
Class<?> parameter = parameters[i];
AnnotationSet annotations = new AnnotationSet(parameterAnnotations[i]);
Named namedAnno = annotations.get(Named.class);
parameterDecls.add(new DependencyDecl(parameter, namedAnno != null ? namedAnno.value() : null));
}
constructor.setAccessible(true);
_constructorParameterDependencies.put(beanClazz, new InjectableConstructor(constructor, parameterDecls));
}
}
if (annotatedConstructors == 0) {
try {
Constructor<?> defaultConstructor = beanClazz.getConstructor();
defaultConstructor.setAccessible(true);
_constructorParameterDependencies.put(beanClazz, new InjectableConstructor(defaultConstructor, Collections.<DependencyDecl>emptyList()));
} catch (NoSuchMethodException e) {
throw new RestLiInternalException(String.format("No injectable constructor defined for class %s. Classes must define" + " either a default constructor or a constructor annotated " + "with @Inject.", beanClazz.getName()), e);
}
}
}
use of com.linkedin.restli.internal.server.RestLiInternalException in project rest.li by linkedin.
the class RestLiJSONDocumentationRenderer method renderResource.
@Override
public void renderResource(String resourceName, OutputStream out) {
final ResourceSchema resourceSchema = _relationships.getResourceSchemaCollection().getResource(resourceName);
if (resourceSchema == null) {
throw new RoutingException(String.format("Resource named '%s' does not exist", resourceName), 404);
}
final DataMap outputMap = createEmptyOutput();
try {
renderResource(resourceSchema, outputMap);
_codec.writeMap(outputMap, out);
} catch (IOException e) {
throw new RestLiInternalException(e);
}
}
use of com.linkedin.restli.internal.server.RestLiInternalException in project rest.li by linkedin.
the class VelocityTemplatingEngine method render.
@Override
public void render(String templateName, Map<String, Object> pageModel, OutputStream out) {
if (_velocity == null) {
return;
}
final String actualTemplateName = VELOCITY_TEMPLATE_DIR + "/" + templateName;
final VelocityContext context = new VelocityContext(pageModel);
final Writer outWriter = new OutputStreamWriter(out);
try {
_velocity.mergeTemplate(actualTemplateName, VelocityEngine.ENCODING_DEFAULT, context, outWriter);
} catch (Exception e) {
throw new RestLiInternalException(e);
}
try {
outWriter.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations