Search in sources :

Example 6 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext 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 7 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext 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 8 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.

the class TestCseHttpEntity method test.

@Test
public void test() {
    CseHttpEntity<String> entity = new CseHttpEntity<>(null, null);
    entity.addContext("c1", "c1v");
    Assert.assertEquals(1, entity.getContext().getContext().size());
    Assert.assertEquals("c1v", entity.getContext().getContext("c1"));
    InvocationContext context = new InvocationContext();
    context.addContext("c2", "c2v");
    entity.setContext(context);
    Assert.assertEquals(1, entity.getContext().getContext().size());
    Assert.assertEquals("c2v", entity.getContext().getContext("c2"));
}
Also used : InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) Test(org.junit.Test)

Example 9 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext 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)

Example 10 with InvocationContext

use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project incubator-servicecomb-java-chassis by apache.

the class CodeFirstSpringmvcBase method responseEntity.

public ResponseEntity<Date> responseEntity(InvocationContext c1, Date date) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("h1", "h1v " + c1.getContext().toString());
    InvocationContext c2 = ContextUtils.getInvocationContext();
    headers.add("h2", "h2v " + c2.getContext().toString());
    return new ResponseEntity<Date>(date, headers, HttpStatus.ACCEPTED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext)

Aggregations

InvocationContext (org.apache.servicecomb.swagger.invocation.context.InvocationContext)15 User (org.apache.servicecomb.demo.server.User)5 ResponseHeaders (org.apache.servicecomb.swagger.extend.annotations.ResponseHeaders)5 HttpHeaders (org.springframework.http.HttpHeaders)5 Response (org.apache.servicecomb.swagger.invocation.Response)4 Headers (org.apache.servicecomb.swagger.invocation.response.Headers)4 Test (org.junit.Test)4 ApiResponse (io.swagger.annotations.ApiResponse)3 ResponseEntity (org.springframework.http.ResponseEntity)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Vertx (io.vertx.core.Vertx)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1