Skip to main content
summaryrefslogtreecommitdiffstats
blob: 58dc303babfdb91c835f90f9e3d8548376cd7b32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*******************************************************************************
 * Copyright (c) 2014 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.activity.internal.jaxrs;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.Response.StatusType;
import javax.ws.rs.ext.Provider;
import org.eclipse.osee.activity.ActivityConstants;
import org.eclipse.osee.activity.api.Activity;
import org.eclipse.osee.activity.api.ActivityLog;
import org.eclipse.osee.logger.Log;

/**
 * @author Ryan D. Brooks
 */
@Provider
public class ActivityLogResponseFilter implements ContainerResponseFilter {

   private Log logger;
   private ActivityLog activityLog;

   public void setActivityLogger(ActivityLog activityLog) {
      this.activityLog = activityLog;
   }

   public void setLogger(Log logger) {
      this.logger = logger;
   }

   /**
    * Called after a resource method is executed
    */
   @Override
   public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
      try {
         Long entryId = (Long) requestContext.getProperty(ActivityConstants.HTTP_HEADER__ACTIVITY_ENTRY_ID);
         if (entryId != null) {
            StatusType statusType = responseContext.getStatusInfo();
            if (statusType.getFamily() == Status.Family.SUCCESSFUL) {
               activityLog.completeEntry(entryId);
            } else {
               activityLog.endEntryAbnormally(entryId, responseContext.getStatus());
            }
         } else {
            // Response was called without a matching request
            activityLog.createUpdateableEntry(Activity.JAXRS_METHOD_CALL_FILTER_ERROR,
               ActivityConstants.ERROR_MSG__MISSING_ACTIVITY_HEADER);
         }
      } catch (Throwable th) {
         logger.error(th, "Error during ActivityContainerResponseFilter");
      }
   }
}

Back to the top