You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Max Spring <m2...@springdot.org> on 2018/02/20 22:29:44 UTC

globally disabling/enabling REST?

I'm using CXF 3.1.3 with Karaf 3.0.5.
I have a engine which exposes its functionality via REST.

My engine takes some time to properly start up.
I would like all my REST functions to always return 503 (Service Unavailable)
while the OSGi container and my engine is starting up,
until my engine declares "up".

Is there such a global flag to control CXF REST?

Thanks!
-Max

Re: globally disabling/enabling REST?

Posted by nino martinez wael <ni...@gmail.com>.
would be very nice if it was default functionality..

On Tue, Mar 13, 2018 at 1:24 AM, Max Spring <m2...@springdot.org> wrote:

> I ended up implementing this via a ContainerRequestFilter:
>
>     package org.example.filters;
>
>     import org.example.engine.Engine;
>
>     import javax.ws.rs.container.ContainerRequestContext;
>     import javax.ws.rs.container.ContainerRequestFilter;
>     import javax.ws.rs.core.Response;
>     import java.io.IOException;
>
>     public class OfflineModeFilter implements ContainerRequestFilter{
>
>         private Engine engine;
>
>         public void setEngine(Engine engine){
>             this.engine = engine;
>         }
>
>         @Override
>         public void filter(ContainerRequestContext requestContext) throws
> IOException{
>             if (engine.isOfflineMode()){
>                 requestContext.abortWith(Response.status(Response.Status.
> SERVICE_UNAVAILABLE)
>                   .entity("engine offline").build()
>                 );
>             }
>         }
>     }
>
> ...and injecting the engine via Blueprint:
>
>     <blueprint xmlns...>
>
>       <jaxrs:server id="restService" address="/">
>         <jaxrs:providers>
>           <bean class="org.example.filters.OfflineModeFilter">
>             <property name="engine" ref="engineSvc"/>
>           </bean>
>         </jaxrs:providers>
>       </jaxrs:server>
>
>       <reference id="engineSvc" interface="org.example.engine.Engine"
> availability="mandatory"/>
>
>     </blueprint>
>
> -Max
>
>
>
> On 02/20/2018 02:29 PM, Max Spring wrote:
>
>> I'm using CXF 3.1.3 with Karaf 3.0.5.
>> I have a engine which exposes its functionality via REST.
>>
>> My engine takes some time to properly start up.
>> I would like all my REST functions to always return 503 (Service
>> Unavailable)
>> while the OSGi container and my engine is starting up,
>> until my engine declares "up".
>>
>> Is there such a global flag to control CXF REST?
>>
>> Thanks!
>> -Max
>>
>>


-- 
Best regards / Med venlig hilsen
Nino Martinez

Re: globally disabling/enabling REST?

Posted by Max Spring <m2...@springdot.org>.
I ended up implementing this via a ContainerRequestFilter:

     package org.example.filters;

     import org.example.engine.Engine;

     import javax.ws.rs.container.ContainerRequestContext;
     import javax.ws.rs.container.ContainerRequestFilter;
     import javax.ws.rs.core.Response;
     import java.io.IOException;

     public class OfflineModeFilter implements ContainerRequestFilter{

         private Engine engine;

         public void setEngine(Engine engine){
             this.engine = engine;
         }

         @Override
         public void filter(ContainerRequestContext requestContext) throws IOException{
             if (engine.isOfflineMode()){
                 requestContext.abortWith(Response.status(Response.Status.SERVICE_UNAVAILABLE)
                   .entity("engine offline").build()
                 );
             }
         }
     }

...and injecting the engine via Blueprint:

     <blueprint xmlns...>

       <jaxrs:server id="restService" address="/">
         <jaxrs:providers>
           <bean class="org.example.filters.OfflineModeFilter">
             <property name="engine" ref="engineSvc"/>
           </bean>
         </jaxrs:providers>
       </jaxrs:server>

       <reference id="engineSvc" interface="org.example.engine.Engine" availability="mandatory"/>

     </blueprint>

-Max


On 02/20/2018 02:29 PM, Max Spring wrote:
> I'm using CXF 3.1.3 with Karaf 3.0.5.
> I have a engine which exposes its functionality via REST.
> 
> My engine takes some time to properly start up.
> I would like all my REST functions to always return 503 (Service Unavailable)
> while the OSGi container and my engine is starting up,
> until my engine declares "up".
> 
> Is there such a global flag to control CXF REST?
> 
> Thanks!
> -Max
>