Search in sources :

Example 1 with ResponseHeaders

use of org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders in project incubator-servicecomb-java-chassis by apache.

the class CodeFirstJaxrs method response.

@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@Path("/response")
@GET
public Response response(InvocationContext c1) {
    Response response = Response.createSuccess(Status.ACCEPTED, new User());
    Headers headers = response.getHeaders();
    headers.addHeader("h1", "h1v " + c1.getContext().toString());
    InvocationContext c2 = ContextUtils.getInvocationContext();
    headers.addHeader("h2", "h2v " + c2.getContext().toString());
    return response;
}
Also used : ApiResponse(io.swagger.annotations.ApiResponse) Response(org.apache.servicecomb.swagger.invocation.Response) User(org.apache.servicecomb.demo.server.User) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) Headers(org.apache.servicecomb.swagger.invocation.response.Headers) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) ApiResponse(io.swagger.annotations.ApiResponse)

Example 2 with ResponseHeaders

use of org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders in project incubator-servicecomb-java-chassis by apache.

the class ResponseHeadersProcessor method process.

@Override
public void process(Object annotation, OperationGenerator operationGenerator) {
    ResponseHeaders responseHeaders = (ResponseHeaders) annotation;
    MethodAnnotationProcessor processor = operationGenerator.getContext().findMethodAnnotationProcessor(ResponseHeader.class);
    for (ResponseHeader responseHeader : responseHeaders.value()) {
        processor.process(responseHeader, operationGenerator);
    }
}
Also used : ResponseHeader(io.swagger.annotations.ResponseHeader) MethodAnnotationProcessor(org.apache.servicecomb.swagger.generator.core.MethodAnnotationProcessor) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders)

Example 3 with ResponseHeaders

use of org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders in project incubator-servicecomb-java-chassis by apache.

the class CodeFirstSpringmvc method cseResponse.

@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@RequestMapping(path = "/cseResponse", method = RequestMethod.GET)
public Response cseResponse(InvocationContext c1) {
    Response response = Response.createSuccess(Status.ACCEPTED, new User());
    Headers headers = response.getHeaders();
    headers.addHeader("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE).toString());
    InvocationContext c2 = ContextUtils.getInvocationContext();
    headers.addHeader("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE).toString());
    return response;
}
Also used : Response(org.apache.servicecomb.swagger.invocation.Response) ApiResponse(io.swagger.annotations.ApiResponse) User(org.apache.servicecomb.demo.server.User) HttpHeaders(org.springframework.http.HttpHeaders) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) Headers(org.apache.servicecomb.swagger.invocation.response.Headers) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) ApiResponse(io.swagger.annotations.ApiResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ResponseHeaders

use of org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders in project incubator-servicecomb-java-chassis by apache.

the class CodeFirstSpringmvc method responseEntity.

@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@RequestMapping(path = "/responseEntity", method = RequestMethod.POST)
public ResponseEntity<Date> responseEntity(InvocationContext c1, @RequestAttribute("date") Date date) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE).toString());
    InvocationContext c2 = ContextUtils.getInvocationContext();
    headers.add("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE).toString());
    return new ResponseEntity<>(date, headers, HttpStatus.ACCEPTED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ResponseHeaders

use of org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders in project incubator-servicecomb-java-chassis by apache.

the class CodeFirstSpringmvc method responseEntityPATCH.

@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@RequestMapping(path = "/responseEntity", method = RequestMethod.PATCH)
public ResponseEntity<Date> responseEntityPATCH(InvocationContext c1, @RequestAttribute("date") Date date) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE).toString());
    InvocationContext c2 = ContextUtils.getInvocationContext();
    headers.add("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE).toString());
    return new ResponseEntity<>(date, headers, HttpStatus.ACCEPTED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) ResponseHeaders(org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResponseHeaders (org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders)6 InvocationContext (org.apache.servicecomb.swagger.invocation.context.InvocationContext)5 ApiResponse (io.swagger.annotations.ApiResponse)3 User (org.apache.servicecomb.demo.server.User)3 Response (org.apache.servicecomb.swagger.invocation.Response)3 Headers (org.apache.servicecomb.swagger.invocation.response.Headers)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 ResponseEntity (org.springframework.http.ResponseEntity)2 ResponseHeader (io.swagger.annotations.ResponseHeader)1 MethodAnnotationProcessor (org.apache.servicecomb.swagger.generator.core.MethodAnnotationProcessor)1