import java.sql.*;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
public abstract class ConnWrapper<T, U> {
+ EELFLogger logger = EELFManager.getInstance().getLogger( ConnWrapper.class );
protected Connection c;
protected PreparedStatement ps;
protected ResultSet rs;
protected abstract T run(U u) throws Exception;
- public T protect(ConnectionFactory cf, U u) throws DBException {
+ public T protect(ConnectionFactory cf, U u) {
try {
try {
return(attempt(cf, u, false));
} catch (SQLException sqle) {
+ logger.error("Error", sqle);
return(attempt(cf, u, true));
}
} catch (RuntimeException rte) {
c = null;
return(ret);
} finally {
- if (rs != null) { try { rs.close(); } catch (Exception e) {}}
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (Exception e) {
+ logger.error("Error", e);
+ }}
rs = null;
- if (ps != null) { try { ps.close(); } catch (Exception e) {}}
+ if (ps != null) {
+ try {
+ ps.close();
+ } catch (Exception e) {
+ logger.error("Error", e);
+ }}
ps = null;
- if (c != null) { try { c.close(); } catch (Exception e) {}}
+ if (c != null) {
+ try {
+ c.close();
+ } catch (Exception e) {
+ logger.error("Error", e);
+ }}
c = null;
}
}
import java.sql.*;
import java.util.*;
-import org.apache.log4j.Logger;
-
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
import org.onap.dmaap.dbcapi.util.DmaapConfig;
public class ConnectionFactory {
return;
}
}
- try { c.close(); } catch (Exception e) {}
+ try {
+ c.close();
+ } catch (Exception e) {
+ logger.error("Error", e);
+ }
}
}
public DBMap(ConnectionFactory cf, Class<C> cls, String tabname, String keyfield) throws Exception {
super(cf, cls, tabname, keyfield);
}
- public void clear() throws UnsupportedOperationException {
+ public void clear() {
throw new UnsupportedOperationException();
}
- public boolean containsKey(Object key) throws DBException {
+ public boolean containsKey(Object key) {
return(get(key) != null);
}
- public boolean containsValue(Object value) throws UnsupportedOperationException {
+ public boolean containsValue(Object value) {
throw new UnsupportedOperationException();
}
public boolean isEmpty() {
return(false);
}
- public Set<Map.Entry<String, C>> entrySet() throws DBException {
+ public Set<Map.Entry<String, C>> entrySet() {
return(list());
}
- public Set<String> keySet() throws DBException {
- Set<String> ret = new HashSet<String>();
+ public Set<String> keySet() {
+ Set<String> ret = new HashSet<>();
for (Map.Entry<String, C> x: list()) {
ret.add(x.getKey());
}
return(ret);
}
- public void putAll(Map<? extends String, ? extends C> m) throws UnsupportedOperationException {
+ public void putAll(Map<? extends String, ? extends C> m) {
throw new UnsupportedOperationException();
}
public int size() {
return(2);
}
- public Collection<C> values() throws DBException {
- Collection<C> ret = new Vector<C>();
+ public Collection<C> values() {
+ Collection<C> ret = new Vector<>();
for (Map.Entry<String, C> x: list()) {
ret.add(x.getValue());
}
return(ret);
}
- public C get(Object key) throws DBException {
+ public C get(Object key) {
if (!(key instanceof String)) {
return(null);
}
}
}).protect(cf, (String)key));
}
- public Set<Map.Entry<String, C>> list() throws DBException {
+ public Set<Map.Entry<String, C>> list() {
return((new ConnWrapper<Set<Map.Entry<String, C>>, Object>() {
protected Set<Map.Entry<String, C>> run(Object junk) throws Exception {
DBFieldHandler keyfield = fields[fields.length - 1];
ps = c.prepareStatement(liststmt);
rs = ps.executeQuery();
- Set<Map.Entry<String, C>> ret = new HashSet<Map.Entry<String, C>>();
+ Set<Map.Entry<String, C>> ret = new HashSet<>();
while (rs.next()) {
C val = cls.newInstance();
for (DBFieldHandler f: fields) {
}
}).protect(cf, null));
}
- public C put(String key, C val) throws DBException {
+ public C put(String key, C val) {
try {
fields[fields.length - 1].setKey(val, key);
} catch (Exception e) {
}
}).protect(cf, val));
}
- public C remove(Object key) throws DBException {
+ public C remove(Object key) {
if (!(key instanceof String)) {
return(null);
}
super(cf, cls, tabname, null);
singleton = cls.newInstance();
}
- public C get() throws DBException {
+ public C get() {
return((new ConnWrapper<C, Object>() {
protected C run(Object junk) throws Exception {
ps = c.prepareStatement(getstmt);
}
}).protect(cf, null));
}
- public void init(C val) throws DBException {
+ public void init(C val) {
if (get() != null) {
return;
}
}
}).protect(cf, val);
}
- public void update(C val) throws DBException {
+ public void update(C val) {
(new ConnWrapper<Void, C>() {
protected Void run(C val) throws Exception {
ps = c.prepareStatement(insorreplstmt);
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
+import org.apache.log4j.Logger;
import org.onap.dmaap.dbcapi.authentication.AuthenticationErrorException;
import org.onap.dmaap.dbcapi.service.ApiService;
-import org.onap.dmaap.dbcapi.util.DmaapConfig;
@Authorization
public class AuthorizationFilter implements ContainerRequestFilter {
-
+ private Logger logger = Logger.getLogger(AuthorizationFilter.class.getName());
@Override
public void filter(ContainerRequestContext requestContext)
try {
apiResp.checkAuthorization();
} catch ( AuthenticationErrorException ae ) {
+ logger.error("Error", ae);
requestContext.abortWith( apiResp.unauthorized( apiResp.getErr().getMessage() ) );
return ;
} catch ( Exception e ) {
+ logger.error("Error", e);
requestContext.abortWith( apiResp.unavailable() );
return;
}