javax.ws.rs.core.Link.Builder Java Examples
The following examples show how to use
javax.ws.rs.core.Link.Builder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LinkCreator.java From rest-schemagen with Apache License 2.0 | 6 votes |
private void addHttpMethod(Builder builder, Scope scope) { final List<Class<? extends Annotation>> httpMethodAnnotations = Arrays.asList(GET.class, POST.class, PUT.class, DELETE.class); final Method invokedMethod = scope.getInvokedMethod(); final Optional<Class<? extends Annotation>> httpMethod = httpMethodAnnotations.stream() .filter(invokedMethod::isAnnotationPresent).findFirst(); if (httpMethod.isPresent()) { builder.param(METHOD_PARAM_KEY, httpMethod.get().getSimpleName()); } else { throw new IllegalArgumentException( "LinkCreator: The method has to be annotated with one of: " + String.join(", ", (Iterable<String>) httpMethodAnnotations.stream().map( Class::getSimpleName).map(m -> '@' + m)::iterator)); } }
Example #2
Source File: LinkCreator.java From rest-schemagen with Apache License 2.0 | 5 votes |
public static Builder setRelation(Relation relation, URI uri) { requireNonNull(relation); requireNonNull(uri); Builder builder = Link.fromUri(uri).rel(relation.getName()); if (requireNonNull(relation).getType().isShouldBeSerialized()) { builder.param("relType", relation.getType().getName()); builder.param("target", relation.getType().getSerializedName()); } return builder; }
Example #3
Source File: LinkCreator.java From rest-schemagen with Apache License 2.0 | 5 votes |
/** * create a link for a resource method * * @param scopes * list of Scope objects for every scope level * @param relation * relation of method * @param linkFactoryContext * the base URI for resolution of relative URIs and method and * property checkers * @return link with schema if applicable */ public Link createFor(List<Scope> scopes, Relation relation, LinkFactoryContext linkFactoryContext) { final Class<?> resourceClass = scopes.get(0).getInvokedClass(); UriBuilder uriBuilder = UriBuilder.fromResource(resourceClass); Map<String, Object> pathParameters = new HashMap<>(); for (Scope scope : scopes) { final Method method = scope.getInvokedMethod(); final Object[] parameters = scope.getParams(); if (method.isAnnotationPresent(Path.class)) { uriBuilder.path(method.getDeclaringClass(), method.getName()); } pathParameters.putAll(collectPathParameters(scope, parameters)); setQueryParameters(uriBuilder, scope, parameters); } URI uri = mergeUri(linkFactoryContext.getBaseUri(), uriBuilder, pathParameters); Builder builder = setRelation(relation, uri); addLinkProperties(scopes, builder); detectMediaType(scopes, builder); final Scope lastScopedMethod = Iterables.getLast(scopes); addHttpMethod(builder, lastScopedMethod); addSchemaIfNeeded(builder, lastScopedMethod, linkFactoryContext); return builder.build(); }
Example #4
Source File: LinkCreator.java From rest-schemagen with Apache License 2.0 | 5 votes |
private void addLinkProperties(List<Scope> scopes, Builder builder) { final LinkProperties properties = Iterables.getLast(scopes).getInvokedMethod() .getAnnotation(LinkProperties.class); if (properties != null) { Stream.of(properties.value()).forEach(x -> builder.param(x.key(), x.value())); } }
Example #5
Source File: LinkCreator.java From rest-schemagen with Apache License 2.0 | 5 votes |
private void addSchemaIfNeeded(Builder builder, Scope method, LinkFactoryContext linkFactoryContext) { Optional<String> optionalInputSchema = jsonSchemaGenerator.createInputSchema(method, linkFactoryContext.getFieldCheckerForSchema()); optionalInputSchema.ifPresent(s -> builder.param(SCHEMA_PARAM_KEY, s)); Optional<String> mt = detectMediaType(method.getInvokedMethod()); if (mt.isPresent() && MediaType.APPLICATION_JSON.equals(mt.get())) { Optional<String> optionalOutputSchema = jsonSchemaGenerator.createOutputSchema(method, linkFactoryContext.getFieldCheckerForSchema()); optionalOutputSchema.ifPresent(s -> builder.param(TARGET_SCHEMA_PARAM_KEY, s)); } }
Example #6
Source File: ExternalLinkFactory.java From rest-schemagen with Apache License 2.0 | 5 votes |
public Link createFor(URI uri, Optional<String> schemaForLink, String relName) { Objects.requireNonNull(uri); Objects.requireNonNull(schemaForLink); Objects.requireNonNull(relName); Relation rel = Relation.of(relName, RelType.OTHER); Builder linkBuilder = LinkCreator.setRelation(rel, uri); schemaForLink.ifPresent(s -> linkBuilder.param(LinkCreator.SCHEMA_PARAM_KEY, s)); return linkBuilder.build(); }
Example #7
Source File: LinkBuilderImpl.java From cxf with Apache License 2.0 | 5 votes |
@Override public Builder param(String name, String value) { checkNotNull(name); checkNotNull(value); params.put(name, value); return this; }
Example #8
Source File: MockResponse.java From gitlab4j-api with MIT License | 4 votes |
@Override public Builder getLinkBuilder(String relation) { return null; }
Example #9
Source File: JacksonResponse.java From nifi with Apache License 2.0 | 4 votes |
@Override public Builder getLinkBuilder(String relation) { return null; }
Example #10
Source File: ResponseImplTest.java From cxf with Apache License 2.0 | 4 votes |
@Override public Builder createLinkBuilder() { return original.createLinkBuilder(); }
Example #11
Source File: ResponseImplTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testGetNoLinkBuilder() throws Exception { Response response = Response.ok().build(); Builder builder = response.getLinkBuilder("anyrelation"); assertNull(builder); }
Example #12
Source File: AbstractResponseContextImpl.java From cxf with Apache License 2.0 | 4 votes |
public Builder getLinkBuilder(String rel) { return r.getLinkBuilder(rel); }
Example #13
Source File: LinkBuilderImpl.java From cxf with Apache License 2.0 | 4 votes |
@Override public Builder baseUri(String uri) { baseUri = URI.create(uri); return this; }
Example #14
Source File: LinkBuilderImpl.java From cxf with Apache License 2.0 | 4 votes |
@Override public Builder baseUri(URI uri) { this.baseUri = uri; return this; }
Example #15
Source File: LinkBuilderImpl.java From cxf with Apache License 2.0 | 4 votes |
@Override public Builder uriBuilder(UriBuilder builder) { this.ub = builder; return this; }
Example #16
Source File: CustomResponse.java From cxf with Apache License 2.0 | 4 votes |
@Override public Builder getLinkBuilder(String arg0) { return null; }
Example #17
Source File: ResponseWrapper.java From ambiverse-nlu with Apache License 2.0 | 4 votes |
@Override public Builder getLinkBuilder(final String relation) { return delegate.getLinkBuilder(relation); }
Example #18
Source File: LinkCreator.java From rest-schemagen with Apache License 2.0 | 4 votes |
private void detectMediaType(Collection<Scope> scopes, Builder builder) { detectMediaType(Iterables.getLast(scopes).getInvokedMethod()).ifPresent(mediatype -> builder .param("mediaType", mediatype)); }
Example #19
Source File: ResponseImpl.java From raml-module-builder with Apache License 2.0 | 4 votes |
@Override public Builder getLinkBuilder(String relation) { // TODO Auto-generated method stub return null; }