use of org.jboss.resteasy.spi.ResteasyUriBuilder in project resteasy by resteasy.
the class ObjectLinksProvider method buildURI.
private URI buildURI(UriBuilder uriBuilder, LinkResource service, Object entity, Method m) {
for (ParamBinding binding : service.queryParameters()) {
uriBuilder.queryParam(binding.name(), evaluateEL(m, getELContext(m, entity), binding.value()));
}
for (ParamBinding binding : service.matrixParameters()) {
uriBuilder.matrixParam(binding.name(), evaluateEL(m, getELContext(m, entity), binding.value()));
}
String[] uriTemplates = service.pathParameters();
if (uriTemplates.length > 0) {
Object[] values = new Object[uriTemplates.length];
for (int i = 0; i < values.length; i++) {
values[i] = evaluateEL(m, getELContext(m, entity), uriTemplates[i]);
}
return uriBuilder.build(values);
}
// do we need any path parameters?
List<String> paramNames = ((ResteasyUriBuilder) uriBuilder).getPathParamNamesInDeclarationOrder();
if (paramNames.isEmpty()) {
return uriBuilder.build();
}
// try to find the IDs
List<Object> params = findURIParamsFromResource(entity);
if (params.size() == paramNames.size()) {
return uriBuilder.build(params.toArray());
}
// if we have too many, ignore the last ones
if (params.size() > paramNames.size()) {
return uriBuilder.build(params.subList(0, paramNames.size()).toArray());
}
throw new ServiceDiscoveryException(m, Messages.MESSAGES.notEnoughtUriParameters(paramNames.size(), params.size()));
}
use of org.jboss.resteasy.spi.ResteasyUriBuilder in project resteasy by resteasy.
the class ClientWebTarget method queryParamsNoTemplate.
@Override
public ResteasyWebTarget queryParamsNoTemplate(MultivaluedMap<String, Object> parameters) throws IllegalArgumentException, NullPointerException {
client.abortIfClosed();
if (parameters == null)
throw new NullPointerException(Messages.MESSAGES.parametersWasNull());
ResteasyUriBuilder copy;
if (uriBuilder instanceof ResteasyUriBuilder) {
copy = (ResteasyUriBuilder) uriBuilder.clone();
} else {
copy = ResteasyUriBuilder.fromTemplate(uriBuilder.toTemplate());
}
for (Map.Entry<String, List<Object>> entry : parameters.entrySet()) {
String[] stringValues = toStringValues(entry.getValue().toArray());
for (String val : stringValues) {
copy.clientQueryParam(entry.getKey(), val);
}
}
return newInstance(client, copy, configuration);
}
use of org.jboss.resteasy.spi.ResteasyUriBuilder in project resteasy by resteasy.
the class ResteasyUriInfo method initialize.
protected void initialize(CharSequence absoluteUri, String queryString, String contextPath) {
ResteasyUriBuilder absoluteBuilder = (ResteasyUriBuilder) ((ResteasyUriBuilder) RuntimeDelegate.getInstance().createUriBuilder()).uriFromCharSequence((CharSequence) absoluteUri);
absolutePath = absoluteBuilder.build();
requestURI = absoluteBuilder.replaceQuery(queryString).build();
encodedPath = PathHelper.getEncodedPathInfo(absolutePath.getRawPath(), contextPath);
baseURI = absolutePath;
if (!encodedPath.trim().equals("")) {
String tmpContextPath = contextPath;
if (!tmpContextPath.endsWith("/"))
tmpContextPath += "/";
baseURI = absoluteBuilder.clone().replacePath(tmpContextPath).replaceQuery(null).build();
}
// make sure path starts with '/'
if (encodedPath.length() == 0 || encodedPath.charAt(0) != '/') {
encodedPath = "/" + encodedPath;
}
path = UriBuilder.fromPath(encodedPath).build().getPath();
processPath();
}
use of org.jboss.resteasy.spi.ResteasyUriBuilder in project resteasy by resteasy.
the class ResourceMethodRegistry method removeRegistration.
private void removeRegistration(String base, Class<?> clazz) {
for (Method method : clazz.getMethods()) {
Path path = method.getAnnotation(Path.class);
Set<String> httpMethods = IsHttpMethod.getHttpMethods(method);
if (path == null && httpMethods == null)
continue;
ResteasyUriBuilder builder = new ResteasyUriBuilderImpl();
if (base != null)
builder.path(base);
if (clazz.isAnnotationPresent(Path.class))
builder.path(clazz);
String classExpression = builder.getPath();
if (path != null)
builder.path(method);
String fullpath = builder.getPath();
if (fullpath == null)
fullpath = "";
if (widerMatching)
rootNode.removeBinding(fullpath, method);
else
root.removeBinding(classExpression, fullpath, method);
}
}
use of org.jboss.resteasy.spi.ResteasyUriBuilder in project quarkus by quarkusio.
the class QuarkusRestClientBuilder method verifyInterface.
private <T> void verifyInterface(Class<T> typeDef) {
Method[] methods = typeDef.getMethods();
// multiple verbs
for (Method method : methods) {
boolean hasHttpMethod = false;
for (Annotation annotation : method.getAnnotations()) {
boolean isHttpMethod = (annotation.annotationType().getAnnotation(HttpMethod.class) != null);
if (!hasHttpMethod && isHttpMethod) {
hasHttpMethod = true;
} else if (hasHttpMethod && isHttpMethod) {
throw new RestClientDefinitionException("Ambiguous @HttpMethod definition on type " + typeDef);
}
}
}
// invalid parameter
Path classPathAnno = typeDef.getAnnotation(Path.class);
ResteasyUriBuilder template = null;
for (Method method : methods) {
Path methodPathAnno = method.getAnnotation(Path.class);
if (methodPathAnno != null) {
template = classPathAnno == null ? (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(methodPathAnno.value()) : (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(classPathAnno.value() + "/" + methodPathAnno.value());
} else if (classPathAnno != null) {
template = (ResteasyUriBuilder) new ResteasyUriBuilderImpl().uri(classPathAnno.value());
} else {
template = null;
}
if (template == null) {
continue;
}
// it's not executed, so this can be anything - but a hostname needs to present
template.host("localhost");
Set<String> allVariables = new HashSet<>(template.getPathParamNamesInDeclarationOrder());
Map<String, Object> paramMap = new HashMap<>();
for (Parameter p : method.getParameters()) {
PathParam pathParam = p.getAnnotation(PathParam.class);
if (pathParam != null) {
paramMap.put(pathParam.value(), "foobar");
} else if (p.isAnnotationPresent(org.jboss.resteasy.annotations.jaxrs.PathParam.class)) {
org.jboss.resteasy.annotations.jaxrs.PathParam rePathParam = p.getAnnotation(org.jboss.resteasy.annotations.jaxrs.PathParam.class);
String name = rePathParam.value() == null || rePathParam.value().length() == 0 ? p.getName() : rePathParam.value();
paramMap.put(name, "foobar");
} else if (p.isAnnotationPresent(BeanParam.class)) {
verifyBeanPathParam(p.getType(), paramMap);
}
}
if (allVariables.size() != paramMap.size()) {
throw new RestClientDefinitionException("Parameters and variables don't match on " + typeDef + "::" + method.getName());
}
try {
template.resolveTemplates(paramMap, false).build();
} catch (IllegalArgumentException ex) {
throw new RestClientDefinitionException("Parameter names don't match variable names on " + typeDef + "::" + method.getName(), ex);
}
}
}
Aggregations