Java Code Examples for org.eclipse.jetty.server.Response#SC_OK

The following examples show how to use org.eclipse.jetty.server.Response#SC_OK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TlsCertificateAuthorityServiceHandler.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void writeResponse(ObjectMapper objectMapper, HttpServletRequest request, HttpServletResponse response, TlsCertificateAuthorityResponse tlsCertificateAuthorityResponse,
                           int responseCode) throws IOException {
    if (logger.isInfoEnabled()) {
        logger.info(new StringBuilder("Returning code:").append(responseCode).append(" payload ").append(objectMapper.writeValueAsString(tlsCertificateAuthorityResponse))
                .append(" to ").append(request.getRemoteHost()).toString());
    }
    if (responseCode == Response.SC_OK) {
        objectMapper.writeValue(response.getWriter(), tlsCertificateAuthorityResponse);
        response.setStatus(responseCode);
    } else {
        response.setStatus(responseCode);
        response.setContentType("application/json");
        response.setCharacterEncoding(StandardCharsets.UTF_8.name());
        objectMapper.writeValue(response.getWriter(), tlsCertificateAuthorityResponse);
    }
}
 
Example 2
Source File: TlsCertificateAuthorityServiceHandler.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void writeResponse(ObjectMapper objectMapper, HttpServletRequest request, HttpServletResponse response, TlsCertificateAuthorityResponse tlsCertificateAuthorityResponse,
                           int responseCode) throws IOException {
    if (logger.isInfoEnabled()) {
        logger.info(new StringBuilder("Returning code:").append(responseCode).append(" payload ").append(objectMapper.writeValueAsString(tlsCertificateAuthorityResponse))
                .append(" to ").append(request.getRemoteHost()).toString());
    }
    if (responseCode == Response.SC_OK) {
        objectMapper.writeValue(response.getWriter(), tlsCertificateAuthorityResponse);
        response.setStatus(responseCode);
    } else {
        response.setStatus(responseCode);
        response.setContentType("application/json");
        response.setCharacterEncoding(StandardCharsets.UTF_8.name());
        objectMapper.writeValue(response.getWriter(), tlsCertificateAuthorityResponse);
    }
}
 
Example 3
Source File: TlsCertificateSigningRequestPerformerTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testOk() throws Exception {
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse(testHmac, testSignedCsr);
    tlsCertificateSigningRequestPerformer.perform(keyPair);
}
 
Example 4
Source File: TlsCertificateSigningRequestPerformerTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void test0CertSize() throws Exception {
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse();
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.EXPECTED_ONE_CERTIFICATE, e.getMessage());
    }
}
 
Example 5
Source File: TlsCertificateSigningRequestPerformerTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void test2CertSize() throws Exception {
    certificates.add(caCertificate);
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse();
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.EXPECTED_ONE_CERTIFICATE, e.getMessage());
    }
}
 
Example 6
Source File: TlsCertificateSigningRequestPerformerTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoHmac() throws Exception {
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse(null, testSignedCsr);
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.EXPECTED_RESPONSE_TO_CONTAIN_HMAC, e.getMessage());
    }
}
 
Example 7
Source File: TlsCertificateSigningRequestPerformerTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadHmac() throws Exception {
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse("badHmac".getBytes(StandardCharsets.UTF_8), testSignedCsr);
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.UNEXPECTED_HMAC_RECEIVED_POSSIBLE_MAN_IN_THE_MIDDLE, e.getMessage());
    }
}
 
Example 8
Source File: TlsCertificateSigningRequestPerformerTest.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoCertificate() throws Exception {
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse(testHmac, null);
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.EXPECTED_RESPONSE_TO_CONTAIN_CERTIFICATE, e.getMessage());
    }
}
 
Example 9
Source File: TlsCertificateSigningRequestPerformerTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testOk() throws Exception {
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse(testHmac, testSignedCsr);
    tlsCertificateSigningRequestPerformer.perform(keyPair);
}
 
Example 10
Source File: TlsCertificateSigningRequestPerformerTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void test0CertSize() throws Exception {
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse();
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.EXPECTED_ONE_CERTIFICATE, e.getMessage());
    }
}
 
Example 11
Source File: TlsCertificateSigningRequestPerformerTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void test2CertSize() throws Exception {
    certificates.add(caCertificate);
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse();
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.EXPECTED_ONE_CERTIFICATE, e.getMessage());
    }
}
 
Example 12
Source File: TlsCertificateSigningRequestPerformerTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoHmac() throws Exception {
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse(null, testSignedCsr);
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.EXPECTED_RESPONSE_TO_CONTAIN_HMAC, e.getMessage());
    }
}
 
Example 13
Source File: TlsCertificateSigningRequestPerformerTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadHmac() throws Exception {
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse("badHmac".getBytes(StandardCharsets.UTF_8), testSignedCsr);
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.UNEXPECTED_HMAC_RECEIVED_POSSIBLE_MAN_IN_THE_MIDDLE, e.getMessage());
    }
}
 
Example 14
Source File: TlsCertificateSigningRequestPerformerTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoCertificate() throws Exception {
    certificates.add(caCertificate);
    statusCode = Response.SC_OK;
    tlsCertificateAuthorityResponse = new TlsCertificateAuthorityResponse(testHmac, null);
    try {
        tlsCertificateSigningRequestPerformer.perform(keyPair);
        fail("Expected IOE");
    } catch (IOException e) {
        assertEquals(TlsCertificateSigningRequestPerformer.EXPECTED_RESPONSE_TO_CONTAIN_CERTIFICATE, e.getMessage());
    }
}