Package com.google.sitebricks.client

Examples of com.google.sitebricks.client.Transport


      injector.getInstance(HttpServletRequest.class).setAttribute(Reply.NO_REPLY_ATTR, Boolean.TRUE);
      return;
    }

    // This is where we take all the builder values and encode them in the response.
    Transport transport = injector.getInstance(this.transport);

    // Set any headers (we do this first, so we can override any cheekily set headers).
    if (!headers.isEmpty()) {
      for (Map.Entry<String, String> header : headers.entrySet()) {
        response.setHeader(header.getKey(), header.getValue());
      }
    }

    // If the content type was already set, do nothing.
    if (response.getContentType() == null) {
      // By default we use the content type of the transport.
      if (null == contentType) {
        response.setContentType(transport.contentType());
      } else {
        response.setContentType(contentType);
      }
    }

    // Send redirect
    if (null != redirectUri) {
      response.sendRedirect(redirectUri);
      response.setStatus(status); // HACK to override whatever status the redirect sets.
      return;
    }

    // Write out data.
    response.setStatus(status);

    if (null != templateKey) {
      response.getWriter().write(injector.getInstance(Templates.class).render(templateKey, entity));
    } else if (null != entity) {
      if (entity instanceof InputStream) {
        // Stream the response rather than marshalling it through a transport.
        InputStream inputStream = (InputStream) entity;
        try {
          ByteStreams.copy(inputStream, response.getOutputStream());
        } finally {
          inputStream.close();
        }
      } else {
        // TODO(dhanji): This feels wrong to me. We need a better way to obtain the entity type.
        transport.out(response.getOutputStream(), (Class<E>) entity.getClass(), entity);
      }
    }
  }
View Full Code Here


    if (event == null)
      event = DEFAULT;

    MethodDispatcher method = receivers.get(event);
    Object instance = injector.getInstance(type);
    Transport transport = injector.getInstance(method.observe.value());

    try {
      Object in = transport.in(new ByteArrayInputStream(data.getBytes()),
          method.method.getParameterTypes()[0]);

      method.method.invoke(instance, in);
    } catch (IllegalAccessException e) {
      throw new RuntimeException("Dispatch error in @Observe method: " + method, e);
View Full Code Here

      injector.getInstance(HttpServletRequest.class).setAttribute(Reply.NO_REPLY_ATTR, Boolean.TRUE);
      return;
    }

    // This is where we take all the builder values and encode them in the response.
    Transport transport = injector.getInstance(this.transport);

    // Set any headers (we do this first, so we can override any cheekily set headers).
    if (!headers.isEmpty()) {
      for (Map.Entry<String, String> header : headers.entrySet()) {
        response.setHeader(header.getKey(), header.getValue());
      }
    }

    // If the content type was already set, do nothing.
    if (response.getContentType() == null) {
      // By default we use the content type of the transport.
      if (null == contentType) {
        response.setContentType(transport.contentType());
      } else {
        response.setContentType(contentType);
      }
    }


    // Send redirect
    if (null != redirectUri) {
      response.sendRedirect(redirectUri);
      response.setStatus(status); // HACK to override whatever status the redirect sets.
      return;
    }

    // Write out data.
    response.setStatus(status);

    if (null != templateKey) {
      response.getWriter().write(injector.getInstance(Templates.class).render(templateKey, entity));
    } else if (null != entity) {
      if (entity instanceof InputStream) {
        // Stream the response rather than marshalling it through a transport.
        InputStream inputStream = (InputStream) entity;
        try {
          IOUtils.copy(inputStream, response.getOutputStream());
        } finally {
          inputStream.close();
        }
      } else {
        // TODO(dhanji): This feels wrong to me. We need a better way to obtain the entity type.
        transport.out(response.getOutputStream(), (Class<E>) entity.getClass(), entity);
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.google.sitebricks.client.Transport

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.