directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject [directory-fortress-enmasse] branch master updated: o new interceptor to set the HTTP status code based on the FortResponse (FC-258) o set the HTTP sttus code while creating the error response o updated the version of realm o added new interceptor to the application context
Date Sun, 03 Mar 2019 12:04:28 GMT
This is an automated email from the ASF dual-hosted git repository.

kayyagari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-fortress-enmasse.git


The following commit(s) were added to refs/heads/master by this push:
     new c06b53c  o new interceptor to set the HTTP status code based on the FortResponse
(FC-258) o set the HTTP sttus code while creating the error response o updated the version
of realm o added new interceptor to the application context
c06b53c is described below

commit c06b53c7fb546eab0120cd79f629a6f6456808b6
Author: Kiran Ayyagari <kayyagari@apache.org>
AuthorDate: Mon Nov 19 21:45:56 2018 +0530

    o new interceptor to set the HTTP status code based on the FortResponse (FC-258)
    o set the HTTP sttus code while creating the error response
    o updated the version of realm
    o added new interceptor to the application context
---
 pom.xml                                            |  2 +-
 .../directory/fortress/rest/AbstractMgrImpl.java   |  1 +
 .../fortress/rest/FortressResponseInterceptor.java | 65 ++++++++++++++++++++++
 src/main/resources/applicationContext.xml          |  6 ++
 4 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index ce17f39..e42e80a 100755
--- a/pom.xml
+++ b/pom.xml
@@ -93,7 +93,7 @@
     <title>${project.name} ${project.version}</title>
     
     <!-- Dependencies version -->
-    <fortress.realm.version>2.0.3</fortress.realm.version>
+    <fortress.realm.version>2.0.4-SNAPSHOT</fortress.realm.version>
     <cxf.version>3.2.6</cxf.version>
     <httpclient.version>3.1</httpclient.version>
     <java.version>1.8</java.version>
diff --git a/src/main/java/org/apache/directory/fortress/rest/AbstractMgrImpl.java b/src/main/java/org/apache/directory/fortress/rest/AbstractMgrImpl.java
index 95c5b2e..b0361b6 100644
--- a/src/main/java/org/apache/directory/fortress/rest/AbstractMgrImpl.java
+++ b/src/main/java/org/apache/directory/fortress/rest/AbstractMgrImpl.java
@@ -44,6 +44,7 @@ abstract class AbstractMgrImpl
         LOG.info( "Caught " + se );
         response.setErrorCode( se.getErrorId() );
         response.setErrorMessage( se.getMessage() );
+        response.setHttpStatus(se.getHttpStatus());
     }
     
     
diff --git a/src/main/java/org/apache/directory/fortress/rest/FortressResponseInterceptor.java
b/src/main/java/org/apache/directory/fortress/rest/FortressResponseInterceptor.java
new file mode 100644
index 0000000..c94a62d
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/rest/FortressResponseInterceptor.java
@@ -0,0 +1,65 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.fortress.rest;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.directory.fortress.core.model.FortResponse;
+
+/**
+ * Interceptor to set the HTTP Status code based on the value present in FortResponse.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class FortressResponseInterceptor extends AbstractPhaseInterceptor<Message>
+{
+    public FortressResponseInterceptor()
+    {
+        super(Phase.MARSHAL);
+        addBefore(JAXRSOutInterceptor.class.getName());
+    }
+    
+    @Override
+    public void handleMessage(Message message) throws Fault
+    {
+        boolean isOutbound = false;
+        if( ( message == message.getExchange().getOutMessage() ) || ( message == message.getExchange().getOutFaultMessage()
) )
+        {
+            isOutbound = true;
+        }
+        
+        if( isOutbound )
+        {
+            MessageContentsList objs = MessageContentsList.getContentsList(message);
+            if (objs != null && !objs.isEmpty())
+            {
+                Object o = objs.get(0);
+                if( o instanceof FortResponse )
+                {
+                    message.getExchange().put( Message.RESPONSE_CODE, ((FortResponse)o).getHttpStatus()
);
+                }
+            }
+        }
+    }
+}
diff --git a/src/main/resources/applicationContext.xml b/src/main/resources/applicationContext.xml
index 5649b86..6e6d26e 100644
--- a/src/main/resources/applicationContext.xml
+++ b/src/main/resources/applicationContext.xml
@@ -45,6 +45,8 @@ under the License.
         <constructor-arg ref="customMapper"/>
     </bean>
 
+    <bean id="fortressResponseInterceptor" class="org.apache.directory.fortress.rest.FortressResponseInterceptor"/>
+
     <jaxrs:server id="restContainer" address="/">
         <jaxrs:serviceBeans>
             <ref bean="fortressService"/>
@@ -54,6 +56,10 @@ under the License.
             <ref bean="annotationsInterceptor"/>
         </jaxrs:inInterceptors>
 
+        <jaxrs:outInterceptors>
+            <ref bean="fortressResponseInterceptor"/>
+        </jaxrs:outInterceptors>
+
         <jaxrs:outFaultInterceptors>
             <bean class="org.apache.directory.fortress.rest.SecurityOutFaultInterceptor"/>
         </jaxrs:outFaultInterceptors>


Mime
View raw message