use of org.glassfish.jersey.filter.LoggingFilter in project irontest by zheng-wang.
the class IronTestApplication method createSystemResources.
private void createSystemResources(IronTestConfiguration configuration, Environment environment) {
final DBIFactory dbiFactory = new DBIFactory();
final DBI jdbi = dbiFactory.build(environment, configuration.getSystemDatabase(), "systemDatabase");
// create DAO objects
final FolderDAO folderDAO = jdbi.onDemand(FolderDAO.class);
final EnvironmentDAO environmentDAO = jdbi.onDemand(EnvironmentDAO.class);
final EndpointDAO endpointDAO = jdbi.onDemand(EndpointDAO.class);
final TestcaseDAO testcaseDAO = jdbi.onDemand(TestcaseDAO.class);
final TeststepDAO teststepDAO = jdbi.onDemand(TeststepDAO.class);
final AssertionDAO assertionDAO = jdbi.onDemand(AssertionDAO.class);
final UtilsDAO utilsDAO = jdbi.onDemand(UtilsDAO.class);
final FolderTreeNodeDAO folderTreeNodeDAO = jdbi.onDemand(FolderTreeNodeDAO.class);
final UserDefinedPropertyDAO udpDAO = jdbi.onDemand(UserDefinedPropertyDAO.class);
final DataTableColumnDAO dataTableColumnDAO = jdbi.onDemand(DataTableColumnDAO.class);
final DataTableCellDAO dataTableCellDAO = jdbi.onDemand(DataTableCellDAO.class);
final TestcaseRunDAO testcaseRunDAO = jdbi.onDemand(TestcaseRunDAO.class);
final TestcaseIndividualRunDAO testcaseIndividualRunDAO = jdbi.onDemand(TestcaseIndividualRunDAO.class);
final TeststepRunDAO teststepRunDAO = jdbi.onDemand(TeststepRunDAO.class);
UserDAO userDAO = null;
if (isInTeamMode(configuration)) {
userDAO = jdbi.onDemand(UserDAO.class);
}
AppInfo appInfo = new AppInfo();
if (isInTeamMode(configuration)) {
appInfo.setAppMode(AppMode.TEAM);
// ignore bindHost
DefaultServerFactory server = (DefaultServerFactory) configuration.getServerFactory();
List<ConnectorFactory> applicationConnectors = server.getApplicationConnectors();
HttpConnectorFactory httpConnectorFactory = (HttpConnectorFactory) applicationConnectors.get(0);
httpConnectorFactory.setBindHost(null);
// turn on user authentication and authorization
environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<SimplePrincipal>().setAuthenticator(new ResourceAuthenticator(userDAO)).setAuthorizer(new ResourceAuthorizer()).buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(new AuthResponseFilter());
}
// create database tables
// order is important!!! (there are foreign keys linking them)
folderDAO.createSequenceIfNotExists();
folderDAO.createTableIfNotExists();
folderDAO.insertARootNodeIfNotExists();
environmentDAO.createSequenceIfNotExists();
environmentDAO.createTableIfNotExists();
endpointDAO.createSequenceIfNotExists();
endpointDAO.createTableIfNotExists();
testcaseDAO.createSequenceIfNotExists();
testcaseDAO.createTableIfNotExists();
teststepDAO.createSequenceIfNotExists();
teststepDAO.createTableIfNotExists();
assertionDAO.createSequenceIfNotExists();
assertionDAO.createTableIfNotExists();
udpDAO.createSequenceIfNotExists();
udpDAO.createTableIfNotExists();
dataTableColumnDAO.createSequenceIfNotExists();
dataTableColumnDAO.createTableIfNotExists();
dataTableCellDAO.createSequenceIfNotExists();
dataTableCellDAO.createTableIfNotExists();
testcaseRunDAO.createSequenceIfNotExists();
testcaseRunDAO.createTableIfNotExists();
testcaseIndividualRunDAO.createSequenceIfNotExists();
testcaseIndividualRunDAO.createTableIfNotExists();
teststepRunDAO.createSequenceIfNotExists();
teststepRunDAO.createTableIfNotExists();
if (isInTeamMode(configuration)) {
userDAO.createSequenceIfNotExists();
userDAO.createTableIfNotExists();
userDAO.insertBuiltinAdminUserIfNotExists();
}
// register APIs
environment.jersey().register(new SystemResource(appInfo));
environment.jersey().register(new ManagedEndpointResource(appInfo, endpointDAO));
environment.jersey().register(new TestcaseResource(testcaseDAO, teststepDAO));
environment.jersey().register(new FolderResource(folderDAO));
environment.jersey().register(new FolderTreeNodeResource(folderTreeNodeDAO));
environment.jersey().register(new TeststepResource(appInfo, teststepDAO, udpDAO, utilsDAO));
environment.jersey().register(new WSDLResource());
environment.jersey().register(new EnvironmentResource(environmentDAO));
environment.jersey().register(new TestcaseRunResource(testcaseDAO, udpDAO, teststepDAO, utilsDAO, testcaseRunDAO, teststepRunDAO));
environment.jersey().register(new AssertionResource(udpDAO, teststepDAO, utilsDAO));
environment.jersey().register(new UDPResource(udpDAO));
environment.jersey().register(new DataTableResource(utilsDAO));
if (isInTeamMode(configuration)) {
environment.jersey().register(new UserResource(userDAO));
}
// if turned on in config.yml, register jersey LoggingFilter (used for logging Iron Test resource oriented HTTP API requests and responses)
DefaultLoggingFactory defaultLoggingFactory = (DefaultLoggingFactory) configuration.getLoggingFactory();
if (defaultLoggingFactory.getLoggers().containsKey(LoggingFilter.class.getName())) {
environment.jersey().register(new LoggingFilter(Logger.getLogger(LoggingFilter.class.getName()), true));
}
// register exception mappers
environment.jersey().register(new IronTestLoggingExceptionMapper());
}
use of org.glassfish.jersey.filter.LoggingFilter in project cloudbreak by hortonworks.
the class RestClientUtil method createClient.
private static Client createClient(ConfigKey configKey) {
LOGGER.debug("Constructing jax rs client: {}", configKey);
ClientConfig config = new ClientConfig();
config.property(ClientProperties.FOLLOW_REDIRECTS, "false");
config.property(ClientProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT_MS);
config.register(MultiPartFeature.class);
ClientBuilder builder = ClientBuilder.newBuilder().withConfig(config);
if (configKey.isDebug()) {
builder = builder.register(new LoggingFilter(java.util.logging.Logger.getLogger(RestClientUtil.class.getName()), true));
}
if (!configKey.isSecure()) {
builder.sslContext(CertificateTrustManager.sslContext());
builder.hostnameVerifier(CertificateTrustManager.hostnameVerifier());
}
Client client = builder.build();
client.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, configKey.isIgnorePreValidation());
SSLContext sslContext = client.getSslContext();
LOGGER.warn("RestClient has been constructed: {}, client: {}, sslContext: {}", configKey, client, sslContext);
return client;
}
use of org.glassfish.jersey.filter.LoggingFilter in project openstack4j by ContainX.
the class HttpCommand method initialize.
private void initialize() {
Client client = ClientFactory.create(request.getConfig());
// try to set unsupported HTTP method. In our case used for PATCH.
if (request.getMethod().name() == "PATCH")
client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
WebTarget target = client.target(request.getEndpoint()).path(request.getPath());
if (HttpLoggingFilter.isLoggingEnabled())
target.register(new LoggingFilter(Logger.getLogger("os"), 10000));
target = populateQueryParams(target, request);
invocation = target.request(MediaType.APPLICATION_JSON);
populateHeaders(invocation, request);
entity = (request.getEntity() == null) ? null : Entity.entity(request.getEntity(), request.getContentType());
}
use of org.glassfish.jersey.filter.LoggingFilter in project irontest by zheng-wang.
the class IronTestApplication method createSystemResources.
private void createSystemResources(IronTestConfiguration configuration, Environment environment, Jdbi systemDBJdbi, WireMockServer wireMockServer) {
systemDBJdbi.registerArgument(new PropertiesArgumentFactory());
systemDBJdbi.registerArgument(new EndpointPropertiesArgumentFactory());
// create DAO objects
final VersionDAO versionDAO = systemDBJdbi.onDemand(VersionDAO.class);
final FolderDAO folderDAO = systemDBJdbi.onDemand(FolderDAO.class);
final EnvironmentDAO environmentDAO = systemDBJdbi.onDemand(EnvironmentDAO.class);
final EndpointDAO endpointDAO = systemDBJdbi.onDemand(EndpointDAO.class);
final TestcaseDAO testcaseDAO = systemDBJdbi.onDemand(TestcaseDAO.class);
final TeststepDAO teststepDAO = systemDBJdbi.onDemand(TeststepDAO.class);
final AssertionDAO assertionDAO = systemDBJdbi.onDemand(AssertionDAO.class);
final PropertyExtractorDAO propertyExtractorDAO = systemDBJdbi.onDemand(PropertyExtractorDAO.class);
final UtilsDAO utilsDAO = systemDBJdbi.onDemand(UtilsDAO.class);
final FolderTreeNodeDAO folderTreeNodeDAO = systemDBJdbi.onDemand(FolderTreeNodeDAO.class);
final UserDefinedPropertyDAO udpDAO = systemDBJdbi.onDemand(UserDefinedPropertyDAO.class);
final DataTableDAO dataTableDAO = systemDBJdbi.onDemand(DataTableDAO.class);
final DataTableColumnDAO dataTableColumnDAO = systemDBJdbi.onDemand(DataTableColumnDAO.class);
final DataTableCellDAO dataTableCellDAO = systemDBJdbi.onDemand(DataTableCellDAO.class);
final TestcaseRunDAO testcaseRunDAO = systemDBJdbi.onDemand(TestcaseRunDAO.class);
final TestcaseIndividualRunDAO testcaseIndividualRunDAO = systemDBJdbi.onDemand(TestcaseIndividualRunDAO.class);
final TeststepRunDAO teststepRunDAO = systemDBJdbi.onDemand(TeststepRunDAO.class);
final HTTPStubMappingDAO httpStubMappingDAO = systemDBJdbi.onDemand(HTTPStubMappingDAO.class);
UserDAO userDAO = null;
if (isInTeamMode(configuration)) {
userDAO = systemDBJdbi.onDemand(UserDAO.class);
}
AppInfo appInfo = new AppInfo();
if (isInTeamMode(configuration)) {
appInfo.setAppMode(AppMode.TEAM);
// ignore bindHost
DefaultServerFactory server = (DefaultServerFactory) configuration.getServerFactory();
List<ConnectorFactory> applicationConnectors = server.getApplicationConnectors();
HttpConnectorFactory httpConnectorFactory = (HttpConnectorFactory) applicationConnectors.get(0);
httpConnectorFactory.setBindHost(null);
// turn on user authentication and authorization
environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<SimplePrincipal>().setAuthenticator(new ResourceAuthenticator(userDAO)).setAuthorizer(new ResourceAuthorizer()).buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
environment.jersey().register(new AuthResponseFilter());
}
// create database tables
// keep the order!!! (there are foreign keys linking some of them)
versionDAO.createTableIfNotExists();
versionDAO.insertVersionIfNotExists();
folderDAO.createSequenceIfNotExists();
folderDAO.createTableIfNotExists();
folderDAO.insertARootNodeIfNotExists();
environmentDAO.createSequenceIfNotExists();
environmentDAO.createTableIfNotExists();
endpointDAO.createSequenceIfNotExists();
endpointDAO.createTableIfNotExists();
testcaseDAO.createSequenceIfNotExists();
testcaseDAO.createTableIfNotExists();
teststepDAO.createSequenceIfNotExists();
teststepDAO.createTableIfNotExists();
assertionDAO.createSequenceIfNotExists();
assertionDAO.createTableIfNotExists();
propertyExtractorDAO.createSequenceIfNotExists();
propertyExtractorDAO.createTableIfNotExists();
udpDAO.createSequenceIfNotExists();
udpDAO.createTableIfNotExists();
dataTableColumnDAO.createSequenceIfNotExists();
dataTableColumnDAO.createTableIfNotExists();
dataTableColumnDAO.insertCaptionColumnForTestcasesWithoutDataTableColumn();
dataTableCellDAO.createSequenceIfNotExists();
dataTableCellDAO.createTableIfNotExists();
testcaseRunDAO.createSequenceIfNotExists();
testcaseRunDAO.createTableIfNotExists();
testcaseIndividualRunDAO.createSequenceIfNotExists();
testcaseIndividualRunDAO.createTableIfNotExists();
teststepRunDAO.createSequenceIfNotExists();
teststepRunDAO.createTableIfNotExists();
httpStubMappingDAO.createSequenceIfNotExists();
httpStubMappingDAO.createTableIfNotExists();
if (isInTeamMode(configuration)) {
userDAO.createSequenceIfNotExists();
userDAO.createTableIfNotExists();
userDAO.insertBuiltinAdminUserIfNotExists();
}
// register APIs
environment.jersey().register(new SystemResource(appInfo));
environment.jersey().register(new ManagedEndpointResource(appInfo, endpointDAO));
environment.jersey().register(new TestcaseResource(testcaseDAO, teststepDAO));
environment.jersey().register(new FolderResource(folderDAO, testcaseDAO));
environment.jersey().register(new FolderTreeNodeResource(folderTreeNodeDAO));
environment.jersey().register(new TeststepResource(appInfo, teststepDAO, udpDAO, utilsDAO, dataTableDAO, assertionDAO));
environment.jersey().register(new WSDLResource());
environment.jersey().register(new EnvironmentResource(environmentDAO));
environment.jersey().register(new TestcaseRunResource(testcaseDAO, utilsDAO, testcaseRunDAO, teststepRunDAO, wireMockServer));
environment.jersey().register(new AssertionResource(udpDAO, teststepDAO, dataTableDAO, assertionDAO));
environment.jersey().register(new UDPResource(udpDAO));
environment.jersey().register(new DataTableResource(dataTableDAO, dataTableColumnDAO, dataTableCellDAO));
environment.jersey().register(new HTTPStubResource(httpStubMappingDAO, wireMockServer, udpDAO, dataTableDAO));
environment.jersey().register(new MockServerResource(wireMockServer));
environment.jersey().register(new PropertyExtractorResource(udpDAO, dataTableDAO, propertyExtractorDAO));
if (isInTeamMode(configuration)) {
environment.jersey().register(new UserResource(userDAO));
}
// if turned on in config.yml, register jersey LoggingFilter (used for logging Iron Test resource oriented HTTP API requests and responses)
DefaultLoggingFactory defaultLoggingFactory = (DefaultLoggingFactory) configuration.getLoggingFactory();
if (defaultLoggingFactory.getLoggers().containsKey(LoggingFilter.class.getName())) {
environment.jersey().register(new LoggingFilter(Logger.getLogger(LoggingFilter.class.getName()), true));
}
// register exception mappers
environment.jersey().register(new IronTestLoggingExceptionMapper());
}
use of org.glassfish.jersey.filter.LoggingFilter in project cloudbreak by hortonworks.
the class RestClientUtil method createClient.
public static Client createClient(SSLContext sslContext, boolean debug, Class<?> debugClass) {
ClientConfig config = new ClientConfig();
config.property(ClientProperties.FOLLOW_REDIRECTS, "false");
config.property(ClientProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT_MS);
config.register(MultiPartFeature.class);
ClientBuilder builder = ClientBuilder.newBuilder().withConfig(config);
builder.sslContext(sslContext);
builder.hostnameVerifier(CertificateTrustManager.hostnameVerifier());
if (debug) {
builder = builder.register(new LoggingFilter(java.util.logging.Logger.getLogger(debugClass.getName()), true));
}
Client client = builder.build();
LOGGER.debug("Jax rs client has been constructed: {}, sslContext: {}", client, sslContext);
return client;
}
Aggregations