Package com.anthavio.httl.SenderBodyRequest

Examples of com.anthavio.httl.SenderBodyRequest.FakeStream


      String mimeType = (String) type[0];
      Charset charset = (Charset) type[1];
      if (request.hasBody()) {
        InputStream stream = ((SenderBodyRequest) request).getBodyStream();
        if (stream instanceof FakeStream) {
          FakeStream fake = (FakeStream) stream;

          if (fake.getValue() instanceof String) {
            String string = (String) fake.getValue();
            byte[] dataBytes = string.getBytes(charset);
            writeBytes(connection, dataBytes);
          } else {
            RequestBodyMarshaller marshaller = getRequestMarshaller(mimeType);
            if (marshaller == null) {
              throw new IllegalArgumentException("Request body marshaller not found for " + mimeType);
            }
            if (fake.isStreaming()) {
              marshaller.write(fake.getValue(), connection.getOutputStream(), charset);
            } else {
              //XXX create string first an then write...
              marshaller.write(fake.getValue(), connection.getOutputStream(), charset);
            }
          }
        } else {
          writeStream(connection, stream);
        }
View Full Code Here


    RequestEntity entity;
    if (request.hasBody()) {
      InputStream stream = ((SenderBodyRequest) request).getBodyStream();
      if (stream instanceof FakeStream) {
        FakeStream fake = (FakeStream) stream;
        if (fake.getValue() instanceof String) {
          entity = new StringRequestEntity((String) fake.getValue(), null, charset.name());
        } else {
          RequestBodyMarshaller marshaller = getRequestMarshaller(mimeType);
          if (marshaller == null) {
            throw new IllegalArgumentException("Request body marshaller not found for " + mimeType);
          }
          entity = new ObjectEntity(fake.getValue(), charset, marshaller, fake.isStreaming());
        }
      } else {//plain InputStream
        entity = new InputStreamRequestEntity(stream);
      }
    } else if (query != null && query.length() != 0) {
View Full Code Here

    /**
     * Set String as request body (entity)
     */
    public X body(String body, String contentType) {
      this.bodyStream = new FakeStream(body);
      this.contentType = contentType;
      return getX();
    }
View Full Code Here

     * Object will be marshalled/serialized to String
     *
     * @param streaming write directly into output stream or create interim String / byte[]
     */
    public X body(Object body, String contentType, boolean streaming) {
      this.bodyStream = new FakeStream(body, streaming);
      this.contentType = contentType;
      return getX();
    }
View Full Code Here

    HttpEntity entity;
    if (request.hasBody()) {
      InputStream stream = ((SenderBodyRequest) request).getBodyStream();
      if (stream instanceof FakeStream) {
        FakeStream fake = (FakeStream) stream;
        if (fake.getValue() instanceof String) {
          entity = new StringEntity((String) fake.getValue(), charset);
        } else {
          RequestBodyMarshaller marshaller = getRequestMarshaller(mimeType);
          if (marshaller == null) {
            throw new IllegalArgumentException("Request body marshaller not found for " + mimeType);
          }
          entity = new ObjectHttpEntity(fake.getValue(), charset, marshaller, fake.isStreaming());
        }
      } else { //plain InputStream
        entity = new InputStreamEntity(stream, -1);
      }
    } else if (query != null && query.length() != 0) {
View Full Code Here

TOP

Related Classes of com.anthavio.httl.SenderBodyRequest.FakeStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.