Search in sources :

Example 1 with ApplicationRequest

use of io.gravitee.rest.api.model.log.ApplicationRequest in project gravitee-management-rest-api by gravitee-io.

the class LogMapperTest method testConvertFull.

@Test
public void testConvertFull() {
    // init
    ApplicationRequest applicationRequest = new ApplicationRequest();
    applicationRequest.setApi(LOG_API);
    applicationRequest.setHost(LOG_HOST);
    applicationRequest.setId(LOG_APPLICATION);
    Map<String, Map<String, String>> metadata = new HashMap<String, Map<String, String>>();
    HashMap<String, String> appMetadata = new HashMap<String, String>();
    appMetadata.put(LOG_API, LOG_API);
    metadata.put(LOG_APPLICATION, appMetadata);
    applicationRequest.setMetadata(metadata);
    applicationRequest.setMethod(HttpMethod.CONNECT);
    applicationRequest.setPath(LOG_PATH);
    applicationRequest.setPlan(LOG_PLAN);
    Request request = new Request();
    request.setBody(LOG_REQUEST_BODY);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.add(HttpHeaders.ACCEPT, LOG_ID);
    request.setHeaders(requestHeaders);
    request.setMethod(HttpMethod.CONNECT);
    request.setUri(LOG_REQUEST_URI);
    applicationRequest.setRequest(request);
    applicationRequest.setRequestContentLength(1L);
    Response response = new Response();
    response.setBody(LOG_RESPONSE_BODY);
    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.add(HttpHeaders.ACCEPT_CHARSET, LOG_ID);
    response.setHeaders(responseHeaders);
    response.setStatus(1);
    applicationRequest.setResponse(response);
    applicationRequest.setResponseContentLength(1L);
    applicationRequest.setResponseTime(1);
    applicationRequest.setSecurityToken(LOG_SECURITY_TOKEN);
    applicationRequest.setSecurityType(LOG_SECURITY_TYPE);
    applicationRequest.setStatus(1);
    applicationRequest.setTimestamp(1);
    applicationRequest.setTransactionId(LOG_TRANSACTION);
    applicationRequest.setUser(LOG_USER);
    // Test
    Log log = logMapper.convert(applicationRequest);
    assertNotNull(log);
    assertEquals(LOG_API, log.getApi());
    assertEquals(LOG_HOST, log.getHost());
    assertEquals(LOG_APPLICATION, log.getId());
    assertEquals(metadata, log.getMetadata());
    assertEquals(io.gravitee.rest.api.portal.rest.model.HttpMethod.CONNECT, log.getMethod());
    assertEquals(LOG_PATH, log.getPath());
    assertEquals(LOG_PLAN, log.getPlan());
    final io.gravitee.rest.api.portal.rest.model.Request logRequest = log.getRequest();
    assertNotNull(logRequest);
    assertEquals(LOG_REQUEST_BODY, logRequest.getBody());
    assertEquals(requestHeaders, logRequest.getHeaders());
    assertEquals(io.gravitee.rest.api.portal.rest.model.HttpMethod.CONNECT, logRequest.getMethod());
    assertEquals(LOG_REQUEST_URI, logRequest.getUri());
    assertEquals(1L, log.getRequestContentLength().longValue());
    final io.gravitee.rest.api.portal.rest.model.Response logResponse = log.getResponse();
    assertNotNull(logResponse);
    assertEquals(LOG_RESPONSE_BODY, logResponse.getBody());
    assertEquals(responseHeaders, logResponse.getHeaders());
    assertEquals(1, logResponse.getStatus().intValue());
    assertEquals(1L, log.getResponseContentLength().longValue());
    assertEquals(1L, log.getResponseTime().longValue());
    assertEquals(LOG_SECURITY_TOKEN, log.getSecurityToken());
    assertEquals(LOG_SECURITY_TYPE, log.getSecurityType());
    assertEquals(1, log.getStatus().intValue());
    assertEquals(1L, log.getTimestamp().longValue());
    assertEquals(LOG_TRANSACTION, log.getTransactionId());
    assertEquals(LOG_USER, log.getUser());
}
Also used : HttpHeaders(io.gravitee.common.http.HttpHeaders) HashMap(java.util.HashMap) Log(io.gravitee.rest.api.portal.rest.model.Log) ApplicationRequest(io.gravitee.rest.api.model.log.ApplicationRequest) Request(io.gravitee.rest.api.model.log.extended.Request) Response(io.gravitee.rest.api.model.log.extended.Response) ApplicationRequest(io.gravitee.rest.api.model.log.ApplicationRequest) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with ApplicationRequest

use of io.gravitee.rest.api.model.log.ApplicationRequest in project gravitee-management-rest-api by gravitee-io.

the class ApplicationLogsResource method applicationLog.

@GET
@Path("/{logId}")
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_LOG, acls = RolePermissionAction.READ) })
public Response applicationLog(@PathParam("applicationId") String applicationId, @PathParam("logId") String logId, @QueryParam("timestamp") Long timestamp) {
    // Does application exists ?
    applicationService.findById(applicationId);
    ApplicationRequest applicationLogs = logsService.findApplicationLog(logId, timestamp);
    return Response.ok(logMapper.convert(applicationLogs)).build();
}
Also used : ApplicationRequest(io.gravitee.rest.api.model.log.ApplicationRequest) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 3 with ApplicationRequest

use of io.gravitee.rest.api.model.log.ApplicationRequest in project gravitee-management-rest-api by gravitee-io.

the class ApplicationLogsResourceTest method shouldGetLog.

@Test
public void shouldGetLog() {
    final ApplicationRequest toBeReturned = new ApplicationRequest();
    toBeReturned.setId(LOG);
    doReturn(toBeReturned).when(logsService).findApplicationLog(eq(LOG), any());
    final Response response = target(APPLICATION).path("logs").path(LOG).queryParam("timestamp", 1).request().get();
    assertEquals(HttpStatusCode.OK_200, response.getStatus());
    Mockito.verify(logMapper).convert(toBeReturned);
    Mockito.verify(logsService).findApplicationLog(LOG, 1L);
    Log Log = response.readEntity(Log.class);
    assertNotNull(Log);
}
Also used : LogsResponse(io.gravitee.rest.api.portal.rest.model.LogsResponse) Response(javax.ws.rs.core.Response) SearchLogResponse(io.gravitee.rest.api.model.log.SearchLogResponse) Log(io.gravitee.rest.api.portal.rest.model.Log) ApplicationRequest(io.gravitee.rest.api.model.log.ApplicationRequest) Test(org.junit.Test)

Example 4 with ApplicationRequest

use of io.gravitee.rest.api.model.log.ApplicationRequest in project gravitee-management-rest-api by gravitee-io.

the class LogMapper method convert.

public Log convert(ApplicationRequest applicationRequest) {
    final Log logItem = new Log();
    logItem.setApi(applicationRequest.getApi());
    logItem.setHost(applicationRequest.getHost());
    logItem.setId(applicationRequest.getId());
    logItem.setMetadata(applicationRequest.getMetadata() == null ? null : new HashMap(applicationRequest.getMetadata()));
    logItem.setMethod(HttpMethod.fromValue(applicationRequest.getMethod().name()));
    logItem.setPath(applicationRequest.getPath());
    logItem.setPlan(applicationRequest.getPlan());
    if (applicationRequest.getRequest() != null) {
        logItem.setRequest(new Request().body(applicationRequest.getRequest().getBody()).headers(applicationRequest.getRequest().getHeaders()).method(HttpMethod.fromValue(applicationRequest.getRequest().getMethod().name())).uri(applicationRequest.getRequest().getUri()));
    }
    logItem.setRequestContentLength(applicationRequest.getRequestContentLength());
    if (applicationRequest.getResponse() != null) {
        logItem.setResponse(new Response().body(applicationRequest.getResponse().getBody()).status(applicationRequest.getResponse().getStatus()).headers(applicationRequest.getResponse().getHeaders()));
    }
    logItem.setResponseContentLength(applicationRequest.getResponseContentLength());
    logItem.setResponseTime(applicationRequest.getResponseTime());
    logItem.setSecurityToken(applicationRequest.getSecurityToken());
    logItem.setSecurityType(applicationRequest.getSecurityType());
    logItem.setStatus(applicationRequest.getStatus());
    logItem.setTimestamp(applicationRequest.getTimestamp());
    logItem.setTransactionId(applicationRequest.getTransactionId());
    logItem.setUser(applicationRequest.getUser());
    return logItem;
}
Also used : Response(io.gravitee.rest.api.portal.rest.model.Response) Log(io.gravitee.rest.api.portal.rest.model.Log) HashMap(java.util.HashMap) Request(io.gravitee.rest.api.portal.rest.model.Request) ApplicationRequest(io.gravitee.rest.api.model.log.ApplicationRequest)

Aggregations

ApplicationRequest (io.gravitee.rest.api.model.log.ApplicationRequest)4 Log (io.gravitee.rest.api.portal.rest.model.Log)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 HttpHeaders (io.gravitee.common.http.HttpHeaders)1 SearchLogResponse (io.gravitee.rest.api.model.log.SearchLogResponse)1 Request (io.gravitee.rest.api.model.log.extended.Request)1 Response (io.gravitee.rest.api.model.log.extended.Response)1 LogsResponse (io.gravitee.rest.api.portal.rest.model.LogsResponse)1 Request (io.gravitee.rest.api.portal.rest.model.Request)1 Response (io.gravitee.rest.api.portal.rest.model.Response)1 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1