aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--feature-eelf/src/main/feature/config/logback-eelf.xml9
-rw-r--r--feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnectorTest.java44
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java2
-rw-r--r--policy-management/src/main/server/config/logback.xml6
4 files changed, 58 insertions, 3 deletions
diff --git a/feature-eelf/src/main/feature/config/logback-eelf.xml b/feature-eelf/src/main/feature/config/logback-eelf.xml
index 7c2725d8..d76eb20b 100644
--- a/feature-eelf/src/main/feature/config/logback-eelf.xml
+++ b/feature-eelf/src/main/feature/config/logback-eelf.xml
@@ -33,7 +33,7 @@
<property name="defaultAuditPattern"
value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}||%X{ProcessKey}|%X{CustomField1}|%X{CustomField2}|%X{CustomField3}|%X{CustomField4}|%msg%n" />
<property name="defaultErrorPattern"
- value="%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%X{RequestId}|%thread|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{ErrorCategory}|%X{ErrorCode}|%X{ErrorDesciption}|%msg%replace(%xException){'\n',' - '}%nopex%n" />
+ value="%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00, UTC}|%X{RequestId}|%thread|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{ErrorCategory}|%X{ErrorCode}|%X{ErrorDesciption}|%msg%replace(%xException){'\n',' - '}%nopex%n" />
<property name="networkPattern" value="[%d|%t]%m%n" />
<property name="debugPattern" value="[%date|%level|%logger{0}|%thread] %replace(%msg){'\n', ' '}%n" />
@@ -142,7 +142,8 @@
<appender name="NetworkOut" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logDirectory}/${networkLogName}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>logs/network.log.%i.zip</fileNamePattern>
+ <fileNamePattern>${logDirectory}/${networkLogName}.%i.log.zip
+ </fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>5</maxIndex>
</rollingPolicy>
@@ -178,6 +179,10 @@
<appender-ref ref="AsyncNetworkOut" />
</logger>
+ <logger name="org.eclipse.jetty.server.RequestLog" level="info" additivity="false">
+ <appender-ref ref="AsyncNetworkOut" />
+ </logger>
+
<root level="INFO">
<appender-ref ref="asyncEELFDebug" />
<appender-ref ref="asyncEELFError" />
diff --git a/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnectorTest.java b/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnectorTest.java
index c16a1bbd..792e6f8b 100644
--- a/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnectorTest.java
+++ b/feature-session-persistence/src/test/java/org/onap/policy/drools/persistence/JpaDroolsSessionConnectorTest.java
@@ -22,12 +22,17 @@ package org.onap.policy.drools.persistence;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.junit.After;
@@ -86,6 +91,45 @@ public class JpaDroolsSessionConnectorTest {
assertEquals("{name=nameY, id=20}",
conn.get("nameY").toString());
}
+
+ @Test(expected = RuntimeException.class)
+ public void testGet_NewEx() {
+ EntityManagerFactory emf = mock(EntityManagerFactory.class);
+ EntityManager em = mock(EntityManager.class);
+
+ when(emf.createEntityManager()).thenReturn(em);
+ when(em.getTransaction()).thenThrow(new RuntimeException("expected exception"));
+
+ conn = new JpaDroolsSessionConnector(emf);
+ conn.get("xyz");
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testGet_FindEx() {
+ EntityManagerFactory emf = mock(EntityManagerFactory.class);
+ EntityManager em = mock(EntityManager.class);
+ EntityTransaction tr = mock(EntityTransaction.class);
+
+ when(emf.createEntityManager()).thenReturn(em);
+ when(em.getTransaction()).thenReturn(tr);
+ when(em.find(any(), any())).thenThrow(new RuntimeException("expected exception"));
+
+ new JpaDroolsSessionConnector(emf).get("xyz");
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testGet_FindEx_CloseEx() {
+ EntityManagerFactory emf = mock(EntityManagerFactory.class);
+ EntityManager em = mock(EntityManager.class);
+ EntityTransaction tr = mock(EntityTransaction.class);
+
+ when(emf.createEntityManager()).thenReturn(em);
+ when(em.getTransaction()).thenReturn(tr);
+ when(em.find(any(), any())).thenThrow(new RuntimeException("expected exception"));
+ doThrow(new RuntimeException("expected exception #2")).when(em).close();
+
+ new JpaDroolsSessionConnector(emf).get("xyz");
+ }
@Test
public void testReplace_Existing() {
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java
index 66261349..55d058f5 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java
@@ -25,6 +25,7 @@ import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.Slf4jRequestLog;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.security.Credential;
@@ -134,6 +135,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable
this.context.setContextPath(contextPath);
this.jettyServer = new Server();
+ this.jettyServer.setRequestLog(new Slf4jRequestLog());
this.connector = new ServerConnector(this.jettyServer);
this.connector.setName(name);
diff --git a/policy-management/src/main/server/config/logback.xml b/policy-management/src/main/server/config/logback.xml
index 53d73434..1801c43a 100644
--- a/policy-management/src/main/server/config/logback.xml
+++ b/policy-management/src/main/server/config/logback.xml
@@ -75,7 +75,7 @@
<appender name="NetworkOut" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logDir}/${networkLog}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>logs/network.log.%i.zip</fileNamePattern>
+ <fileNamePattern>${logDir}/${networkLog}.%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>9</maxIndex>
</rollingPolicy>
@@ -94,6 +94,10 @@
<logger name="network" level="INFO" additivity="false">
<appender-ref ref="AsyncNetworkOut" />
</logger>
+
+ <logger name="org.eclipse.jetty.server.RequestLog" level="info" additivity="false">
+ <appender-ref ref="AsyncNetworkOut" />
+ </logger>
<root level="INFO">
<appender-ref ref="AsyncDebugOut" />