001/*
002 * Copyright 2012-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.sdk.OAuthTokenHandler;
021
022import javax.servlet.http.HttpServletRequest;
023import javax.ws.rs.Consumes;
024import javax.ws.rs.POST;
025import javax.ws.rs.Path;
026import javax.ws.rs.Produces;
027import javax.ws.rs.core.Context;
028import javax.ws.rs.core.HttpHeaders;
029import javax.ws.rs.core.MediaType;
030import javax.ws.rs.core.Response;
031import javax.ws.rs.core.SecurityContext;
032import javax.ws.rs.core.UriInfo;
033import java.io.InputStream;
034
035
036
037/**
038 * This class is a JAX-RS resource for the Bulk operation, where the content
039 * type is determined by HTTP headers.
040 */
041@Path("Bulk")
042public class BulkResource extends AbstractBulkResource
043{
044  /**
045   * Create a new instance of the bulk resource.
046   *
047   * @param application        The SCIM JAX-RS application associated with this
048   *                           resource.
049   * @param tokenHandler       The token handler to use for OAuth
050   *                           authentication.
051   */
052  public BulkResource(final SCIMApplication application,
053                      final OAuthTokenHandler tokenHandler)
054  {
055    super(application, tokenHandler);
056  }
057
058
059
060  /**
061   * Implement the POST operation consuming and producing JSON format.
062   *
063   * @param inputStream      The content to be consumed.
064   * @param request          The HTTP servlet request.
065   * @param securityContext  The security context for the request.
066   * @param headers          The request headers.
067   * @param uriInfo          The URI info for the request.
068   *
069   * @return  The response to the request.
070   */
071  @POST
072  @Consumes(MediaType.APPLICATION_JSON)
073  @Produces(MediaType.APPLICATION_JSON)
074  public Response doJsonJsonPost(final InputStream inputStream,
075                                 @Context final HttpServletRequest request,
076                                 @Context final SecurityContext securityContext,
077                                 @Context final HttpHeaders headers,
078                                 @Context final UriInfo uriInfo)
079  {
080    final RequestContext requestContext =
081        new RequestContext(request, securityContext, headers, uriInfo,
082                           MediaType.APPLICATION_JSON_TYPE,
083                           MediaType.APPLICATION_JSON_TYPE);
084    return postBulk(requestContext, inputStream);
085  }
086
087
088
089  /**
090   * Implement the POST operation consuming and producing XML format.
091   *
092   * @param inputStream      The content to be consumed.
093   * @param request          The HTTP servlet request.
094   * @param securityContext  The security context for the request.
095   * @param headers          The request headers.
096   * @param uriInfo          The URI info for the request.
097   *
098   * @return  The response to the request.
099   */
100  @POST
101  @Consumes(MediaType.APPLICATION_XML)
102  @Produces(MediaType.APPLICATION_XML)
103  public Response doXmlXmlPost(final InputStream inputStream,
104                               @Context final HttpServletRequest request,
105                               @Context final SecurityContext securityContext,
106                               @Context final HttpHeaders headers,
107                               @Context final UriInfo uriInfo)
108  {
109    final RequestContext requestContext =
110        new RequestContext(request, securityContext, headers, uriInfo,
111                           MediaType.APPLICATION_XML_TYPE,
112                           MediaType.APPLICATION_XML_TYPE);
113    return postBulk(requestContext, inputStream);
114  }
115
116
117
118  /**
119   * Implement the POST operation consuming XML format and producing JSON
120   * format.
121   *
122   * @param inputStream      The content to be consumed.
123   * @param request          The HTTP servlet request.
124   * @param securityContext  The security context for the request.
125   * @param headers          The request headers.
126   * @param uriInfo          The URI info for the request.
127   *
128   * @return  The response to the request.
129   */
130  @POST
131  @Consumes(MediaType.APPLICATION_XML)
132  @Produces(MediaType.APPLICATION_JSON)
133  public Response doXmlJsonPost(final InputStream inputStream,
134                                @Context final HttpServletRequest request,
135                                @Context final SecurityContext securityContext,
136                                @Context final HttpHeaders headers,
137                                @Context final UriInfo uriInfo)
138  {
139    final RequestContext requestContext =
140        new RequestContext(request, securityContext, headers, uriInfo,
141                           MediaType.APPLICATION_XML_TYPE,
142                           MediaType.APPLICATION_JSON_TYPE);
143    return postBulk(requestContext, inputStream);
144  }
145
146
147
148  /**
149   * Implement the POST operation consuming JSON format and producing XML
150   * format.
151   *
152   * @param inputStream      The content to be consumed.
153   * @param request          The HTTP servlet request.
154   * @param securityContext  The security context for the request.
155   * @param headers          The request headers.
156   * @param uriInfo          The URI info for the request.
157   *
158   * @return  The response to the request.
159   */
160  @POST
161  @Consumes(MediaType.APPLICATION_JSON)
162  @Produces(MediaType.APPLICATION_XML)
163  public Response doJsonXmlPost(final InputStream inputStream,
164                                @Context final HttpServletRequest request,
165                                @Context final SecurityContext securityContext,
166                                @Context final HttpHeaders headers,
167                                @Context final UriInfo uriInfo)
168  {
169    final RequestContext requestContext =
170        new RequestContext(request, securityContext, headers, uriInfo,
171                           MediaType.APPLICATION_JSON_TYPE,
172                           MediaType.APPLICATION_XML_TYPE);
173    return postBulk(requestContext, inputStream);
174  }
175
176
177}