Search in sources :

Example 1 with RequestData

use of org.neo4j.server.rest.web.InternalJettyServletRequest.RequestData in project neo4j by neo4j.

the class BatchOperationsTest method shouldForwardMetadataFromRequestData.

@Test
public void shouldForwardMetadataFromRequestData() throws Exception {
    // Given
    RequestData mock = new RequestData("127.0.0.1", true, 1, "TheLocalName", "129.0.0.1", 2, "authorization/auth");
    InternalJettyServletRequest req = new InternalJettyServletRequest("POST", "https://localhost:7473/db/data/node", "", new InternalJettyServletResponse(), mock);
    // When & then
    assertEquals("127.0.0.1", req.getRemoteAddr());
    assertException(() -> req.getRemoteHost(), UnsupportedOperationException.class, "Remote host-name lookup might prove expensive, this should be explicitly considered.");
    assertTrue(req.isSecure());
    assertEquals(1, req.getRemotePort());
    assertEquals("TheLocalName", req.getLocalName());
    assertEquals("129.0.0.1", req.getLocalAddr());
    assertEquals(2, req.getLocalPort());
    assertEquals("authorization/auth", req.getAuthType());
}
Also used : RequestData(org.neo4j.server.rest.web.InternalJettyServletRequest.RequestData) InternalJettyServletRequest(org.neo4j.server.rest.web.InternalJettyServletRequest) InternalJettyServletResponse(org.neo4j.server.rest.web.InternalJettyServletResponse) Test(org.junit.Test)

Example 2 with RequestData

use of org.neo4j.server.rest.web.InternalJettyServletRequest.RequestData in project neo4j by neo4j.

the class BatchOperations method parseAndPerform.

protected void parseAndPerform(UriInfo uriInfo, HttpHeaders httpHeaders, HttpServletRequest req, InputStream body, Map<Integer, String> locations) throws IOException, ServletException {
    JsonParser jp = jsonFactory.createJsonParser(body);
    JsonToken token;
    RequestData requestData = RequestData.from(req);
    while ((token = jp.nextToken()) != null) {
        if (token == JsonToken.START_OBJECT) {
            String jobMethod = "", jobPath = "", jobBody = "";
            Integer jobId = null;
            while ((token = jp.nextToken()) != JsonToken.END_OBJECT && token != null) {
                String field = jp.getText();
                jp.nextToken();
                switch(field) {
                    case METHOD_KEY:
                        jobMethod = jp.getText().toUpperCase();
                        break;
                    case TO_KEY:
                        jobPath = jp.getText();
                        break;
                    case ID_KEY:
                        jobId = jp.getIntValue();
                        break;
                    case BODY_KEY:
                        jobBody = readBody(jp);
                        break;
                    default:
                        break;
                }
            }
            // Read one job description. Execute it.
            performRequest(uriInfo, jobMethod, jobPath, jobBody, jobId, httpHeaders, locations, requestData);
        }
    }
}
Also used : RequestData(org.neo4j.server.rest.web.InternalJettyServletRequest.RequestData) JsonToken(org.codehaus.jackson.JsonToken) JsonParser(org.codehaus.jackson.JsonParser)

Aggregations

RequestData (org.neo4j.server.rest.web.InternalJettyServletRequest.RequestData)2 JsonParser (org.codehaus.jackson.JsonParser)1 JsonToken (org.codehaus.jackson.JsonToken)1 Test (org.junit.Test)1 InternalJettyServletRequest (org.neo4j.server.rest.web.InternalJettyServletRequest)1 InternalJettyServletResponse (org.neo4j.server.rest.web.InternalJettyServletResponse)1