use of org.glassfish.jersey.server.model.Parameter in project jersey by jersey.
the class WadlBuilder method generateRequest.
private Request generateRequest(org.glassfish.jersey.server.model.Resource parentResource, final org.glassfish.jersey.server.model.ResourceMethod resourceMethod, Map<String, Param> wadlResourceParams) {
try {
final List<Parameter> requestParams = new LinkedList<>(resourceMethod.getInvocable().getParameters());
// Adding handler instance parameters to the list of potential request parameters.
requestParams.addAll(resourceMethod.getInvocable().getHandler().getParameters());
if (requestParams.isEmpty()) {
return null;
}
Request wadlRequest = _wadlGenerator.createRequest(parentResource, resourceMethod);
processRequestParameters(parentResource, resourceMethod, wadlResourceParams, requestParams, wadlRequest);
if (wadlRequest.getRepresentation().size() + wadlRequest.getParam().size() == 0) {
return null;
} else {
return wadlRequest;
}
} catch (Exception e) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_REQUEST(resourceMethod, parentResource), e);
}
}
use of org.glassfish.jersey.server.model.Parameter in project jersey by jersey.
the class WadlBuilder method generateResource.
private Resource generateResource(final org.glassfish.jersey.server.model.Resource resource, String path, Set<org.glassfish.jersey.server.model.Resource> visitedResources) {
try {
if (!detailedWadl && resource.isExtended()) {
return null;
}
Resource wadlResource = _wadlGenerator.createResource(resource, path);
// prevent infinite recursion
if (visitedResources.contains(resource)) {
return wadlResource;
} else {
visitedResources = new HashSet<>(visitedResources);
visitedResources.add(resource);
}
// if the resource contains subresource locator create new resource for this locator and return it instead
// of this resource
final ResourceMethod locator = resource.getResourceLocator();
if (locator != null) {
try {
org.glassfish.jersey.server.model.Resource.Builder builder = org.glassfish.jersey.server.model.Resource.builder(locator.getInvocable().getRawResponseType());
if (builder == null) {
// for example in the case the return type of the sub resource locator is Object
builder = org.glassfish.jersey.server.model.Resource.builder().path(resource.getPath());
}
org.glassfish.jersey.server.model.Resource subResource = builder.build();
Resource wadlSubResource = generateResource(subResource, resource.getPath(), visitedResources);
if (wadlSubResource == null) {
return null;
}
if (locator.isExtended()) {
wadlSubResource.getAny().add(WadlApplicationContextImpl.EXTENDED_ELEMENT);
}
for (Parameter param : locator.getInvocable().getParameters()) {
Param wadlParam = generateParam(resource, locator, param);
if (wadlParam != null && wadlParam.getStyle() == ParamStyle.TEMPLATE) {
wadlSubResource.getParam().add(wadlParam);
}
}
return wadlSubResource;
} catch (RuntimeException e) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_RESOURCE_LOCATOR(locator, resource), e);
}
}
Map<String, Param> wadlResourceParams = new HashMap<>();
// for each resource method
for (org.glassfish.jersey.server.model.ResourceMethod method : resource.getResourceMethods()) {
if (!detailedWadl && method.isExtended()) {
continue;
}
com.sun.research.ws.wadl.Method wadlMethod = generateMethod(resource, wadlResourceParams, method);
wadlResource.getMethodOrResource().add(wadlMethod);
}
// add method parameters that are associated with the resource PATH template
for (Param wadlParam : wadlResourceParams.values()) {
wadlResource.getParam().add(wadlParam);
}
// for each sub-resource method
Map<String, Resource> wadlSubResources = new HashMap<>();
Map<String, Map<String, Param>> wadlSubResourcesParams = new HashMap<>();
for (org.glassfish.jersey.server.model.Resource childResource : resource.getChildResources()) {
Resource childWadlResource = generateResource(childResource, childResource.getPath(), visitedResources);
if (childWadlResource == null) {
continue;
}
wadlResource.getMethodOrResource().add(childWadlResource);
}
return wadlResource;
} catch (Exception e) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_RESOURCE_PATH(resource, path), e);
}
}
use of org.glassfish.jersey.server.model.Parameter in project dropwizard by dropwizard.
the class ConstraintMessage method isRequestEntity.
/**
* Determines if constraint violation occurred in the request entity. If it did, return a client
* friendly string representation of where the error occurred (eg. "patient.name")
*/
public static Optional<String> isRequestEntity(ConstraintViolation<?> violation, Invocable invocable) {
final Path.Node parent = Iterables.get(violation.getPropertyPath(), 1, null);
if (parent == null) {
return Optional.empty();
}
final List<Parameter> parameters = invocable.getParameters();
switch(parent.getKind()) {
case PARAMETER:
final Parameter param = parameters.get(parent.as(Path.ParameterNode.class).getParameterIndex());
if (param.getSource().equals(Parameter.Source.UNKNOWN)) {
return Optional.of(Joiner.on('.').join(Iterables.skip(violation.getPropertyPath(), 2)));
}
default:
break;
}
return Optional.empty();
}
use of org.glassfish.jersey.server.model.Parameter in project jersey by jersey.
the class JavaResourceMethodDispatcherProvider method create.
@Override
public ResourceMethodDispatcher create(final Invocable resourceMethod, final InvocationHandler invocationHandler, final ConfiguredValidator validator) {
final List<ParamValueFactoryWithSource<?>> valueProviders = ParameterValueHelper.createValueProviders(injectionManager, resourceMethod);
final Class<?> returnType = resourceMethod.getHandlingMethod().getReturnType();
ResourceMethodDispatcher resourceMethodDispatcher = null;
if (Response.class.isAssignableFrom(returnType)) {
resourceMethodDispatcher = new ResponseOutInvoker(resourceMethod, invocationHandler, valueProviders, validator);
} else if (returnType != void.class) {
if (returnType == Object.class || GenericEntity.class.isAssignableFrom(returnType)) {
resourceMethodDispatcher = new ObjectOutInvoker(resourceMethod, invocationHandler, valueProviders, validator);
} else {
resourceMethodDispatcher = new TypeOutInvoker(resourceMethod, invocationHandler, valueProviders, validator);
}
} else {
// return type is void
int i = 0;
for (final Parameter parameter : resourceMethod.getParameters()) {
if (SseEventSink.class.equals(parameter.getRawType())) {
resourceMethodDispatcher = new SseEventSinkInvoker(resourceMethod, invocationHandler, valueProviders, validator, i);
break;
}
i++;
}
if (resourceMethodDispatcher == null) {
resourceMethodDispatcher = new VoidOutInvoker(resourceMethod, invocationHandler, valueProviders, validator);
}
}
// Inject validator.
injectionManager.inject(resourceMethodDispatcher);
return resourceMethodDispatcher;
}
use of org.glassfish.jersey.server.model.Parameter in project jersey by jersey.
the class MethodSelectingRouter method isReadable.
private boolean isReadable(final RequestSpecificConsumesProducesAcceptor candidate) {
final Invocable invocable = candidate.methodRouting.method.getInvocable();
final Method handlingMethod = invocable.getHandlingMethod();
final Parameter entityParam = getEntityParam(invocable);
if (entityParam == null) {
return true;
} else {
final Class<?> entityType = entityParam.getRawType();
for (final ReaderModel model : workers.getReaderModelsForType(entityType)) {
if (model.isReadable(entityType, entityParam.getType(), handlingMethod.getDeclaredAnnotations(), candidate.consumes.combinedType)) {
return true;
}
}
}
return false;
}
Aggregations