@Override @SuppressWarnings("unchecked") public <T> ParamConverter<T> getConverter( final Class<T> rawType, final Type genericType, final Annotation[] annotations) { if (Date.class.equals(rawType)) { return (ParamConverter<T>) new DateParamConverter(); } return null; }
batchRequestItems = BatchPayloadParser.parse(input, mediaType, new BatchRequestItem()); } catch (IOException e) { LOG.error("Could not parse batch request with boundary {}", boundary, e); header(RESTHeaders.PREFERENCE_APPLIED, getPreference().toString()). header(HttpHeaders.LOCATION, uriInfo.getAbsolutePathBuilder().build()). type(RESTHeaders.multipartMixedWith(boundary)). build(); } else {
@Override public Response deleteExecutions(final ExecDeleteQuery query) { List<BatchResponseItem> batchResponseItems = getExecutableLogic().deleteExecutions( query.getKey(), query.getStartedBefore(), query.getStartedAfter(), query.getEndedBefore(), query.getEndedAfter()); String boundary = "deleteExecutions_" + SecureRandomUtils.generateRandomUUID().toString(); return Response.ok(BatchPayloadGenerator.generate( batchResponseItems, SyncopeConstants.DOUBLE_DASH + boundary)). type(RESTHeaders.multipartMixedWith(boundary)). build(); }
/** * Sets the {@code Prefer} header on the give service instance. * * @param <T> any service class * @param service service class instance * @param preference preference to be set via {@code Prefer} header * @return given service instance, with {@code Prefer} header set */ public <T> T prefer(final T service, final Preference preference) { return header(service, RESTHeaders.PREFER, preference.toString()); }
/** * Sends the current request, with items accumulated by invoking methods on proxies obtained via * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for a synchronous or asynchronous * response, depending on the {@code async} parameter. * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests. * * @param async whether asynchronous Batch process is requested, or not * @return batch response */ public BatchResponse commit(final boolean async) { String boundary = "--batch_" + UUID.randomUUID().toString(); WebClient webClient = WebClient.create(bcfb.getAddress()).path("batch"). header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt). type(RESTHeaders.multipartMixedWith(boundary.substring(2))); if (async) { webClient.header(RESTHeaders.PREFER, Preference.RESPOND_ASYNC); } String body = BatchPayloadGenerator.generate(bcfb.getBatchRequestItems(), boundary); LOG.debug("Batch request body:\n{}", body); initBatchClientFactoryBean(); return new BatchResponse(boundary, jwt, webClient.post(body)); } }
/** * If asynchronous processing was requested, queries the monitor URI. * * @return the last Response received from the Batch service */ public Response poll() { if (monitor != null) { response = WebClient.create(monitor). header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt). type(RESTHeaders.multipartMixedWith(boundary.substring(2))).get(); } return response; }
protected JAXRSClientFactoryBean defaultRestClientFactoryBean() { JAXRSClientFactoryBean defaultRestClientFactoryBean = new JAXRSClientFactoryBean(); defaultRestClientFactoryBean.setHeaders(new HashMap<>()); if (StringUtils.isBlank(address)) { throw new IllegalArgumentException("Property 'address' is missing"); } defaultRestClientFactoryBean.setAddress(address); if (StringUtils.isNotBlank(domain)) { defaultRestClientFactoryBean.getHeaders().put(RESTHeaders.DOMAIN, Collections.singletonList(domain)); } defaultRestClientFactoryBean.setThreadSafe(true); defaultRestClientFactoryBean.setInheritHeaders(true); List<Feature> features = new ArrayList<>(); features.add(new LoggingFeature()); defaultRestClientFactoryBean.setFeatures(features); List<Object> providers = new ArrayList<>(4); providers.add(new DateParamConverterProvider()); providers.add(getJaxbProvider()); providers.add(getJsonProvider()); providers.add(getExceptionMapper()); defaultRestClientFactoryBean.setProviders(providers); return defaultRestClientFactoryBean; }
/** * Reads {@code Prefer} header from request and parses into a {@code Preference} instance. * * @return a {@code Preference} instance matching the passed {@code Prefer} header, * or {@code Preference.NONE} if missing. */ protected Preference getPreference() { return Preference.fromString(messageContext.getHttpServletRequest().getHeader(RESTHeaders.PREFER)); }
@Override public List<LoggerTO> list(final LoggerType type) { switch (type) { case LOG: return logic.listLogs(); case AUDIT: List<AuditLoggerName> auditLogger = logic.listAudits(); return LoggerWrapper.unwrap(auditLogger); default: throw new BadRequestException(); } }
/** * Sets the {@code Prefer} header on the give service instance. * * @param <T> any service class * @param service service class instance * @param preference preference to be set via {@code Prefer} header * @return given service instance, with {@code Prefer} header set */ public <T> T prefer(final T service, final Preference preference) { return header(service, RESTHeaders.PREFER, preference.toString()); }
/** * Sends the current request, with items accumulated by invoking methods on proxies obtained via * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for a synchronous or asynchronous * response, depending on the {@code async} parameter. * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests. * * @param async whether asynchronous Batch process is requested, or not * @return batch response */ public BatchResponse commit(final boolean async) { String boundary = "--batch_" + UUID.randomUUID().toString(); WebClient webClient = WebClient.create(bcfb.getAddress()).path("batch"). header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt). type(RESTHeaders.multipartMixedWith(boundary.substring(2))); if (async) { webClient.header(RESTHeaders.PREFER, Preference.RESPOND_ASYNC); } String body = BatchPayloadGenerator.generate(bcfb.getBatchRequestItems(), boundary); LOG.debug("Batch request body:\n{}", body); initBatchClientFactoryBean(); return new BatchResponse(boundary, jwt, webClient.post(body)); } }
/** * If asynchronous processing was requested, queries the monitor URI. * * @return the last Response received from the Batch service */ public Response poll() { if (monitor != null) { response = WebClient.create(monitor). header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt). type(RESTHeaders.multipartMixedWith(boundary.substring(2))).get(); } return response; }
@Override @SuppressWarnings("unchecked") public <T> ParamConverter<T> getConverter( final Class<T> rawType, final Type genericType, final Annotation[] annotations) { if (Date.class.equals(rawType)) { return (ParamConverter<T>) new DateParamConverter(); } return null; }
protected JAXRSClientFactoryBean defaultRestClientFactoryBean() { JAXRSClientFactoryBean defaultRestClientFactoryBean = new JAXRSClientFactoryBean(); defaultRestClientFactoryBean.setHeaders(new HashMap<>()); if (StringUtils.isBlank(address)) { throw new IllegalArgumentException("Property 'address' is missing"); } defaultRestClientFactoryBean.setAddress(address); if (StringUtils.isNotBlank(domain)) { defaultRestClientFactoryBean.getHeaders().put(RESTHeaders.DOMAIN, Collections.singletonList(domain)); } defaultRestClientFactoryBean.setThreadSafe(true); defaultRestClientFactoryBean.setInheritHeaders(true); List<Feature> features = new ArrayList<>(); features.add(new LoggingFeature()); defaultRestClientFactoryBean.setFeatures(features); List<Object> providers = new ArrayList<>(4); providers.add(new DateParamConverterProvider()); providers.add(getJaxbProvider()); providers.add(getJsonProvider()); providers.add(getExceptionMapper()); defaultRestClientFactoryBean.setProviders(providers); return defaultRestClientFactoryBean; }
protected Response.ResponseBuilder applyPreference( final ProvisioningResult<?> provisioningResult, final Response.ResponseBuilder builder) { switch (getPreference()) { case RETURN_NO_CONTENT: break; case RETURN_CONTENT: case NONE: default: builder.entity(provisioningResult); break; } if (getPreference() == Preference.RETURN_CONTENT || getPreference() == Preference.RETURN_NO_CONTENT) { builder.header(RESTHeaders.PREFERENCE_APPLIED, getPreference().toString()); } return builder; }
@Override public Response batch() { MediaType mediaType = MediaType.valueOf(messageContext.getHttpServletRequest().getContentType()); String boundary = mediaType.getParameters().get(RESTHeaders.BOUNDARY_PARAMETER); Batch batch = batchDAO.find(boundary); if (batch == null) { throw new NotFoundException("Batch " + boundary); } if (batch.getResults() == null) { return Response.accepted(). type(RESTHeaders.multipartMixedWith(boundary)). header(HttpHeaders.RETRY_AFTER, 5). header(HttpHeaders.LOCATION, uriInfo.getAbsolutePathBuilder().build()). build(); } Response response = Response.ok(batch.getResults()). type(RESTHeaders.multipartMixedWith(boundary)). build(); batchDAO.delete(boundary); return response; } }
/** * Builds response to successful modification request, taking into account any {@code Prefer} header. * * @param entity the entity just modified * @return response to successful modification request */ protected Response modificationResponse(final Object entity) { Response.ResponseBuilder builder; switch (getPreference()) { case RETURN_NO_CONTENT: builder = Response.noContent(); break; case RETURN_CONTENT: case NONE: default: builder = Response.ok(entity); break; } if (getPreference() == Preference.RETURN_CONTENT || getPreference() == Preference.RETURN_NO_CONTENT) { builder.header(RESTHeaders.PREFERENCE_APPLIED, getPreference().toString()); } return builder.build(); }