Skip to content

Commit

Permalink
replace printStackTrace calls with logger messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Apr 1, 2013
1 parent df8b211 commit 191dd1e
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 27 deletions.
@@ -1,12 +1,18 @@
package org.fcrepo.generator.dublincore;

import org.slf4j.Logger;

import javax.jcr.*;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import static org.slf4j.LoggerFactory.getLogger;

public class JcrPropertiesGenerator implements DCGenerator {

private static final Logger logger = getLogger(JcrPropertiesGenerator.class);

@Override
public InputStream getStream(Node node) {

Expand All @@ -32,14 +38,12 @@ public InputStream getStream(Node node) {

str += "</oai_dc:dc>";

try {
return new ByteArrayInputStream(str.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
return new ByteArrayInputStream(str.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
logger.warn("Exception rendering properties: {}", e);
return null;
} catch (RepositoryException e) {
e.printStackTrace();
logger.error("Repository exception: {}", e);
return null;
}
}
Expand Down
@@ -1,8 +1,11 @@

package org.fcrepo.generator.dublincore;

import org.slf4j.Logger;

import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.InputStream;

Expand All @@ -12,6 +15,8 @@

public class WellKnownDatastreamGenerator implements DCGenerator {

private static final Logger logger = getLogger(WellKnownDatastreamGenerator.class);

private String wellKnownDsid;

@Override
Expand All @@ -20,7 +25,8 @@ public InputStream getStream(final Node node) {
try {
return getContentInputStream(node);
} catch (RepositoryException e) {
e.printStackTrace();

logger.warn("logged exception", e);

return null;
}
Expand Down
@@ -1,20 +1,26 @@
package org.fcrepo.generator.dublincore;

import org.slf4j.Logger;

import javax.jcr.Node;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import static org.slf4j.LoggerFactory.getLogger;

public class WorstCaseGenerator implements DCGenerator {

private static final Logger logger = getLogger(WorstCaseGenerator.class);

@Override
public InputStream getStream(Node node) {
String str = "<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" ></oai_dc:dc>";

try {
return new ByteArrayInputStream(str.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
logger.warn("logged exception", e);
return null;
}
}
Expand Down
Expand Up @@ -7,6 +7,9 @@
import org.apache.velocity.app.VelocityEngine;
import org.fcrepo.jaxb.responses.access.DescribeRepository;
import org.fcrepo.jaxb.search.FieldSearchResult;
import org.slf4j.Logger;

import static org.slf4j.LoggerFactory.getLogger;

/**
* Resolves the view to be used
Expand All @@ -16,8 +19,11 @@
public class VelocityViewer {

private VelocityEngine velocityEngine;

public VelocityViewer() {

private static final Logger logger = getLogger(VelocityViewer.class);


public VelocityViewer() {
try
{
// Load the velocity properties from the class path
Expand All @@ -29,7 +35,7 @@ public VelocityViewer() {
}
catch( Exception e )
{
e.printStackTrace();
logger.warn("Exception rendering Velocity template: {}", e);
}
}

Expand All @@ -48,7 +54,7 @@ public String getRepoInfo(DescribeRepository repoinfo) {
}
catch( Exception e )
{
e.printStackTrace();
logger.warn("Exception rendering Velocity template: {}", e);
}
return null;
}
Expand All @@ -68,7 +74,7 @@ public String getFieldSearch(FieldSearchResult results) {
}
catch( Exception e )
{
e.printStackTrace();
logger.warn("Exception rendering Velocity template: {}", e);
}
return null;
}
Expand Down
Expand Up @@ -6,6 +6,7 @@
import static javax.jcr.observation.Event.PROPERTY_ADDED;
import static javax.jcr.observation.Event.PROPERTY_CHANGED;
import static javax.jcr.observation.Event.PROPERTY_REMOVED;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.IOException;
import java.io.StringReader;
Expand All @@ -30,6 +31,7 @@
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.slf4j.Logger;

public class LegacyMethod {

Expand Down Expand Up @@ -64,6 +66,8 @@ public class LegacyMethod {

private final static List<String> METHOD_NAMES = Arrays.asList(METHODS);

private static final Logger logger = getLogger(LegacyMethod.class);

static {
try {
FEDORA_TYPES
Expand Down Expand Up @@ -293,7 +297,7 @@ public static boolean canParse(Message jmsMessage) {
METHOD_NAMES.contains(jmsMessage
.getStringProperty("methodName"));
} catch (JMSException e) {
e.printStackTrace();
logger.info("Could not parse message: {}", jmsMessage);
return false;
}
}
Expand Down
Expand Up @@ -75,12 +75,16 @@ public void testAtomStream() throws LoginException, RepositoryException {
session.getRootNode().addNode("test1").addMixin(FEDORA_OBJECT);
session.save();
session.logout();
while (entry == null)

// we're relying on the onMessage handler to populate entry
while (entry == null) {
try {
Thread.sleep(1000);
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

List<Category> categories = copyOf(entry.getCategories("xsd:string"));
final String title = entry.getTitle();
entry = null;
Expand All @@ -107,12 +111,15 @@ public void testDatastreamTerm() throws NoSuchNodeTypeException,
ds.addNode(JCR_CONTENT).setProperty(JCR_DATA, "fake data");
session.save();
session.logout();
while (entry == null)

// we're relying on the onMessage handler to populate entry
while (entry == null) {
try {
Thread.sleep(1000);
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
List<Category> categories = copyOf(entry.getCategories("xsd:string"));
entry = null;
String path = null;
Expand Down Expand Up @@ -145,7 +152,7 @@ public void onMessage(Message message) {
logger.warn("Could not parse message: {}", message);
}
} catch (Exception e) {
e.printStackTrace();
logger.error("Exception receiving message: {}", e);
fail(e.getMessage());
}

Expand Down
Expand Up @@ -100,7 +100,7 @@ public FixityResult transformEntry(LowLevelCacheEntry entry,
try {
result = entry.checkFixity(dsChecksum, dsSize, digest);
} catch (BinaryStoreException e) {
e.printStackTrace();
logger.error("Exception checking low-level fixity: {}", e);
throw new IllegalStateException(e);
}
return result;
Expand Down Expand Up @@ -299,7 +299,7 @@ public boolean apply(FixityResult result) {
fixityErrorCounter.inc();
}
} catch (IOException e) {
e.printStackTrace();
logger.warn("Exception repairing low-level cache entry: {}", e);
}
}

Expand Down
Expand Up @@ -2,15 +2,19 @@
package org.fcrepo.utils;

import static org.apache.commons.codec.binary.Hex.encodeHexString;
import static org.slf4j.LoggerFactory.getLogger;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;

import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;

public class ContentDigest {

private static final Logger logger = getLogger(ContentDigest.class);

public static final Map<String, String> algorithmToScheme = ImmutableMap
.of("SHA-1", "urn:sha1","SHA1", "urn:sha1");

Expand All @@ -19,8 +23,8 @@ public static URI asURI(String algorithm, String value) {
String scheme = algorithmToScheme.get(algorithm);

return new URI(scheme, value, null);
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (URISyntaxException unlikelyException) {
logger.warn("Exception creating checksum URI: {}", unlikelyException);
return null;
}
}
Expand Down
Expand Up @@ -164,7 +164,7 @@ public FixityResult checkFixity(URI checksum, long size,
logger.debug("Got " + result.toString());
ds.close();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
logger.warn("Could not clone MessageDigest: {}", e);
} catch (IOException e) {
throw new IllegalStateException(e);
}
Expand Down
Expand Up @@ -157,13 +157,14 @@ public Response registerWebhook(@PathParam("id") final String id) throws Reposit


@Subscribe
public void newEvent(FedoraEvent event) {
public void onEvent(FedoraEvent event) {
try {
logger.debug("Webhooks received event: {}", event);
final Node resource = jcrTools.findOrCreateNode(readOnlySession, event.getPath());

runHooks(resource, event);
} catch (RepositoryException e) {
e.printStackTrace();
logger.error("Got a repository exception handling message: {}", e);
}
}

Expand Down

0 comments on commit 191dd1e

Please sign in to comment.