this.allowWildcardServlet = allowWildcardServlet;
}
@Override
public ValidationResult validateRootResources(List<RootResource> rootResources) {
ValidationResult result = new ValidationResult();
for (RootResource rootResource : rootResources) {
if (rootResource.getDelegate() instanceof InterfaceDeclaration) {
if (!isExternallyManagedLifecycle(rootResource)) {
result.addWarning(rootResource, "The Jersey runtime doesn't support interfaces as root resources. The @Path parameter will need to be applied to the " +
"implementation class. If the lifecycle of this root resource is to be managed externally (e.g. by Spring or something), then let Enunciate know by " +
"annotating this class with @" + ExternallyManagedLifecycle.class.getName() + ".");
}
}
else {
List<ConstructorDeclaration> candidates = new ArrayList<ConstructorDeclaration>();
boolean externallyManagedLifecycle = isExternallyManagedLifecycle(rootResource);
CONSTRUCTOR_LOOP:
for (ConstructorDeclaration constructor : ((ClassDeclaration) rootResource.getDelegate()).getConstructors()) {
if (constructor.getModifiers().contains(Modifier.PUBLIC)) {
for (ParameterDeclaration constructorParam : constructor.getParameters()) {
if (!externallyManagedLifecycle && !isSuppliableByJAXRS(constructorParam)) {
//none of those annotation are available. not a candidate constructor.
continue CONSTRUCTOR_LOOP;
}
}
candidates.add(constructor);
}
}
if (candidates.isEmpty() && !externallyManagedLifecycle) {
result.addWarning(rootResource, "A JAX-RS root resource must have a public constructor for which the JAX-RS runtime can provide all parameter values. " +
"If the resource lifecycle is to be managed externally (e.g. by Spring or something), then please let Enunciate know by applying the @" +
ExternallyManagedLifecycle.class.getName() + " annotation to the resource.");
}
else {
while (!candidates.isEmpty()) {
ConstructorDeclaration candidate = candidates.remove(0);
for (ConstructorDeclaration other : candidates) {
if (candidate.getParameters().size() == other.getParameters().size()) {
result.addWarning(rootResource, "Ambiguous JAX-RS constructors (same parameter count).");
}
}
}
}
}
for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) {
if ("/*".equals(resourceMethod.getServletPattern())) {
if (!allowWildcardServlet) {
result.addError(resourceMethod, "This JAX-RS resource method is designed to catch all requests (including requests to " +
"Enunciate-generated documentation and other static files). If this is what you want, then please set 'disableWildcardServletError' to 'true'" +
"in the Enunciate config for the Jersey module. Otherwise, enable the rest subcontext or adjust the @Path annotation to be more specific.");
}
else {
result.addWarning(resourceMethod, "JAX-RS resource method is designed to catch all requests.");
}
}
for (String producesMime : resourceMethod.getProducesMime()) {
try {
MediaType.valueOf(producesMime);
}
catch (Exception e) {
result.addError(resourceMethod, "Invalid produces MIME type: " + producesMime + "(" + e.getMessage() + ").");
}
}
if (resourceMethod.getHttpMethods().size() > 1) {
result.addError(resourceMethod, "You must not apply multiple HTTP operations to the same method: " + resourceMethod.getHttpMethods());
}
for (String method : resourceMethod.getHttpMethods()) {
if ("GET".equalsIgnoreCase(method) && (resourceMethod.getRepresentationMetadata() == null)) {
result.addWarning(resourceMethod, "A resource method that is mapped to HTTP GET should probably have an output payload. (Does it return void?)");
}
if ("GET".equalsIgnoreCase(method) && resourceMethod.getEntityParameter() != null) {
result.addError(resourceMethod, "A resource method that is mapped to HTTP GET must not specify an entity parameter.");
}
}
}
}