001/*
002 * Copyright 2011-2016 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
018package com.unboundid.scim.wink;
019
020import com.unboundid.scim.data.ServiceProviderConfig;
021
022import javax.ws.rs.GET;
023import javax.ws.rs.Path;
024import javax.ws.rs.Produces;
025import javax.ws.rs.core.MediaType;
026import javax.ws.rs.core.Response;
027
028import static com.unboundid.scim.sdk.SCIMConstants.
029    RESOURCE_ENDPOINT_SERVICE_PROVIDER_CONFIG;
030import static com.unboundid.scim.sdk.SCIMConstants.
031    RESOURCE_NAME_SERVICE_PROVIDER_CONFIG;
032
033
034/**
035 * This class is a JAX-RS resource for the SCIM Service Provider Configuration
036 * where the response format is specified in the URL to be XML.
037 */
038@Path(RESOURCE_ENDPOINT_SERVICE_PROVIDER_CONFIG + ".xml")
039public class XMLServiceProviderConfigResource extends AbstractStaticResource
040{
041  private final SCIMApplication application;
042
043  /**
044   * Create a new JAX-RS resource.
045   *
046   * @param application    The SCIM JAX-RS application associated with this
047   *                       resource.
048   */
049  public XMLServiceProviderConfigResource(final SCIMApplication application) {
050    this.application = application;
051  }
052
053  /**
054   * Implement the GET operation to fetch the configuration in XML format.
055   *
056   * @return  The response to the request.
057   */
058  @GET
059  @Produces(MediaType.APPLICATION_XML)
060  public Response doXmlGet()
061  {
062    final ServiceProviderConfig config = application.getServiceProviderConfig();
063    Response.ResponseBuilder builder = Response.ok();
064
065    setResponseEntity(builder, MediaType.APPLICATION_XML_TYPE, config);
066    application.getStatsForResource(RESOURCE_NAME_SERVICE_PROVIDER_CONFIG).
067        incrementStat(ResourceStats.GET_RESPONSE_XML);
068    application.getStatsForResource(RESOURCE_NAME_SERVICE_PROVIDER_CONFIG).
069        incrementStat(ResourceStats.GET_OK);
070    return builder.build();
071  }
072}