1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rest.internal

File XWikiRestletJaxRsApplication.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
17
1
1
83
32
1
0.06
17
1
1

Classes

Class Line # Actions
XWikiRestletJaxRsApplication 37 17 0% 1 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rest.internal;
21   
22    import org.restlet.Restlet;
23    import org.restlet.ext.jaxrs.JaxRsApplication;
24    import org.restlet.routing.Router;
25    import org.restlet.routing.Template;
26    import org.xwiki.component.manager.ComponentManager;
27    import org.xwiki.rest.internal.resources.BrowserAuthenticationResource;
28   
29    /**
30    * <p>
31    * This class implements the main Restlet application using the Restlet's JAX-RS extension. The implementation also
32    * setups the needed filters for handling the requests (setup/cleanup and authentication filters)
33    * </p>
34    *
35    * @version $Id: 0b13a0302955b10764cfbff0267091980d12126b $
36    */
 
37    public class XWikiRestletJaxRsApplication extends JaxRsApplication
38    {
 
39  18 toggle @Override
40    public Restlet createInboundRoot()
41    {
42    /* Create the JAX-RS application and add it to the main Restlet JAX-RS application */
43  18 XWikiJaxRsApplication xwikiJaxRsApplication = new XWikiJaxRsApplication(getContext());
44  18 add(xwikiJaxRsApplication);
45   
46    /*
47    * Create the root restlet. This basically sets up a chain: setup/cleanup filter -> authentication filter ->
48    * router
49    */
50  18 XWikiSetupCleanupFilter setupCleanupFilter = new XWikiSetupCleanupFilter();
51   
52  18 XWikiAuthentication xwikiAuthentication = new XWikiAuthentication(getContext());
53  18 ComponentManager componentManager =
54    (ComponentManager) getContext().getAttributes().get(Constants.XWIKI_COMPONENT_MANAGER);
55  18 xwikiAuthentication.setVerifier(new XWikiSecretVerifier(getContext(), componentManager));
56   
57    /* Create a router for adding resources */
58  18 Router router = new Router();
59  18 router.attach(BrowserAuthenticationResource.URI_PATTERN, BrowserAuthenticationResource.class);
60  18 router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
61   
62    /*
63    * Add to the router the restlet generated by the JAX-RS application which takes care of dispatching requests to
64    * JAX-RS resources
65    */
66  18 Restlet jaxRsRoot = super.createInboundRoot();
67   
68    /* Add support for media query parameter for selecting the media type */
69  18 getTunnelService().setEnabled(true);
70  18 getMetadataService().addCommonExtensions();
71  18 getTunnelService().setQueryTunnel(true);
72   
73  18 router.attach(jaxRsRoot);
74   
75    /* Build the actual chain */
76  18 setupCleanupFilter.setNext(xwikiAuthentication);
77  18 xwikiAuthentication.setNext(router);
78   
79    /* Return the setup/cleanup filter (the entry point for the chain) as the root restlet */
80  18 return setupCleanupFilter;
81    }
82   
83    }