Example usage for org.springframework.http HttpStatus ACCEPTED

List of usage examples for org.springframework.http HttpStatus ACCEPTED

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus ACCEPTED.

Prototype

HttpStatus ACCEPTED

To view the source code for org.springframework.http HttpStatus ACCEPTED.

Click Source Link

Document

202 Accepted .

Usage

From source file:org.kuali.coeus.sys.impl.lock.PessimisticLockController.java

@Transactional
@RequestMapping(value = "/sys/pessimisticLock/{id}", method = RequestMethod.DELETE)
public ResponseEntity<String> deletePessimisticLock(@PathVariable("id") String id) throws Exception {
    if (StringUtils.isNotBlank(id) && NumberUtils.isNumber(id) && parameterService.getParameterValueAsBoolean(
            "KC-GEN", "All", PessimisticLockConstants.ALLOW_CLEAR_PESSIMISTIC_LOCK_PARM)) {

        try {/*from   ww w.  j av a  2  s  . com*/
            //not using PessimisticLockService since there is security constraints on that api that doesn't allow certain users to call it
            dataObjectService.deleteMatching(PessimisticLock.class,
                    QueryByCriteria.Builder.andAttributes(Collections.singletonMap("id", id)).build());
        } catch (IllegalArgumentException | DataAccessException e) {
            //be lenient with delete failures as per normal REST convention
            LOG.warn("Failed to delete pessimistic lock with id: " + id);
        }
    }

    return new ResponseEntity<String>(HttpStatus.ACCEPTED);
}

From source file:org.springframework.cloud.function.web.flux.FunctionController.java

@PostMapping(path = "/**")
@ResponseBody/*w  w  w.j a  v a  2 s .  c o  m*/
public ResponseEntity<Flux<?>> post(
        @RequestAttribute(required = false, name = "org.springframework.cloud.function.web.flux.constants.WebRequestConstants.function") Function<Flux<?>, Flux<?>> function,
        @RequestAttribute(required = false, name = "org.springframework.cloud.function.web.flux.constants.WebRequestConstants.consumer") Consumer<Flux<?>> consumer,
        @RequestAttribute(required = false, name = "org.springframework.cloud.function.web.flux.constants.WebRequestConstants.input_single") Boolean single,
        @RequestBody FluxRequest<?> body) {
    if (function != null) {
        Flux<?> result = (Flux<?>) function.apply(body.flux());
        if (logger.isDebugEnabled()) {
            logger.debug("Handled POST with function");
        }
        return ResponseEntity.ok().body(debug ? result.log() : result);
    }
    if (consumer != null) {
        Flux<?> flux = body.flux().cache(); // send a copy back to the caller
        consumer.accept(flux);
        if (logger.isDebugEnabled()) {
            logger.debug("Handled POST with consumer");
        }
        return ResponseEntity.status(HttpStatus.ACCEPTED).body(flux);
    }
    throw new IllegalArgumentException("no such function");
}

From source file:org.springframework.cloud.function.web.RequestProcessor.java

private Mono<ResponseEntity<?>> response(FunctionWrapper wrapper, Object body, boolean stream) {

    Function<Publisher<?>, Publisher<?>> function = wrapper.function();
    Consumer<Publisher<?>> consumer = wrapper.consumer();

    Flux<?> flux;/*from w w  w  .  j a  va2 s . c  o m*/
    if (body != null) {
        if (Collection.class.isAssignableFrom(this.inspector.getInputType(wrapper.handler()))) {
            flux = Flux.just(body);
        } else {
            Iterable<?> iterable = body instanceof Collection ? (Collection<?>) body
                    : (body instanceof Set ? Collections.singleton(body) : Collections.singletonList(body));
            flux = Flux.fromIterable(iterable);
        }
    } else if (MultiValueMap.class.isAssignableFrom(this.inspector.getInputType(wrapper.handler()))) {
        flux = Flux.just(wrapper.params());
    } else {
        throw new IllegalStateException("Failed to determine input for function call with parameters: '"
                + wrapper.params + "' and headers: `" + wrapper.headers + "`");
    }

    if (this.inspector.isMessage(function)) {
        flux = messages(wrapper, function == null ? consumer : function, flux);
    }
    Mono<ResponseEntity<?>> responseEntityMono = null;

    if (function instanceof FluxedConsumer || function instanceof FluxConsumer) {
        ((Mono<?>) function.apply(flux)).subscribe();
        logger.debug("Handled POST with consumer");
        responseEntityMono = Mono.just(ResponseEntity.status(HttpStatus.ACCEPTED).build());
    } else {
        Flux<?> result = Flux.from(function.apply(flux));
        logger.debug("Handled POST with function");
        if (stream) {
            responseEntityMono = stream(wrapper, result);
        } else {
            responseEntityMono = response(wrapper, function, result,
                    body == null ? null : !(body instanceof Collection), false);
        }
    }
    return responseEntityMono;
}

From source file:org.springframework.web.client.interceptors.ZeroLeggedOAuthInterceptorTest.java

@Test
public void testInterceptor() throws Exception {
    final String url = "http://www.test.com/lrs?param1=val1&param2=val2";
    final String data = "test";
    final String id = "test";
    final String realm = "realm";
    final String consumerKey = "consumerKey";
    final String secretKey = "secretKey";

    PropertyResolver resolver = mock(PropertyResolver.class);
    when(resolver.getProperty(eq("org.jasig.rest.interceptor.oauth." + id + ".realm"))).thenReturn(realm);
    when(resolver.getProperty(eq("org.jasig.rest.interceptor.oauth." + id + ".consumerKey")))
            .thenReturn(consumerKey);//w w  w. j a v  a  2 s .  c o  m
    when(resolver.getProperty(eq("org.jasig.rest.interceptor.oauth." + id + ".secretKey")))
            .thenReturn(secretKey);

    // holder for the headers...
    HttpHeaders headers = new HttpHeaders();

    // Mock guts of RestTemplate so no need to actually hit the web...
    ClientHttpResponse resp = mock(ClientHttpResponse.class);
    when(resp.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
    when(resp.getHeaders()).thenReturn(new HttpHeaders());

    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    ClientHttpRequest client = mock(ClientHttpRequest.class);
    when(client.getHeaders()).thenReturn(headers);
    when(client.getBody()).thenReturn(buffer);
    when(client.execute()).thenReturn(resp);

    ClientHttpRequestFactory factory = mock(ClientHttpRequestFactory.class);
    when(factory.createRequest(any(URI.class), any(HttpMethod.class))).thenReturn(client);

    // add the new interceptor...
    ZeroLeggedOAuthInterceptor interceptor = new ZeroLeggedOAuthInterceptor();
    interceptor.setPropertyResolver(resolver);
    interceptor.setId(id);
    List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
    interceptors.add(interceptor);

    RestTemplate rest = new RestTemplate(factory);
    rest.setInterceptors(interceptors);

    rest.postForLocation(url, data, Collections.emptyMap());

    // make sure auth header is correctly set...
    assertThat(headers, hasKey(Headers.Authorization.name()));

    String authHeader = headers.get(Headers.Authorization.name()).get(0);
    assertThat(authHeader, containsString("OAuth realm=\"" + realm + "\""));
    assertThat(authHeader, containsString("oauth_consumer_key=\"" + consumerKey + "\""));
    // for now, only supports HMAC-SHA1.  May have to fix later...
    assertThat(authHeader, containsString("oauth_signature_method=\"HMAC-SHA1\""));
    assertThat(authHeader, containsString("oauth_version=\"1.0\""));
    assertThat(authHeader, containsString("oauth_timestamp="));
    assertThat(authHeader, containsString("oauth_nonce="));
    assertThat(authHeader, containsString("oauth_signature="));

    // oauth lib will create 2 oauth_signature params if you call sign
    // multiple times.  Make sure only get 1.
    assertThat(StringUtils.countMatches(authHeader, "oauth_signature="), is(1));
}

From source file:org.talend.dataprep.api.service.command.dataset.CreateDataSet.java

/**
 * Default constructor./*from  w  w  w  .jav  a 2  s.  c  o m*/
 *
 * @param name name of the dataset.
 * @param contentType content-type of the dataset.
 * @param dataSetContent Dataset content or import parameters in json for remote datasets.
 */
private CreateDataSet(String name, String tag, String contentType, InputStream dataSetContent) {
    super(GenericCommand.DATASET_GROUP);
    execute(() -> onExecute(name, tag, contentType, dataSetContent));
    onError(e -> {
        if (e instanceof TDPException) {
            return passthrough().apply(e);
        }
        return new TDPException(APIErrorCodes.UNABLE_TO_CREATE_DATASET, e);
    });
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(emptyString());
    on(HttpStatus.OK).then(asString());
}

From source file:org.talend.dataprep.api.service.command.dataset.CreateOrUpdateDataSet.java

/**
 * Private constructor./*ww  w .  j  ava2 s.  c  o  m*/
 *
 * @param id the dataset id.
 * @param name the dataset name.
 * @param dataSetContent the new dataset content.
 */
private CreateOrUpdateDataSet(String id, String name, InputStream dataSetContent) {
    super(GenericCommand.DATASET_GROUP);
    execute(() -> {
        try {
            URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/" + id + "/raw/");
            if (!StringUtils.isEmpty(name)) {
                uriBuilder.addParameter("name", name);
            }
            final HttpPut put = new HttpPut(uriBuilder.build()); // $NON-NLS-1$ //$NON-NLS-2$
            put.setEntity(new InputStreamEntity(dataSetContent));
            return put;
        } catch (URISyntaxException e) {
            throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
        }
    });
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_CREATE_OR_UPDATE_DATASET, e));
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(emptyString());
    on(HttpStatus.OK).then(asString());
}

From source file:org.talend.dataprep.api.service.command.dataset.DataSetList.java

private DataSetList(Sort sort, Order order, String name, boolean certified, boolean favorite, boolean limit) {
    super(GenericCommand.DATASET_GROUP);

    try {/*from  w  w w. j av a 2 s.  c om*/
        execute(() -> onExecute(sort, order, name, certified, favorite, limit));
        onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_LIST_DATASETS, e));
        on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(emptyStream());
        on(HttpStatus.OK).then(pipeStream());

    } catch (Exception e) {
        throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
    }
}

From source file:org.talend.dataprep.api.service.command.dataset.DataSetPreview.java

public DataSetPreview(String dataSetId, boolean metadata, String sheetName) {
    super(GenericCommand.TRANSFORM_GROUP);
    execute(() -> onExecute(dataSetId, metadata, sheetName));
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_RETRIEVE_DATASET_CONTENT, e,
            ExceptionContext.build().put("id", dataSetId)));
    on(HttpStatus.ACCEPTED, HttpStatus.NO_CONTENT).then(emptyStream());
    on(HttpStatus.OK).then(pipeStream());
    // Move permanently/temporarily behaviors
    BiFunction<HttpRequestBase, HttpResponse, InputStream> move = (req, res) -> {
        Exception cause = new Exception(res.getStatusLine().getStatusCode() + ":" //
                + res.getStatusLine().getReasonPhrase());
        throw new TDPException(APIErrorCodes.DATASET_REDIRECT, cause,
                ExceptionContext.build().put("id", dataSetId));
    };//from  w  ww  . ja  va2 s  .c  o m
    on(HttpStatus.MOVED_PERMANENTLY, HttpStatus.FOUND).then(move);
}

From source file:org.talend.dataprep.api.service.command.error.ErrorList.java

/**
 * Private constructor.//  ww  w  .  ja  va  2  s  .  co m
 *
 * @param type the api type.
 * @param groupKey the command group key.
 */
private ErrorList(HystrixCommandGroupKey groupKey, ServiceType type) {
    super(groupKey);
    execute(() -> onExecute(type));
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_LIST_ERRORS, e));
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(emptyStream());
    on(HttpStatus.OK).then(pipeStream());
}

From source file:org.talend.dataprep.api.service.command.preparation.PreparationList.java

private PreparationList(Format format, Sort sort, Order order) {
    super(GenericCommand.PREPARATION_GROUP);
    execute(() -> onExecute(sort, order, format));
    onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_RETRIEVE_PREPARATION_LIST, e));
    on(HttpStatus.NO_CONTENT, HttpStatus.ACCEPTED).then(emptyStream());
    on(HttpStatus.OK).then(pipeStream());
}