Search in sources :

Example 1 with ResponseEntity

use of org.springframework.http.ResponseEntity in project java-chassis by ServiceComb.

the class SpringmvcConsumerResponseMapper method mapResponse.

@Override
public Object mapResponse(Response response) {
    HttpStatus status = HttpStatus.valueOf(response.getStatusCode());
    HttpHeaders httpHeaders = null;
    Map<String, List<Object>> headers = response.getHeaders().getHeaderMap();
    if (headers != null) {
        httpHeaders = new HttpHeaders();
        for (Entry<String, List<Object>> entry : headers.entrySet()) {
            for (Object value : entry.getValue()) {
                httpHeaders.add(entry.getKey(), String.valueOf(value));
            }
        }
    }
    return new ResponseEntity<Object>(response.getResult(), httpHeaders, status);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List)

Example 2 with ResponseEntity

use of org.springframework.http.ResponseEntity in project java-chassis by ServiceComb.

the class SpringmvcProducerResponseMapper method mapResponse.

@SuppressWarnings("unchecked")
@Override
public Response mapResponse(StatusType status, Object response) {
    ResponseEntity<Object> springmvcResponse = (ResponseEntity<Object>) response;
    StatusType responseStatus = new HttpStatus(springmvcResponse.getStatusCode().value(), springmvcResponse.getStatusCode().getReasonPhrase());
    Response cseResponse = Response.status(responseStatus).entity(springmvcResponse.getBody());
    HttpHeaders headers = springmvcResponse.getHeaders();
    Headers cseHeaders = cseResponse.getHeaders();
    for (Entry<String, List<String>> entry : headers.entrySet()) {
        if (entry.getValue() == null || entry.getValue().isEmpty()) {
            continue;
        }
        for (String value : entry.getValue()) {
            cseHeaders.addHeader(entry.getKey(), value);
        }
    }
    return cseResponse;
}
Also used : Response(io.servicecomb.core.Response) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) HttpStatus(io.servicecomb.core.context.HttpStatus) StatusType(javax.ws.rs.core.Response.StatusType) Headers(io.servicecomb.swagger.invocation.response.Headers) HttpHeaders(org.springframework.http.HttpHeaders) List(java.util.List)

Example 3 with ResponseEntity

use of org.springframework.http.ResponseEntity in project rhino by PLOS.

the class ArticleCrudController method deleteRevision.

@Transactional(readOnly = false)
@RequestMapping(value = "/articles/{doi}/revisions/{revision}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteRevision(@PathVariable("doi") String doi, @PathVariable("revision") int revisionNumber) {
    ArticleRevisionIdentifier revisionId = ArticleRevisionIdentifier.create(DoiEscaping.unescape(doi), revisionNumber);
    articleRevisionWriteService.deleteRevision(revisionId);
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArticleRevisionIdentifier(org.ambraproject.rhino.identity.ArticleRevisionIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ResponseEntity

use of org.springframework.http.ResponseEntity in project rhino by PLOS.

the class ArticleCrudController method updateSolrIndex.

@RequestMapping(value = "/articles/{doi:.+}", params = { "solrIndex" }, method = RequestMethod.POST)
public ResponseEntity<?> updateSolrIndex(@PathVariable("doi") String doi) {
    ArticleIdentifier identifier = ArticleIdentifier.create(DoiEscaping.unescape(doi));
    solrIndexService.updateSolrIndex(identifier);
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ResponseEntity

use of org.springframework.http.ResponseEntity in project rhino by PLOS.

the class ArticleCrudController method getRawCategoriesAndText.

/**
   * Retrieves the raw taxonomy categories associated with the article along with the text that is sent to the taxonomy
   * server for classification
   *
   * @param request
   * @return a String containing the text and raw categories in the form of <text> \n\n <categories>
   * @throws IOException
   */
// TODO: Get rid of this?
@Transactional(readOnly = true)
@RequestMapping(value = "/articles/{doi}/categories", method = RequestMethod.GET, params = "rawCategoriesAndText")
public ResponseEntity<String> getRawCategoriesAndText(HttpServletRequest request, @PathVariable("doi") String doi) throws IOException {
    ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(doi));
    String categoriesAndText = articleCrudService.getRawCategoriesAndText(articleId);
    HttpHeaders responseHeader = new HttpHeaders();
    responseHeader.setContentType(MediaType.TEXT_HTML);
    return new ResponseEntity<>(categoriesAndText, responseHeader, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResponseEntity (org.springframework.http.ResponseEntity)1188 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)419 HttpHeaders (org.springframework.http.HttpHeaders)398 Test (org.junit.Test)120 ApiOperation (io.swagger.annotations.ApiOperation)116 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)108 HashMap (java.util.HashMap)104 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)103 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)98 HttpStatus (org.springframework.http.HttpStatus)88 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)85 ArrayList (java.util.ArrayList)80 GetMapping (org.springframework.web.bind.annotation.GetMapping)79 Timed (com.codahale.metrics.annotation.Timed)68 IOException (java.io.IOException)67 List (java.util.List)65 URI (java.net.URI)49 MediaType (org.springframework.http.MediaType)48 Test (org.junit.jupiter.api.Test)46 HttpEntity (org.springframework.http.HttpEntity)46