aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordterry2013-10-04 11:07:26 (EDT)
committerdterry2013-10-22 13:15:43 (EDT)
commit48e5c48d7720a12238d805cb918adf7df68d7125 (patch)
treebb4ca76db8a5da0d0ec8d80ad572077d04f9b18e
parent7dd75ce525bdbf802dbfa313c931a823e0adce30 (diff)
downloadorg.eclipse.lyo.rio-48e5c48d7720a12238d805cb918adf7df68d7125.zip
org.eclipse.lyo.rio-48e5c48d7720a12238d805cb918adf7df68d7125.tar.gz
org.eclipse.lyo.rio-48e5c48d7720a12238d805cb918adf7df68d7125.tar.bz2
Bug 418682 - Add log4j logging to the TRS reference applicationrefs/changes/28/17128/5
Change-Id: I6659356f2d162614f890f2328a37bc6cc92582f8 Signed-off-by: dterry <dgterry@us.ibm.com>
-rw-r--r--org.eclipse.lyo.rio.trs/pom.xml1
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/log4j.properties24
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/Persistence.java79
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/PersistenceResourceUtil.java6
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/BaseResource.java8
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java44
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java22
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/BaseGeneric.java9
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java14
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java14
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ConfigUtil.java12
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/FileUtil.java19
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java37
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java42
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtil.java26
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/resources/Messages.properties15
-rw-r--r--org.eclipse.lyo.rio.trs/src/main/resources/log4j.properties31
17 files changed, 303 insertions, 100 deletions
diff --git a/org.eclipse.lyo.rio.trs/pom.xml b/org.eclipse.lyo.rio.trs/pom.xml
index 951de08..e44922b 100644
--- a/org.eclipse.lyo.rio.trs/pom.xml
+++ b/org.eclipse.lyo.rio.trs/pom.xml
@@ -11,7 +11,6 @@
<artifactId>org.eclipse.lyo.rio.trs</artifactId>
<description>Reference Application demonstrating a Tracked Resource Set integration utilizing the TRS toolkit.</description>
<packaging>war</packaging>
-
<dependencies>
<dependency>
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/log4j.properties b/org.eclipse.lyo.rio.trs/src/main/java/log4j.properties
deleted file mode 100644
index 2b04c9f..0000000
--- a/org.eclipse.lyo.rio.trs/src/main/java/log4j.properties
+++ /dev/null
@@ -1,24 +0,0 @@
-###############################################################################
-#
-# Licensed Materials - Use restricted, please refer to the "Samples Gallery" terms and conditions in the IBM International Program License Agreement (IPLA).
-# Copyright IBM Corporation 2012. All Rights Reserved.
-# U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
-#
-###############################################################################
-# Root logger option
-log4j.rootLogger=INFO, stdout, fileappender
-
-# Direct log messages to stdout
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Target=System.out
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
-
-log4j.appender.fileappender=org.apache.log4j.RollingFileAppender
-log4j.appender.fileappender.File=${catalina.base}/logs/hpqm.log
-log4j.appender.fileappender.layout=org.apache.log4j.PatternLayout
-log4j.appender.fileappender.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
-
-log4j.logger.org.apache.wink.common = DEBUG, stdout, fileappender
-log4j.logger.org.apache.wink.server = DEBUG, stdout, fileappender
-log4j.logger.com.ibm.jlip.sdk = DEBUG, stdout, fileappender \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/Persistence.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/Persistence.java
index 7c3043c..e006d42 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/Persistence.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/Persistence.java
@@ -24,15 +24,17 @@ import java.io.FileOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.text.MessageFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.ResourceBundle;
import java.util.Set;
import java.util.TreeMap;
-import javax.ws.rs.WebApplicationException;
import javax.xml.datatype.DatatypeConfigurationException;
+import org.apache.log4j.Logger;
import org.eclipse.lyo.core.utils.marshallers.OSLC4JContext;
import org.eclipse.lyo.core.utils.marshallers.OSLC4JMarshaller;
import org.eclipse.lyo.oslc4j.core.exception.OslcCoreApplicationException;
@@ -50,6 +52,8 @@ public class Persistence {
public static int PAGE_SIZE = 3;
private static Set<ChangeRequestListener> listeners = new HashSet<ChangeRequestListener>();
+ private static final Logger logger = Logger.getLogger(Persistence.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
private Persistence() {
super();
@@ -61,7 +65,8 @@ public class Persistence {
InstantiationException, InvocationTargetException,
OslcCoreApplicationException, URISyntaxException,
SecurityException, NoSuchMethodException {
-
+ logger.debug("Entering fileload method in Persistence.java class. Param1: " + fileName);
+
final File file = new File(fileName);
if ((file.exists()) && (file.isFile()) && (file.canRead())) {
@@ -96,28 +101,29 @@ public class Persistence {
}
}
}
-
+ logger.debug("Exiting fileload method in Persistence.java class. Return: true");
return true;
}
else {
//ChangeRequestResource
}
+ logger.debug("Exiting fileload method in Persistence.java class. Return: false");
return false;
}
private static void save(final String fileName) {
+ logger.debug("Entering save method in Persistence.java class. Param1: " + fileName);
final ChangeRequest[] changeRequests = getAllChangeRequests();
OSLC4JContext context = OSLC4JContext.newInstance();
OSLC4JMarshaller marshaller = context.createMarshaller();
try {
marshaller.marshal(changeRequests, new FileOutputStream(fileName));
- } catch (WebApplicationException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
+ } catch (Exception e) {
+ logger.error(MessageFormat.format(bundle.getString("SAVE_FAILED"), fileName), e);
}
+ logger.debug("Exiting fileload method in Persistence.java class.");
}
public static long getNextIdentifier() {
@@ -138,6 +144,8 @@ public class Persistence {
public static ChangeRequest[] getChangeRequests(final int page) {
synchronized (CHANGE_REQUESTS_MAP) {
+ logger.debug("Entering getChangeRequests method in Persistence class. Param1: " + page);
+
int startIndex = page * PAGE_SIZE;
int total = getTotalChangeRequests();
int numResults = PAGE_SIZE;
@@ -152,41 +160,30 @@ public class Persistence {
ret = new ChangeRequest[numResults];
System.arraycopy(requests, startIndex, ret, 0, numResults);
}
+
+ logger.debug("Exiting getChangeRequests method in Persistence class");
return ret;
}
}
public static void initialize() {
+ logger.debug("Entering initialize method in Persistence class");
+
try {
fileload(ConfigUtil.getPropertiesInstance().getProperty("ChangeRequestsFile"));
CHANGE_REQUESTS_LOADED = true;
-
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (SecurityException e) {
- e.printStackTrace();
- } catch (DatatypeConfigurationException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InstantiationException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
- } catch (OslcCoreApplicationException e) {
- e.printStackTrace();
- } catch (URISyntaxException e) {
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- e.printStackTrace();
+ } catch (Exception e) {
+ logger.error(bundle.getString("INITIALIZATION_FAILURE"));
}
+
+ logger.debug("Exiting initialize method in Persistence class");
}
public static ChangeRequest[] getAllChangeRequests() {
synchronized (CHANGE_REQUESTS_MAP) {
+ logger.debug("Entering getAllChangeRequests method in Persistence class.");
+
ChangeRequest[] ret = null;
if(CHANGE_REQUESTS_MAP.size() == 0 && !CHANGE_REQUESTS_LOADED){
@@ -202,15 +199,20 @@ public class Persistence {
ret = new ChangeRequest[CHANGE_REQUESTS_MAP.size()];
System.arraycopy(requests, 0, ret, 0, CHANGE_REQUESTS_MAP.size());
}
+
+ logger.debug("Exiting getAllChangeRequests method in Persistence class.");
return ret;
}
}
public static ChangeRequest getChangeRequest(final String identifier) {
synchronized (CHANGE_REQUESTS_MAP) {
+ logger.debug("Entering getChangeRequest method in Persistence class. Param1: " + identifier);
+
if (!CHANGE_REQUESTS_LOADED)
initialize();
+ logger.debug("Exiting getChangeRequest method in Persistence class.");
return CHANGE_REQUESTS_MAP.get(Long.valueOf(identifier));
}
}
@@ -218,6 +220,8 @@ public class Persistence {
public static ChangeRequest createChangeRequest(final String description,
final String title, final String filedAgainst)
throws URISyntaxException {
+ logger.debug("Entering createChangeRequest method in Persistence class. Param1: " + description + " Param2: " + title + " Param3: " + filedAgainst);
+
final ChangeRequest changeRequest = new ChangeRequest();
changeRequest.setApproved(Boolean.FALSE);
@@ -233,11 +237,14 @@ public class Persistence {
changeRequest.setTitle(title);
changeRequest.setVerified(Boolean.FALSE);
+ logger.debug("Exiting createChangeRequest method in Persistence class.");
return changeRequest;
}
public static ChangeRequest persistChangeRequest(final URI basePath,
final ChangeRequest changeRequest) throws URISyntaxException {
+ logger.debug("Entering persistChangeRequest method in Persistence class. Param1: " + basePath.toString());
+
final long identifier = Persistence.getNextIdentifier();
final URI about = basePath.resolve("./changeRequests/" + identifier);
@@ -253,11 +260,14 @@ public class Persistence {
Persistence.addChangeRequest(changeRequest);
+ logger.debug("Exiting persistChangeRequests method in Persistence class.");
return changeRequest;
}
private static void addChangeRequest(final ChangeRequest changeRequest) {
synchronized (CHANGE_REQUESTS_MAP) {
+ logger.debug("Entering addChangeRequest method in Persistence class.");
+
CHANGE_REQUESTS_MAP.put(
Long.valueOf(changeRequest.getIdentifier()), changeRequest);
@@ -266,11 +276,15 @@ public class Persistence {
// Notify any listeners of creation event
notifyListeners(changeRequest, "create");
+
+ logger.debug("Exiting addChangeRequest method in Persistence class.");
}
}
public static ChangeRequest updateChangeRequest(final String identifier,
final ChangeRequest changeRequest) {
+ logger.debug("Entering updateChangeRequest method in Persistence class. Param1: " + identifier);
+
final Long longIdentifier = Long.valueOf(identifier);
synchronized (CHANGE_REQUESTS_MAP) {
@@ -286,15 +300,19 @@ public class Persistence {
// Notify any listeners of the update event
notifyListeners(changeRequest, "update");
+ logger.debug("Exiting updateChangeRequest method in Persistence class.");
return changeRequest;
}
}
+ logger.debug("Exiting updateChangeRequest method in Persistence class. Return is null");
return null;
}
public static ChangeRequest deleteChangeRequest(final String identifier) {
synchronized (CHANGE_REQUESTS_MAP) {
+ logger.debug("Entering deleteChangeRequest method in Persistence class. Param1: " + identifier);
+
ChangeRequest result = CHANGE_REQUESTS_MAP.remove(Long.valueOf(identifier));
// this means we successfully removed something with the given identifier
@@ -306,6 +324,7 @@ public class Persistence {
notifyListeners(result, "delete");
}
+ logger.debug("Exiting deleteChangeRequest method in Persistence class.");
return result;
}
}
@@ -319,10 +338,14 @@ public class Persistence {
}
private static void notifyListeners(ChangeRequest changeRequest, String type) {
+ logger.debug("Entering notifyListeners method in Persistence class. Param2: " + type);
+
Iterator<ChangeRequestListener> iter = listeners.iterator();
while (iter.hasNext()) {
iter.next().changeRequestAltered(changeRequest, type);
}
+
+ logger.debug("Exiting notifyListener method in Persistence class.");
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/PersistenceResourceUtil.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/PersistenceResourceUtil.java
index 1c3924d..60554fe 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/PersistenceResourceUtil.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/cm/PersistenceResourceUtil.java
@@ -19,16 +19,21 @@ package org.eclipse.lyo.rio.trs.cm;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
+import java.util.ResourceBundle;
+import org.apache.log4j.Logger;
import org.eclipse.lyo.rio.trs.util.IResourceUtil;
public final class PersistenceResourceUtil
implements IResourceUtil
{
public static PersistenceResourceUtil instance = new PersistenceResourceUtil();
+ private static final Logger logger = Logger.getLogger(PersistenceResourceUtil.class);
@Override
public List<URI> getAllResourceURIs() {
+ logger.debug("Entering getAllResourceURIs method in PersistenceResourceUtil class");
+
List<URI> uris = new ArrayList<URI>();
ChangeRequest[] allChangeRequests = Persistence.getAllChangeRequests();
@@ -37,6 +42,7 @@ public final class PersistenceResourceUtil
uris.add(currentRequest.getAbout());
}
+ logger.debug("Exiting getAllResourceURIs method in PersistenceResourceUtil class");
return uris;
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/BaseResource.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/BaseResource.java
index fb41b40..a60aca5 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/BaseResource.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/BaseResource.java
@@ -31,6 +31,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
+import org.apache.log4j.Logger;
import org.apache.wink.common.annotations.Workspace;
import org.eclipse.lyo.core.trs.Base;
import org.eclipse.lyo.core.trs.Page;
@@ -71,6 +72,8 @@ public class BaseResource {
@Context
protected UriInfo uriInfo;
+ private static final Logger logger = Logger.getLogger(BaseResource.class);
+
/**
* getBase() on the root URI performs a redirect to page 1 in this implementation to represent
* paged Base resources of the Tracked Resource Set
@@ -78,6 +81,7 @@ public class BaseResource {
@GET
@Produces({ OslcMediaType.TEXT_TURTLE, OslcMediaType.APPLICATION_RDF_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Page getBase() throws URISyntaxException{
+ logger.debug("Entering getBase method in BaseResource class");
URI requestURI = uriInfo.getRequestUri();
boolean endsWithSlash = requestURI.getPath().endsWith("/");
@@ -88,6 +92,7 @@ public class BaseResource {
redirectUrl = redirectUrl + "?" + requestURI.getQuery();
}
+ logger.debug("Exiting getBase method in BaseResource class. Redirecting to: " + redirectUrl);
throw new WebApplicationException(Response.temporaryRedirect(requestURI.resolve(redirectUrl)).build());
}
@@ -99,6 +104,8 @@ public class BaseResource {
@Path("{page}")
@Produces({ OslcMediaType.TEXT_TURTLE, OslcMediaType.APPLICATION_RDF_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Page getBasePage(@PathParam("page")Long page) throws URISyntaxException{
+ logger.debug("Entering getBasePage method in BaseResource class. Param1: " + page);
+
init();
// from uri find out which Inner container to access...
@@ -125,6 +132,7 @@ public class BaseResource {
// output if we return Page. If we force a reference from Base to Page
// instead then we get a ldp:nextPage entry which does not conform to the
// TRS 2.0 specification.
+ logger.debug("Exiting getBasePage method in BaseResource class");
return nextPage;
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java
index 6eb50a4..0507634 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/ChangeRequestResource.java
@@ -21,8 +21,10 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
+import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.ResourceBundle;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
@@ -48,6 +50,7 @@ import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
+import org.apache.log4j.Logger;
import org.apache.wink.common.annotations.Workspace;
import org.eclipse.lyo.core.trs.TRSConstants;
import org.eclipse.lyo.oslc4j.core.annotation.OslcCreationFactory;
@@ -72,6 +75,9 @@ public class ChangeRequestResource
@Context ServletContext servletContext;
private static String URN_PREFIX = "urn:urn-3:cm1.example.com:";
+ private static final Logger logger = Logger.getLogger(ChangeRequestResource.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
+
// Handle the HTML request from browser.
@POST
@Path("creator")
@@ -80,6 +86,7 @@ public class ChangeRequestResource
@FormParam ("description") String description,
@FormParam ("filedAgainst") String filedAgainst)
{
+ logger.debug("Entering createHtmlChangeRequest method in ChangeRequestResource class. Param1: " + title + " Param2: " + description + " Param3: " + filedAgainst);
try {
URI baseURI = uriInfo.getBaseUri();
@@ -105,10 +112,10 @@ public class ChangeRequestResource
out.close();
} catch (Exception e) {
- e.printStackTrace();
+ logger.error(bundle.getObject("FAILED_TO_CREATE_CR"), e);
throw new WebApplicationException(e);
}
-
+ logger.debug("Exiting createHtmlChangeRequest method in ChangeRequestResource class");
}
@PUT
@@ -118,6 +125,7 @@ public class ChangeRequestResource
@PathParam("changeRequestId") final String changeRequestId,
final ChangeRequest changeRequest)
{
+ logger.error("Entering updateChangeRequest method in ChangeRequestResource class. Param1: " + eTagHeader + " Param2: " + changeRequestId);
final ChangeRequest originalChangeRequest = Persistence.getChangeRequest(changeRequestId);
if (originalChangeRequest != null)
@@ -148,7 +156,7 @@ public class ChangeRequestResource
"\"ID\" : \"" + changeRequest.getIdentifier() + "\"}");
out.close();
} catch (IOException e) {
- e.printStackTrace();
+ logger.debug("Change request was updated but failed to update UI with status information.", e);
}
}
else
@@ -160,6 +168,7 @@ public class ChangeRequestResource
{
throw new WebApplicationException(Status.NOT_FOUND);
}
+ logger.debug("Exiting updateChangeRequest method in ChangeRequestResource class");
}
@@ -207,7 +216,8 @@ public class ChangeRequestResource
@Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON})
public ResponseInfoArray<ChangeRequest> getChangeRequests(@QueryParam("oslc.where") final String where, @QueryParam("pageNo")final int pageNo, @Context HttpServletRequest request)
{
-
+ logger.debug("Entering getChangeRequests method in ChangeRequestResource class. Param1: " + where + " Param2: " + pageNo);
+
int totalResults = Persistence.getTotalChangeRequests();
final ChangeRequest[] changeRequests = Persistence.getChangeRequests(pageNo);
URI nextPage = null;
@@ -217,6 +227,7 @@ public class ChangeRequestResource
nextPage = UriBuilder.fromUri(requestURI).replaceQueryParam("pageNo", pageNo+1).build(new Object[0]);
}
+ logger.debug("Exiting getChangeRequest method in ChangeRequestResource class");
return new ResponseInfoArray<ChangeRequest>(changeRequests,
null,
totalResults,
@@ -227,6 +238,7 @@ public class ChangeRequestResource
@Produces({ MediaType.TEXT_HTML })
public void getHtmlCollection(@QueryParam("pageNo")final int pageNo) throws ServletException, IOException
{
+ logger.debug("Entering getHtmlCollection method in ChangeRequestResource class. Param1: " + pageNo);
try
{
int totalResults = Persistence.getTotalChangeRequests();
@@ -247,9 +259,11 @@ public class ChangeRequestResource
httpServletRequest.setAttribute("results", results);
+ logger.debug("Exiting getHtmlCollection method in ChangeRequestResource class");
RequestDispatcher rd = httpServletRequest.getRequestDispatcher("/changerequest_collection_html.jsp");
rd.forward(httpServletRequest, httpServletResponse);
}catch (Exception e) {
+ logger.error(MessageFormat.format(bundle.getString("NO_SUCH_RESOURCE"), pageNo), e);
throw new WebApplicationException(Status.NOT_FOUND);
}
}
@@ -259,6 +273,8 @@ public class ChangeRequestResource
@Produces({OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_XML, OslcMediaType.APPLICATION_JSON})
public Response getChangeRequest(@PathParam("changeRequestId") final String changeRequestId)
{
+ logger.debug("Entering getChangeRequest method in ChangeRequestResource class. Param1: " + changeRequestId);
+
final ChangeRequest changeRequest = Persistence.getChangeRequest(changeRequestId);
if (changeRequest != null)
@@ -268,9 +284,11 @@ public class ChangeRequestResource
String eTag = getETagFromChangeRequest(changeRequest);
Response response = Response.ok(changeRequest).header("ETag", eTag).build();
+ logger.debug("Exiting getChangeRequeswt method in ChangeRequestResource class.");
return response;
}
+ logger.error(MessageFormat.format(bundle.getString("NO_SUCH_RESOURCE"), changeRequestId));
throw new WebApplicationException(Status.NOT_FOUND);
}
@@ -287,6 +305,7 @@ public class ChangeRequestResource
rd.forward(httpServletRequest, httpServletResponse);
}
catch (Exception e) {
+ logger.error(MessageFormat.format(bundle.getString("MODIFICATION_FAILURE"), changeRequestId), e);
throw new WebApplicationException(e);
}
}
@@ -305,6 +324,8 @@ public class ChangeRequestResource
public Response addChangeRequest(ChangeRequest changeRequest)
throws URISyntaxException
{
+ logger.debug("Entering addChangeRequest method in ChangeRequestResource class");
+
URI basePath = uriInfo.getBaseUri();
@@ -317,7 +338,8 @@ public class ChangeRequestResource
changeRequest = Persistence.persistChangeRequest(basePath, changeRequest);
String eTag = getETagFromChangeRequest(changeRequest);
-
+
+ logger.debug("Exiting addChangeRequest method in ChangeRequestResource class");
return Response.created(changeRequest.getAbout()).entity(changeRequest).header("ETag", eTag).build();
}
@@ -325,6 +347,8 @@ public class ChangeRequestResource
@Path("{changeRequestId}")
public Response deleteChangeRequest(@PathParam("changeRequestId") final String changeRequestId)
{
+ logger.debug("Entering deleteChangeRequest method in ChangeRequestResource class. Param1: " + changeRequestId);
+
URI baseURI = uriInfo.getBaseUri();
// Initialize the base before adding / deleting any resource.
TRSUtil.initialize(PersistenceResourceUtil.instance, baseURI);
@@ -336,10 +360,12 @@ public class ChangeRequestResource
// TRS - Insert the deletion event to the change log
TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_DELETION, changeRequest.getAbout(), getCurrentTimeStampURN());
+ logger.debug("Exiting deleteChangeRequest method in ChangeRequestResource class");
return Response.ok().build();
}
-
+
+ logger.error(MessageFormat.format(bundle.getString("DELETION_FAILURE"), changeRequestId));
throw new WebApplicationException(Status.NOT_FOUND);
}
@@ -354,6 +380,8 @@ public class ChangeRequestResource
public String populate()
throws URISyntaxException
{
+ logger.debug("Entering populate method in ChangeRequestResource class");
+
URI baseURI = uriInfo.getBaseUri();
// Initialize the base before adding / deleting any resource.
@@ -396,6 +424,7 @@ public class ChangeRequestResource
"Donec sit amet felis purus.", "Client"));
TRSUtil.insertEventTypeToChangeLog(TRSConstants.TRS_TYPE_CREATION, changeRequest.getAbout(), getCurrentTimeStampURN());
+ logger.debug("Exiting populate method in ChangeRequestResource class");
return "Success!";
}
@@ -420,6 +449,7 @@ public class ChangeRequestResource
rd.forward(httpServletRequest, httpServletResponse);
} catch (Exception e) {
+ logger.error(bundle.getString("FAILED_TO_CREATE_CR"));
throw new WebApplicationException(e);
}
}
@@ -436,7 +466,7 @@ public class ChangeRequestResource
try {
timestampURI = new URI(URN_PREFIX + getCurrentTimeStamp());
} catch (URISyntaxException e) {
- e.printStackTrace();
+ logger.debug("Unable to construct URN for the new change event.");
}
return timestampURI;
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java
index bbe1772..b13c0c8 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/resources/TRSResource.java
@@ -21,6 +21,8 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
import java.net.URISyntaxException;
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -37,6 +39,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
+import org.apache.log4j.Logger;
import org.apache.wink.common.annotations.Workspace;
import org.eclipse.lyo.core.trs.AbstractChangeLog;
import org.eclipse.lyo.core.trs.ChangeEvent;
@@ -82,6 +85,9 @@ public class TRSResource {
@Context private HttpServletResponse httpServletResponse;
@Context private HttpServletRequest httpServletRequest;
+ private static final Logger logger = Logger.getLogger(TRSResource.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
+
/**
* getTrackedResourceSet() returns the Tracked Resource Set with the most recent
* page of the Change Log or EmptyChangeLog if no change logs pages exist
@@ -90,6 +96,8 @@ public class TRSResource {
@GET
@Produces({ OslcMediaType.TEXT_TURTLE, OslcMediaType.APPLICATION_RDF_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public TrackedResourceSet getTrackedResourceSet() throws URISyntaxException, IOException{
+ logger.debug("Entering getTrackedResourceSet method in TRSResource class");
+
init();
URI requestURI = uriInfo.getRequestUri();
@@ -109,6 +117,7 @@ public class TRSResource {
set.setChangeLog(changeLog);
+ logger.debug("Exiting getChangeLog method in TRSResource class");
return set;
}
@@ -120,6 +129,8 @@ public class TRSResource {
@Path("changelog")
@Produces({ OslcMediaType.TEXT_TURTLE, OslcMediaType.APPLICATION_RDF_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public AbstractChangeLog getChangeLog() throws URISyntaxException, IOException{
+ logger.debug("Entering getChangeLog method in TRSResource class");
+
init();
URI requestURI = uriInfo.getRequestUri();
@@ -127,7 +138,8 @@ public class TRSResource {
TRSObject trsObject = TRSUtil.getTrsObject(PersistenceResourceUtil.instance, requestURI);
AbstractChangeLog changeLog = trsObject.getCurrentChangeLog();
-
+
+ logger.debug("Exiting getChangeLog method in TRSResource class");
return changeLog;
}
@@ -140,6 +152,8 @@ public class TRSResource {
@Path("changelog/{page}")
@Produces({ OslcMediaType.TEXT_TURTLE, OslcMediaType.APPLICATION_RDF_XML, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public AbstractChangeLog getChangeLogPage(@PathParam("page") final Long page) throws URISyntaxException, IOException{
+ logger.debug("Entering getChangeLogPage method in TRSResource class. Param1: " + page);
+
init();
URI requestURI = uriInfo.getRequestUri();
@@ -150,6 +164,7 @@ public class TRSResource {
if (changeLog == null)
throw new WebApplicationException(Status.NOT_FOUND);
+ logger.debug("Exiting getChangeLogPage method in TRSResource class");
return changeLog;
}
@@ -159,6 +174,7 @@ public class TRSResource {
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED})
public void modifyCutOffEventhtml ( @FormParam ("event") String event )
{
+ logger.debug("Entering modifyCutOffEventhtml in TRSResource class. Param1: " + event);
try {
ChangeEvent ce = TRSUtil.getChangeEvent((event));
@@ -173,12 +189,12 @@ public class TRSResource {
PrintWriter out = httpServletResponse.getWriter();
out.print("{\"event\": \"" + event + "\"}");
out.close();
-
} catch (Exception e) {
- e.printStackTrace();
+ logger.error(MessageFormat.format(bundle.getString("MODIFY_CUTOFF_FAILURE"), event), e);
throw new WebApplicationException(e);
}
+ logger.debug("Exiting modifyCutOffEventhtml method in TRSResource class");
}
private void init() {
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/BaseGeneric.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/BaseGeneric.java
index 1e6c1ce..3ac2958 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/BaseGeneric.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/BaseGeneric.java
@@ -22,6 +22,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
+import java.util.ResourceBundle;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
@@ -32,6 +33,7 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
+import org.apache.log4j.Logger;
import org.eclipse.lyo.core.trs.Base;
import org.eclipse.lyo.core.trs.Page;
import org.eclipse.lyo.core.utils.marshallers.OSLC4JContext;
@@ -71,11 +73,15 @@ import org.eclipse.lyo.rio.trs.util.TRSUtil;
@SuppressWarnings("serial")
public class BaseGeneric extends HttpServlet {
+ private static final Logger logger = Logger.getLogger(BaseGeneric.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
public BaseGeneric() {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ logger.debug("Entering doGet method in BaseGeneric class");
+
String responseType = ResponseUtil.parseAcceptType(request);
response.setContentType(responseType);
@@ -141,7 +147,7 @@ public class BaseGeneric extends HttpServlet {
oArray = results.toArray();
marshaller.marshal(oArray, outputStream);
} catch (URISyntaxException e) {
- e.printStackTrace();
+ logger.error(bundle.getString("UNABLE_TO_CONSTRUCT_URI"), e);
}
}
@@ -151,5 +157,6 @@ public class BaseGeneric extends HttpServlet {
// redirects it to first page.
response.sendRedirect(request.getRequestURL().toString() + "/1");
}
+ logger.debug("Exiting doGet method in BaseGeneric class");
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java
index e952b05..af6ec3f 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/ChangeLogGeneric.java
@@ -19,6 +19,7 @@ package org.eclipse.lyo.rio.trs.servlet;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ResourceBundle;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
@@ -29,6 +30,7 @@ import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
+import org.apache.log4j.Logger;
import org.eclipse.lyo.core.trs.AbstractChangeLog;
import org.eclipse.lyo.core.utils.marshallers.OSLC4JContext;
import org.eclipse.lyo.core.utils.marshallers.OSLC4JMarshaller;
@@ -45,11 +47,15 @@ import org.eclipse.lyo.rio.trs.util.TRSUtil;
*/
@SuppressWarnings("serial")
public class ChangeLogGeneric extends HttpServlet {
+ private static final Logger logger = Logger.getLogger(ChangeLogGeneric.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
public ChangeLogGeneric() {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ logger.debug("Entering doGet method in ChangeLogGeneric class");
+
String responseType = ResponseUtil.parseAcceptType(request);
response.setContentType(responseType);
@@ -73,8 +79,10 @@ public class ChangeLogGeneric extends HttpServlet {
}
changeLog = trsObject.getChangeLogPage(page);
- if (changeLog == null)
+ if (changeLog == null) {
+ logger.error(bundle.getString("NO_CHANGE_LOG"));
throw new WebApplicationException(Status.NOT_FOUND);
+ }
}
else
{
@@ -94,7 +102,9 @@ public class ChangeLogGeneric extends HttpServlet {
oArray[0] = changeLog;
marshaller.marshal(oArray, outputStream);
} catch (URISyntaxException e) {
- e.printStackTrace();
+ logger.error(bundle.getString("UNABLE_TO_CONSTRUCT_URI"), e);
}
+
+ logger.debug("Exiting doGet method in ChangeLogGeneric class");
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java
index f1468ed..1888a49 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/servlet/TRSGeneric.java
@@ -20,6 +20,7 @@ package org.eclipse.lyo.rio.trs.servlet;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ResourceBundle;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
@@ -28,6 +29,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.core.MediaType;
+import org.apache.log4j.Logger;
import org.eclipse.lyo.core.trs.AbstractChangeLog;
import org.eclipse.lyo.core.trs.TRSConstants;
import org.eclipse.lyo.core.trs.TrackedResourceSet;
@@ -66,12 +68,16 @@ import org.eclipse.lyo.rio.trs.util.TRSUtil;
// The servlet class to handle request for /restx/trs/*. Implementation TRS through Servlet.
@SuppressWarnings("serial")
public class TRSGeneric extends HttpServlet {
+ private static final Logger logger = Logger.getLogger(TRSGeneric.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
public TRSGeneric() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ logger.debug("Entering doGet method in TRSGeneric class");
+
String responseType = ResponseUtil.parseAcceptType(request);
response.setContentType(responseType);
@@ -83,8 +89,7 @@ public class TRSGeneric extends HttpServlet {
requestURI = new URI(request.getRequestURL().toString());
set.setAbout(requestURI);
} catch (URISyntaxException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.warn(bundle.getString("UNABLE_TO_CONSTRUCT_URI"), e);
}
// Now set the uri for obtaining the Base of the Tracked Resource Set
@@ -110,8 +115,9 @@ public class TRSGeneric extends HttpServlet {
oArray[0] = set;
marshaller.marshal(oArray, outputStream);
} catch (URISyntaxException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.warn(bundle.getString("UNABLE_TO_CONSTRUCT_URI"), e);
}
+
+ logger.debug("Exiting doGet method in TRSGeneric class");
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ConfigUtil.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ConfigUtil.java
index d31c089..dc9a98f 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ConfigUtil.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ConfigUtil.java
@@ -18,10 +18,16 @@ package org.eclipse.lyo.rio.trs.util;
import java.io.IOException;
import java.util.Properties;
+import java.util.ResourceBundle;
+
+import org.apache.log4j.Logger;
public class ConfigUtil {
private static final String CONFIG_PROPERTIES = "config.properties";
+ private static final Logger logger = Logger.getLogger(ConfigUtil.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
+
private static Properties prop = null;
/**
@@ -31,18 +37,20 @@ public class ConfigUtil {
*/
public static Properties getPropertiesInstance()
{
+ logger.debug("Entering getPropertiesInstance method in ConfigUtil class");
+
if (prop == null) {
prop = new Properties();
try {
prop.load(ConfigUtil.class.getClassLoader().getResourceAsStream(CONFIG_PROPERTIES));
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error(bundle.getString("UNABLE_TO_LOAD_CONFIG"), e);
throw new IllegalStateException();
}
}
+ logger.debug("Exiting getPropertiesInstance method in ConfigUtil class");
return prop;
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/FileUtil.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/FileUtil.java
index 1e42728..a21aed9 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/FileUtil.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/FileUtil.java
@@ -24,20 +24,24 @@ import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.ResourceBundle;
-import javax.ws.rs.WebApplicationException;
import javax.xml.datatype.DatatypeConfigurationException;
+import org.apache.log4j.Logger;
import org.eclipse.lyo.core.utils.marshallers.OSLC4JContext;
import org.eclipse.lyo.core.utils.marshallers.OSLC4JMarshaller;
import org.eclipse.lyo.oslc4j.core.exception.OslcCoreApplicationException;
import org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper;
+import org.slf4j.helpers.MessageFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.util.FileManager;
public class FileUtil {
+ private static final Logger logger = Logger.getLogger(FileUtil.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
public static Object[] fileload(final String fileName, List<Class<?>> objectTypes)
throws DatatypeConfigurationException, FileNotFoundException,
@@ -45,7 +49,8 @@ public class FileUtil {
InstantiationException, InvocationTargetException,
OslcCoreApplicationException, URISyntaxException,
SecurityException, NoSuchMethodException {
-
+ logger.debug("Entering fileLoad method in FileUtil class. Param1: " + fileName);
+
final File file = new File(fileName);
if ((file.exists()) && (file.isFile()) && (file.canRead())) {
@@ -59,22 +64,24 @@ public class FileUtil {
objects.addAll(Arrays.asList(objectResources));
}
+ logger.debug("Exiting fileLoad method in FileUtil class.");
return objects.toArray();
}
+ logger.debug("Exiting fileLoad method in FileUtil class. Return is null");
return null;
}
public static void save(Object[] objects, final String fileName) {
+ logger.debug("Entering save method in FileUtil class. Param1: " + fileName);
OSLC4JContext context = OSLC4JContext.newInstance();
OSLC4JMarshaller marshaller = context.createMarshaller();
try {
marshaller.marshal(objects, new FileOutputStream(fileName));
- } catch (WebApplicationException e) {
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
+ } catch (Exception e) {
+ logger.error(MessageFormatter.format(bundle.getString("SAVE_FAILED"), fileName), e);
}
+ logger.debug("Exiting save method in FileUtil class");
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java
index ab21c15..f4a3252 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/ResponseUtil.java
@@ -16,44 +16,55 @@
package org.eclipse.lyo.rio.trs.util;
import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;
+import org.apache.log4j.Logger;
import org.eclipse.lyo.oslc4j.core.model.OslcMediaType;
+import org.eclipse.lyo.oslc4j.utils.AcceptUtil;
/**
* Class consisting of various methods to assist in the marshalling/unmarshalling
* of TRS toolkit resources for the servlet based implementation.
*/
public class ResponseUtil {
+ private static final Logger logger = Logger.getLogger(ResponseUtil.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
+
/**
* Return a string representing the requested accept type. Right now we
- * support text/turle and application/rdf+xml with text/turtle
+ * support text/turtle and application/rdf+xml with text/turtle
* being the default response.
*/
public static String parseAcceptType(HttpServletRequest request) throws IOException {
+ logger.debug("Entering parseAcceptType method in ResponseUtil class");
- String acceptTypes = request.getHeader("Accept");
+ MediaType acceptType = AcceptUtil.matchMediaType(request,
+ new MediaType[]{OslcMediaType.TEXT_TURTLE_TYPE,
+ OslcMediaType.APPLICATION_RDF_XML_TYPE,
+ OslcMediaType.APPLICATION_XML_TYPE});
- if (acceptTypes == null) {
+ if (acceptType == null) {
// turtle is the default response type if nothing specific is
// requested.
return OslcMediaType.TEXT_TURTLE;
}
- String[] types = acceptTypes.split(",");
- // Accepts should be answered in priority order. Respond with the first
- // type we encounter that is supported.
- for (String type : types) {
- if (type != null && (type.startsWith(OslcMediaType.TEXT_TURTLE) || type.startsWith("*/*"))) {
- return OslcMediaType.TEXT_TURTLE;
- } else if (type != null && (type.startsWith(OslcMediaType.APPLICATION_RDF_XML) || type.startsWith(OslcMediaType.APPLICATION_XML))) {
- return OslcMediaType.APPLICATION_RDF_XML;
- }
- }
+ if (acceptType.isCompatible(MediaType.valueOf(OslcMediaType.TEXT_TURTLE))) {
+ logger.debug("Exiting parseAcceptType method in ResponseUtil class. Accept type is turtle");
+ return OslcMediaType.TEXT_TURTLE;
+ } else if (acceptType.isCompatible(MediaType.valueOf(OslcMediaType.APPLICATION_RDF_XML))
+ || acceptType.isCompatible(MediaType.valueOf(OslcMediaType.APPLICATION_XML))) {
+ logger.debug("Exiting parseAcceptType method in ResponseUtil class. Accept type is RDF/XML");
+ return OslcMediaType.APPLICATION_RDF_XML;
+ }
+ logger.error(MessageFormat.format(bundle.getString("UNSUPPORTED_MEDIA_TYPE"), acceptType.toString()));
throw new WebApplicationException(Status.UNSUPPORTED_MEDIA_TYPE);
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java
index 5385343..34300f9 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSObject.java
@@ -27,8 +27,10 @@ import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.NavigableSet;
+import java.util.ResourceBundle;
import java.util.TreeMap;
+import org.apache.log4j.Logger;
import org.eclipse.lyo.core.trs.AbstractChangeLog;
import org.eclipse.lyo.core.trs.Base;
import org.eclipse.lyo.core.trs.ChangeEvent;
@@ -60,6 +62,9 @@ public class TRSObject {
private final TreeMap<Long, ChangeLog> trs_changelog_map = new TreeMap<Long, ChangeLog>();
private final List<ChangeEvent> change_events = new ArrayList<ChangeEvent>();
+ private static final Logger logger = Logger.getLogger(TRSObject.class);
+ private static final ResourceBundle bundle = ResourceBundle.getBundle("Messages");
+
private URI trs_uri = null;
private int trs_curr_changelog_size = 0;
private Long trs_curr_changelog_page = -1L;
@@ -103,6 +108,8 @@ public class TRSObject {
*/
private void initialize() {
synchronized (trs_base_map) {
+ logger.debug("Entering initialize method in TRSObject class");
+
trs_base_initialized = true;
List<URI> uris = resourceUtil.getAllResourceURIs();
@@ -162,6 +169,7 @@ public class TRSObject {
if (last_change_event != null) {
setCutOffEventInner(last_change_event);
}
+ logger.debug("Exiting initialize method in TRSObject class");
}
/**
@@ -173,6 +181,8 @@ public class TRSObject {
*/
private void loadChangeEvents() {
synchronized (change_events) {
+ logger.debug("Entering loadChangeEvents method in TRSObject class");
+
Object[] changeEvents;
try {
Class<?> [] objectTypes = {Creation.class, Modification.class, Deletion.class};
@@ -220,9 +230,9 @@ public class TRSObject {
}
}
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error(bundle.getString("CHANGE_EVENT_LOAD_FAILURE"), e);
}
+ logger.debug("Exiting loadChangeEvents method in TRSObject class");
}
}
@@ -275,6 +285,8 @@ public class TRSObject {
* persist across server restarts should likely be used.
*/
public void insertEventTypeToChangeLog(String trsEvent, URI resource, URI changeURN) {
+ logger.debug("Entering insertEventTypeToChangeLog method in TRSObject class. Param1: " + trsEvent + " Param2: " + resource.toString() + " Param3: " + changeURN.toString());
+
ChangeEvent event = null;
// increment the event number to maintain event order
int eventNumber = (last_change_event != null) ? last_change_event.getOrder() + 1 : 0;
@@ -289,7 +301,7 @@ public class TRSObject {
} catch (URISyntaxException e) {
// Unable to create a URN with the order appended. Log the error
// and continue on using the old style URN
- e.printStackTrace();
+ logger.warn(bundle.getString("URN_GENERATION_FAILULRE"), e);
}
if (trsEvent.equals(TRSConstants.TRS_TYPE_CREATION)) {
@@ -307,6 +319,8 @@ public class TRSObject {
FileUtil.save(change_events.toArray(), this.changeEventsFilename);
insertEventToPagedChangeLog(event, resource);
+
+ logger.debug("Exiting insertEventTypeToChangeLog method in TRSObject class");
}
/**
@@ -316,6 +330,9 @@ public class TRSObject {
*/
private void insertEventToPagedChangeLog(ChangeEvent event, URI resource) {
synchronized (trs_changelog_map) {
+
+ logger.debug("Entering insertEventToPagedChangeLog method in TRSObject class. Param1: " + event + " Param2: " + resource.toString());
+
// Create a change log entry if the current size is zero
if (trs_curr_changelog_size == 0) {
trs_curr_changelog_page++;
@@ -347,6 +364,7 @@ public class TRSObject {
trs_curr_changelog_size = 0;
}
}
+ logger.debug("Exiting insertEventToPagedChangeLog method in TRSObject class");
}
/**
@@ -364,6 +382,8 @@ public class TRSObject {
public void modifyCutoffEventInner(ChangeEvent inCutOffEvent) {
synchronized (trs_changelog_map) {
+ logger.debug("Entering modifyCutoffEventInner method in TRSObject class");
+
List<ChangeEvent> ListofEvents2Compact = new ArrayList<ChangeEvent>();
boolean bNewCutOffFound = false;
@@ -402,6 +422,8 @@ public class TRSObject {
}
// 2. Set the cutOffEvent
setCutOffEventInner(inCutOffEvent);
+
+ logger.debug("Exiting modifyCutoffEventInner method in TRSObject class");
}
}
@@ -410,6 +432,8 @@ public class TRSObject {
* @return null if the change event with the given uri can not be found or the change event with the given uri
*/
public ChangeEvent getChangeEventInner(String uriAbout) {
+ logger.debug("Entering getChangeEventInner method in TRSObject. Param1: " + uriAbout);
+
ChangeEvent result = null;
for (int page = 0; page <= trs_curr_changelog_page; page++) {
@@ -423,6 +447,7 @@ public class TRSObject {
}
}
+ logger.debug("Exiting getChangeEventInner method in TRSObject class");
return result;
}
@@ -433,7 +458,7 @@ public class TRSObject {
newBase.setCutoffEvent(new URI(TRSConstants.RDF_NIL));
newBase.setNextPage(getNextBasePage(newBase, getBaseResourceURI(currentPageNumber), new URI(TRSConstants.RDF_NIL)));
} catch (URISyntaxException e) {
- e.printStackTrace();
+ logger.error(bundle.getString("BASE_INITIALIZATION_FAILURE"), e);
}
return newBase;
}
@@ -490,6 +515,8 @@ public class TRSObject {
*/
private void modifyBase(ChangeEvent changeEvent) {
synchronized (trs_base_map) {
+ logger.debug("Entering modifyBase method in TRSObject class");
+
Collection<Base> baseValues = getTrsBaseMapInner().values();
// if Creation then add resource to base(last page).
if (changeEvent.getClass().equals(Creation.class)) {
@@ -526,6 +553,7 @@ public class TRSObject {
}
}
}
+ logger.debug("Exiting modifyBase method in TRSObject");
}
}
@@ -539,6 +567,8 @@ public class TRSObject {
* @throws ParseException
*/
private boolean isPrunningNecessary(URI urn) throws ParseException {
+ logger.debug("Entering isPrunningNecessary method in TRSObject. Param1: " + urn.toString());
+
// Get the time of the event in milliseconds
String eventTime = urn.toString();
@@ -549,6 +579,7 @@ public class TRSObject {
eventTime = eventTime.split(":")[3];
} catch (NullPointerException e) {
// Unexpected URN format do not prune this event
+ logger.warn(bundle.getString("UNEXPECTED_URN_FORMAT"), e);
return false;
}
@@ -563,9 +594,10 @@ public class TRSObject {
// If an event is older than the prune time (less time since the epoch
// has elapsed) indicate we need to prune this event.
if (pruneTime >= eventMilliseconds) {
+ logger.debug("Exiting isPrunningNecessary method in TRSObject class. Return is true");
return true;
}
-
+ logger.debug("Exiting isPrunningNecessary method in TRSObject class. Return is false");
return false;
}
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtil.java b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtil.java
index a0fcc97..d807481 100644
--- a/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtil.java
+++ b/org.eclipse.lyo.rio.trs/src/main/java/org/eclipse/lyo/rio/trs/util/TRSUtil.java
@@ -18,6 +18,8 @@ package org.eclipse.lyo.rio.trs.util;
import java.net.URI;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
import org.eclipse.lyo.core.trs.ChangeEvent;
/**
@@ -63,11 +65,17 @@ public class TRSUtil {
}
private static boolean IsGenericImplDesired(URI inURI){
+ logger.debug("Entering IsGenericImplDesired method in TRSUtil class. Param1: " + inURI);
+
String sUri = inURI.getPath();
- if (sUri.contains(TRS_GENERIC_MARKER))
+ if (sUri.contains(TRS_GENERIC_MARKER)) {
+ logger.debug("Exiting IsGenericImplDesired method in TRSUtil class. Return is true");
return true;
- else
- return false;
+ }
+ else {
+ logger.debug("Exiting IsGenericImplDesired method in TRSUtil class. Return is false");
+ return false;
+ }
}
public static TRSObject getTrsObject(IResourceUtil resourceUtil, URI inURI) {
@@ -83,6 +91,13 @@ public class TRSUtil {
public static void updateTRSResourceURI(IResourceUtil resourceUtil, URI resource) {
if (!TRS_URI_INITIALIZED) {
+ // By default the log4j.properties file will be placed in the application's
+ // WEB-INF/classes folder. Most application servers will automatically
+ // detect this file and initialize the logging. If that does not occur
+ // you may register the logging directly with the following call:
+ //PropertyConfigurator.configure(TRSUtil.class.getClassLoader().getResource("log4j.properties"));
+
+ logger.debug("Entering updateTRSResourceURI method in TRSUtil class. Param1: " + resource.toString());
String sPath = resource.getPath();
String sContext = null;
@@ -102,7 +117,9 @@ public class TRSUtil {
trs_Uri = resource.resolve("/" + sContext + TRS_URI_PATH2);
}
innerHelpr[i] = new TRSObject(resourceUtil, trs_Uri, ConfigUtil.getPropertiesInstance().getProperty("ChangeEventsFile"));
- }
+ }
+
+ logger.debug("Exiting updateTRSResource method in TRSUtil class.");
}
}
@@ -123,4 +140,5 @@ public class TRSUtil {
// inner container helper obj representing JAXRS and generic implementation.
private static TRSObject[] innerHelpr = new TRSObject[2];
public static boolean TRS_URI_INITIALIZED = false;
+ private static final Logger logger = Logger.getLogger(TRSUtil.class);
}
diff --git a/org.eclipse.lyo.rio.trs/src/main/resources/Messages.properties b/org.eclipse.lyo.rio.trs/src/main/resources/Messages.properties
new file mode 100644
index 0000000..1dc5f69
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs/src/main/resources/Messages.properties
@@ -0,0 +1,15 @@
+BASE_INITIALIZATION_FAILURE=Unable to initialize the base resource during server startup. Please ensure enough memory is free and restart the server.
+CHANGE_EVENT_LOAD_FAILURE=Unable to load change events from disk. Ensure the file specified by the ChangeEventsFile property is accessible. The server must be restarted or the change events will not be read and may be overwritten.
+DELETION_FAILURE=Unable to delete resource {0}. Please refresh the UI and ensure the resource exists. If errors persist ensure you have write permissions to the file specified by the ChangeRequestsFile property.
+FAILED_TO_CREATE_CR=Failed to create change request. You may refresh the page and attempt to create the change request again. If failures continue see the resourceContainer.log file for further details.
+INITIALIZATION_FAILURE=Failed to initialize the persistance component of the reference application. Ensure the config.properties file exists and that the ChangeRequestsFile property refers to a file that is readable by the reference application.
+MODIFICATION_FAILURE=Unable to modify resource {0}. Ensure you have write permissions to the file specified by the ChangeRequestsFile property.
+MODIFY_CUTOFF_FAILURE=Unable to set base's cutoff property to {0}. Check the change log and ensure you are specifying a valid event URN.
+NO_CHANGE_LOG=There is no change log associated with page number {0}.
+NO_SUCH_RESOURCE=The resource {0} could not be located. If you feel the resource still exists, refresh the UI and issue the request again.
+SAVE_FAILED=Failed to save data to {0}. Ensure you have write access to this directory.
+UNABLE_TO_LOAD_CONFIG=Unable to load the configuration properties found in the config.properties file. Please ensure this file exists in the classpath, often the WEB-INF/classes folder, and that your application server has read access to this file.
+UNABLE_TO_CONSTRUCT_URI=Unable to construct URI to TRS resource. See accompanying exception info for more details.
+UNEXPECTED_URN_FORMAT=An event older than PruneTimeInDays was discovered but it will not be pruned as its URN format does not match the typical urn:urn-3:cm1.example.com: + timestamp + : + order number format.
+UNSUPPORTED_MEDIA_TYPE=Received request with the following accept types {0} but none of these are supported.
+URN_GENERATION_FAILULRE=Unable to create a unique URN containing the event number. A URN containing only a timestamp will be used instead. This can potentially lead to multiple events with the same URN if they are created at the same time on a fast server. \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs/src/main/resources/log4j.properties b/org.eclipse.lyo.rio.trs/src/main/resources/log4j.properties
new file mode 100644
index 0000000..983da62
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs/src/main/resources/log4j.properties
@@ -0,0 +1,31 @@
+###############################################################################
+# Copyright (c) 2013 IBM Corporation.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+#
+# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+# and the Eclipse Distribution License is available at
+# http://www.eclipse.org/org/documents/edl-v10.php.
+#
+# Contributors:
+#
+# David Terry - initial implementation
+###############################################################################
+# Root logger option
+log4j.rootLogger=INFO, stdout, fileappender
+
+# Direct log messages to stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+
+log4j.appender.fileappender=org.apache.log4j.RollingFileAppender
+log4j.appender.fileappender.File=lyotrs.log
+log4j.appender.fileappender.layout=org.apache.log4j.PatternLayout
+log4j.appender.fileappender.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
+
+#log4j.logger.org.apache.wink.common = DEBUG, stdout, fileappender
+#log4j.logger.org.apache.wink.server = DEBUG, stdout, fileappender \ No newline at end of file