/* * RHQ Management Platform * Copyright 2013-2014, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.rhg.maven.plugins.itest; import java.io.IOException; import java.io.InputStream; import java.net.URI; import javax.ws.rs.Consumes; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; /** * @author Thomas Segismont */ @Path("/content") public class FakeContentEndpoint { @POST @Path("/fresh") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Response uploadContent(InputStream contentStream, @Context HttpHeaders headers, @Context UriInfo uriInfo) throws IOException { String name = "handle"; StringValue stringValue = new StringValue(name); UriBuilder uriBuilder = uriInfo.getBaseUriBuilder(); uriBuilder.path("/content/{handle}"); URI uri = uriBuilder.build(name); MediaType mediaType = headers.getAcceptableMediaTypes().get(0); Response.ResponseBuilder builder = Response.created(uri); builder.entity(stringValue); builder.type(mediaType); return builder.build(); } }