001    /*
002     * Copyright 2011-2012 UnboundID Corp.
003     *
004     * This program is free software; you can redistribute it and/or modify
005     * it under the terms of the GNU General Public License (GPLv2 only)
006     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007     * as published by the Free Software Foundation.
008     *
009     * This program is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     * GNU General Public License for more details.
013     *
014     * You should have received a copy of the GNU General Public License
015     * along with this program; if not, see <http://www.gnu.org/licenses>.
016     */
017    
018    package com.unboundid.scim.wink;
019    
020    import com.unboundid.scim.data.ServiceProviderConfig;
021    
022    import javax.ws.rs.GET;
023    import javax.ws.rs.Path;
024    import javax.ws.rs.Produces;
025    import javax.ws.rs.core.MediaType;
026    import javax.ws.rs.core.Response;
027    
028    import static com.unboundid.scim.sdk.SCIMConstants.
029        RESOURCE_ENDPOINT_SERVICE_PROVIDER_CONFIG;
030    
031    
032    
033    /**
034     * This class is a JAX-RS resource for the SCIM Service Provider Configuration
035     * where the response format is specified in the URL to be JSON.
036     */
037    @Path(RESOURCE_ENDPOINT_SERVICE_PROVIDER_CONFIG + ".json")
038    public class JSONServiceProviderConfigResource extends AbstractStaticResource
039    {
040      private final SCIMApplication application;
041      private final ResourceStats resourceStats;
042    
043      /**
044       * Create a new JAX-RS resource.
045       *
046       * @param application    The SCIM JAX-RS application associated with this
047       *                       resource.
048       * @param resourceStats  The ResourceStats instance to use.
049       */
050      public JSONServiceProviderConfigResource(final SCIMApplication application,
051                                               final ResourceStats resourceStats) {
052        this.application = application;
053        this.resourceStats = resourceStats;
054      }
055    
056      /**
057       * Implement the GET operation to fetch the configuration in JSON format.
058       *
059       * @return  The response to the request.
060       */
061      @GET
062      @Produces(MediaType.APPLICATION_JSON)
063      public Response doJsonGet()
064      {
065        final ServiceProviderConfig config = application.getServiceProviderConfig();
066        Response.ResponseBuilder builder = Response.ok();
067    
068        setResponseEntity(builder, MediaType.APPLICATION_JSON_TYPE, config);
069        resourceStats.incrementStat(ResourceStats.GET_RESPONSE_XML);
070        resourceStats.incrementStat(ResourceStats.GET_OK);
071        return builder.build();
072      }
073    }