Package juzu

Examples of juzu.MimeType


    protected Response response() {
      try {
        Object ret = context.getHandler().getMethod().invoke(controller, args);

        //
        MimeType mimeType = null;
        for (Annotation annotation : context.getHandler().getMethod().getDeclaredAnnotations()) {
          if (annotation instanceof MimeType) {
            mimeType = (MimeType)annotation;
          } else {
            mimeType = annotation.annotationType().getAnnotation(MimeType.class);
          }
          if (mimeType != null && mimeType.value().length > 0) {
            // For now we stop but we should look at the accept types of the client
            // for doing some basic content negociation
            break;
          }
        }

        //
        if (ret instanceof Response) {
          // We should check that it matches....
          // btw we should try to enforce matching during compilation phase
          // @Action -> Response.Action
          // @View -> Response.Mime
          // as we can do it
          Response resp = (Response)ret;
          if (mimeType != null) {
            resp = resp.with(PropertyType.MIME_TYPE, mimeType.value()[0]);
          }
          return resp;
        } else if (ret != null && mimeType != null) {
          for (EntityMarshaller writer : Tools.loadService(EntityMarshaller.class, request.controllerPlugin.getApplication().getClassLoader())) {
            for (String s : mimeType.value()) {
              Streamable streamable = writer.marshall(s, context.getHandler().getMethod(), ret);
              if (streamable != null) {
                return Response.ok().with(PropertyType.MIME_TYPE, s).body(streamable);
              }
            }
View Full Code Here

TOP

Related Classes of juzu.MimeType

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.