Search in sources :

Example 1 with StatusType

use of javax.ws.rs.core.Response.StatusType in project jersey by jersey.

the class ResponseTest method testDeclaredStatusCodes.

public void testDeclaredStatusCodes() {
    for (Status s : Status.values()) {
        StatusType _s = Response.status(s.getStatusCode()).build().getStatusInfo();
        assertSame(s, _s);
    }
}
Also used : Status(javax.ws.rs.core.Response.Status) StatusType(javax.ws.rs.core.Response.StatusType)

Example 2 with StatusType

use of javax.ws.rs.core.Response.StatusType in project java-chassis by ServiceComb.

the class HttpStatusManager method getOrCreateByStatusCode.

public StatusType getOrCreateByStatusCode(int code) {
    StatusType statusType = statusMap.get(code);
    if (statusType != null) {
        return statusType;
    }
    statusType = new HttpStatus(code, "");
    addStatusType(statusType);
    return statusType;
}
Also used : StatusType(javax.ws.rs.core.Response.StatusType)

Example 3 with StatusType

use of javax.ws.rs.core.Response.StatusType 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 4 with StatusType

use of javax.ws.rs.core.Response.StatusType in project java-chassis by ServiceComb.

the class TestConfig method testHttpStatus.

@Test
public void testHttpStatus() {
    StatusType oStatus = new HttpStatus(204, "InternalServerError");
    Assert.assertEquals("InternalServerError", oStatus.getReasonPhrase());
}
Also used : HttpStatus(io.servicecomb.core.context.HttpStatus) StatusType(javax.ws.rs.core.Response.StatusType) Test(org.junit.Test)

Example 5 with StatusType

use of javax.ws.rs.core.Response.StatusType in project jersey by jersey.

the class ResponseTest method testUndeclaredStatusCodes.

public void testUndeclaredStatusCodes() {
    StatusType st = Response.status(199).build().getStatusInfo();
    assertNotNull(st);
    assertEquals(199, st.getStatusCode());
    assertEquals("", st.getReasonPhrase());
    assertEquals(Family.INFORMATIONAL, st.getFamily());
    st = Response.status(299).build().getStatusInfo();
    assertNotNull(st);
    assertEquals(299, st.getStatusCode());
    assertEquals("", st.getReasonPhrase());
    assertEquals(Family.SUCCESSFUL, st.getFamily());
    st = Response.status(399).build().getStatusInfo();
    assertNotNull(st);
    assertEquals(399, st.getStatusCode());
    assertEquals("", st.getReasonPhrase());
    assertEquals(Family.REDIRECTION, st.getFamily());
    st = Response.status(499).build().getStatusInfo();
    assertNotNull(st);
    assertEquals(499, st.getStatusCode());
    assertEquals("", st.getReasonPhrase());
    assertEquals(Family.CLIENT_ERROR, st.getFamily());
    st = Response.status(599).build().getStatusInfo();
    assertNotNull(st);
    assertEquals(599, st.getStatusCode());
    assertEquals("", st.getReasonPhrase());
    assertEquals(Family.SERVER_ERROR, st.getFamily());
}
Also used : StatusType(javax.ws.rs.core.Response.StatusType)

Aggregations

StatusType (javax.ws.rs.core.Response.StatusType)6 HttpStatus (io.servicecomb.core.context.HttpStatus)2 Test (org.junit.Test)2 Response (io.servicecomb.core.Response)1 Headers (io.servicecomb.swagger.invocation.response.Headers)1 List (java.util.List)1 Status (javax.ws.rs.core.Response.Status)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1