001    /*
002     * Copyright 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.sdk.SCIMBackend;
021    
022    import javax.servlet.ServletContext;
023    import javax.ws.rs.Consumes;
024    import javax.ws.rs.POST;
025    import javax.ws.rs.Path;
026    import javax.ws.rs.Produces;
027    import javax.ws.rs.core.Context;
028    import javax.ws.rs.core.HttpHeaders;
029    import javax.ws.rs.core.MediaType;
030    import javax.ws.rs.core.Response;
031    import javax.ws.rs.core.SecurityContext;
032    import javax.ws.rs.core.UriInfo;
033    import 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")
042    public 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 bulkResourceStats  The resource stats for the bulk operation
050       *                           end-point.
051       * @param backend            The SCIMBackend to use to process individual
052       *                           operations within a bulk operation.
053       */
054      public BulkResource(final SCIMApplication application,
055                          final ResourceStats bulkResourceStats,
056                          final SCIMBackend backend)
057      {
058        super(application, bulkResourceStats, backend);
059      }
060    
061    
062    
063      /**
064       * Implement the POST operation consuming and producing JSON format.
065       *
066       * @param inputStream      The content to be consumed.
067       * @param servletContext   The servlet context for the request.
068       * @param securityContext  The security context for the request.
069       * @param headers          The request headers.
070       * @param uriInfo          The URI info for the request.
071       *
072       * @return  The response to the request.
073       */
074      @POST
075      @Consumes(MediaType.APPLICATION_JSON)
076      @Produces(MediaType.APPLICATION_JSON)
077      public Response doJsonJsonPost(final InputStream inputStream,
078                                     @Context final ServletContext servletContext,
079                                     @Context final SecurityContext securityContext,
080                                     @Context final HttpHeaders headers,
081                                     @Context final UriInfo uriInfo)
082      {
083        final RequestContext requestContext =
084            new RequestContext(servletContext, securityContext, headers, uriInfo,
085                               MediaType.APPLICATION_JSON_TYPE,
086                               MediaType.APPLICATION_JSON_TYPE);
087        return postBulk(requestContext, inputStream);
088      }
089    
090    
091    
092      /**
093       * Implement the POST operation consuming and producing XML format.
094       *
095       * @param inputStream      The content to be consumed.
096       * @param servletContext   The servlet context for the request.
097       * @param securityContext  The security context for the request.
098       * @param headers          The request headers.
099       * @param uriInfo          The URI info for the request.
100       *
101       * @return  The response to the request.
102       */
103      @POST
104      @Consumes(MediaType.APPLICATION_XML)
105      @Produces(MediaType.APPLICATION_XML)
106      public Response doXmlXmlPost(final InputStream inputStream,
107                                   @Context final ServletContext servletContext,
108                                   @Context final SecurityContext securityContext,
109                                   @Context final HttpHeaders headers,
110                                   @Context final UriInfo uriInfo)
111      {
112        final RequestContext requestContext =
113            new RequestContext(servletContext, securityContext, headers, uriInfo,
114                               MediaType.APPLICATION_XML_TYPE,
115                               MediaType.APPLICATION_XML_TYPE);
116        return postBulk(requestContext, inputStream);
117      }
118    
119    
120    
121      /**
122       * Implement the POST operation consuming XML format and producing JSON
123       * format.
124       *
125       * @param inputStream      The content to be consumed.
126       * @param servletContext   The servlet context for the request.
127       * @param securityContext  The security context for the request.
128       * @param headers          The request headers.
129       * @param uriInfo          The URI info for the request.
130       *
131       * @return  The response to the request.
132       */
133      @POST
134      @Consumes(MediaType.APPLICATION_XML)
135      @Produces(MediaType.APPLICATION_JSON)
136      public Response doXmlJsonPost(final InputStream inputStream,
137                                    @Context final ServletContext servletContext,
138                                    @Context final SecurityContext securityContext,
139                                    @Context final HttpHeaders headers,
140                                    @Context final UriInfo uriInfo)
141      {
142        final RequestContext requestContext =
143            new RequestContext(servletContext, securityContext, headers, uriInfo,
144                               MediaType.APPLICATION_XML_TYPE,
145                               MediaType.APPLICATION_JSON_TYPE);
146        return postBulk(requestContext, inputStream);
147      }
148    
149    
150    
151      /**
152       * Implement the POST operation consuming JSON format and producing XML
153       * format.
154       *
155       * @param inputStream      The content to be consumed.
156       * @param servletContext   The servlet context for the request.
157       * @param securityContext  The security context for the request.
158       * @param headers          The request headers.
159       * @param uriInfo          The URI info for the request.
160       *
161       * @return  The response to the request.
162       */
163      @POST
164      @Consumes(MediaType.APPLICATION_JSON)
165      @Produces(MediaType.APPLICATION_XML)
166      public Response doJsonXmlPost(final InputStream inputStream,
167                                    @Context final ServletContext servletContext,
168                                    @Context final SecurityContext securityContext,
169                                    @Context final HttpHeaders headers,
170                                    @Context final UriInfo uriInfo)
171      {
172        final RequestContext requestContext =
173            new RequestContext(servletContext, securityContext, headers, uriInfo,
174                               MediaType.APPLICATION_JSON_TYPE,
175                               MediaType.APPLICATION_XML_TYPE);
176        return postBulk(requestContext, inputStream);
177      }
178    
179    
180    }