Search in sources :

Example 11 with ChannelBufferInputStream

use of org.jboss.netty.buffer.ChannelBufferInputStream in project cdap by caskdata.

the class ArtifactHttpHandler method writeProperties.

@PUT
@Path("/namespaces/{namespace-id}/artifacts/{artifact-name}/versions/{artifact-version}/properties")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void writeProperties(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("artifact-name") String artifactName, @PathParam("artifact-version") String artifactVersion) throws Exception {
    NamespaceId namespace = NamespaceId.SYSTEM.getNamespace().equalsIgnoreCase(namespaceId) ? NamespaceId.SYSTEM : validateAndGetNamespace(namespaceId);
    Id.Artifact artifactId = validateAndGetArtifactId(namespace, artifactName, artifactVersion);
    Map<String, String> properties;
    try (Reader reader = new InputStreamReader(new ChannelBufferInputStream(request.getContent()), Charsets.UTF_8)) {
        properties = GSON.fromJson(reader, MAP_STRING_STRING_TYPE);
    } catch (JsonSyntaxException e) {
        throw new BadRequestException("Json Syntax Error while parsing properties from request. " + "Please check that the properties are a json map from string to string.", e);
    } catch (IOException e) {
        throw new BadRequestException("Unable to read properties from the request.", e);
    }
    try {
        artifactRepository.writeArtifactProperties(artifactId, properties);
        responder.sendStatus(HttpResponseStatus.OK);
    } catch (IOException e) {
        LOG.error("Exception writing properties for artifact {}.", artifactId, e);
        responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error adding properties to artifact.");
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BadRequestException(co.cask.cdap.common.BadRequestException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) ArtifactId(co.cask.cdap.proto.id.ArtifactId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) ChannelBufferInputStream(org.jboss.netty.buffer.ChannelBufferInputStream) IOException(java.io.IOException) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 12 with ChannelBufferInputStream

use of org.jboss.netty.buffer.ChannelBufferInputStream in project cdap by caskdata.

the class StreamViewHttpHandler method createOrUpdate.

@PUT
@Path("/streams/{stream}/views/{view}")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void createOrUpdate(HttpRequest request, HttpResponder responder, @PathParam("namespace") String namespace, @PathParam("stream") String stream, @PathParam("view") String view) throws Exception {
    StreamViewId viewId;
    try {
        viewId = new StreamViewId(namespace, stream, view);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException(e);
    }
    try (Reader reader = new InputStreamReader(new ChannelBufferInputStream(request.getContent()))) {
        ViewSpecification spec = GSON.fromJson(reader, ViewSpecification.class);
        if (spec == null) {
            throw new BadRequestException("Missing ViewSpecification in request body");
        }
        boolean created = admin.createOrUpdateView(viewId, spec);
        responder.sendStatus(created ? HttpResponseStatus.CREATED : HttpResponseStatus.OK);
    } catch (JsonSyntaxException e) {
        responder.sendString(HttpResponseStatus.BAD_REQUEST, "Couldn't decode body as view config JSON");
    } catch (IOException e) {
        LOG.warn("Error closing InputStreamReader", e);
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) BadRequestException(co.cask.cdap.common.BadRequestException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) ViewSpecification(co.cask.cdap.proto.ViewSpecification) ChannelBufferInputStream(org.jboss.netty.buffer.ChannelBufferInputStream) IOException(java.io.IOException) StreamViewId(co.cask.cdap.proto.id.StreamViewId) Path(javax.ws.rs.Path) AuditPolicy(co.cask.cdap.common.security.AuditPolicy) PUT(javax.ws.rs.PUT)

Example 13 with ChannelBufferInputStream

use of org.jboss.netty.buffer.ChannelBufferInputStream in project NabAlive by jcheype.

the class DataUtil method decompress.

public static ChannelBuffer decompress(ChannelBuffer in) throws IOException {
    ChannelBufferInputStream channelBufferInputStream = new ChannelBufferInputStream(in);
    SnappyInputStream inputStream = new SnappyInputStream(channelBufferInputStream);
    ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer(ByteStreams.toByteArray(inputStream));
    return channelBuffer;
}
Also used : SnappyInputStream(org.iq80.snappy.SnappyInputStream) ChannelBufferInputStream(org.jboss.netty.buffer.ChannelBufferInputStream) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 14 with ChannelBufferInputStream

use of org.jboss.netty.buffer.ChannelBufferInputStream in project NabAlive by jcheype.

the class DataUtil method compress.

public static ChannelBuffer compress(ChannelBuffer in) throws IOException {
    ChannelBufferInputStream channelBufferInputStream = new ChannelBufferInputStream(in);
    ChannelBuffer out = ChannelBuffers.dynamicBuffer(in.readableBytes());
    ChannelBufferOutputStream channelBufferOutputStream = new ChannelBufferOutputStream(out);
    compress(ByteStreams.toByteArray(channelBufferInputStream), channelBufferOutputStream);
    return out;
}
Also used : ChannelBufferOutputStream(org.jboss.netty.buffer.ChannelBufferOutputStream) ChannelBufferInputStream(org.jboss.netty.buffer.ChannelBufferInputStream) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 15 with ChannelBufferInputStream

use of org.jboss.netty.buffer.ChannelBufferInputStream in project adbcj by mheath.

the class Encoder method decode.

@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
    InputStream in = new ChannelBufferInputStream(buffer);
    DecoderInputStream dis = new DecoderInputStream(in);
    try {
        return decoder.decode(dis, false);
    } finally {
        dis.close();
    }
}
Also used : DecoderInputStream(org.adbcj.support.DecoderInputStream) ChannelBufferInputStream(org.jboss.netty.buffer.ChannelBufferInputStream) InputStream(java.io.InputStream) ChannelBufferInputStream(org.jboss.netty.buffer.ChannelBufferInputStream) DecoderInputStream(org.adbcj.support.DecoderInputStream)

Aggregations

ChannelBufferInputStream (org.jboss.netty.buffer.ChannelBufferInputStream)25 BadRequestException (co.cask.cdap.common.BadRequestException)15 InputStreamReader (java.io.InputStreamReader)15 Reader (java.io.Reader)14 IOException (java.io.IOException)12 JsonSyntaxException (com.google.gson.JsonSyntaxException)10 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)9 Path (javax.ws.rs.Path)8 POST (javax.ws.rs.POST)6 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)4 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)4 NamespaceId (co.cask.cdap.proto.id.NamespaceId)4 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 ExploreException (co.cask.cdap.explore.service.ExploreException)3 QueryHandle (co.cask.cdap.proto.QueryHandle)3 JsonObject (com.google.gson.JsonObject)3 InputStream (java.io.InputStream)3 SQLException (java.sql.SQLException)3 GenericDatumReader (org.apache.avro.generic.GenericDatumReader)3 GenericRecord (org.apache.avro.generic.GenericRecord)3