jersey
  1. jersey
  2. JERSEY-1066

JAF is not used for all java types when returning entity from resource

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Works as designed
    • Affects Version/s: 2.0-m02
    • Fix Version/s: 2.0-m07, 2.0
    • Component/s: None
    • Labels:
      None

      Description

      The spec., Sec. 4.2.1, item 6, says:

      Else if a suitable data handler can be found using the JavaBeans Activation Framework[11] then use
      it to map the entity body to the desired Java type.

      From this, I assume, any Java type is a valid return type:

      @Path("resource")
      public class Resource {
      
      	@POST
      	@Path("jaf")
      	public WeirdClass jaf() {
      		String message = "";
      		try {
      			DataHandler
      					.setDataContentHandlerFactory(new WeirdDataContentHandlerFactory());
      		} catch (Error e) {
      			message = "Factory already present: " + e;
      		}
      		return new WeirdClass(message + " JAF");
      	}
      
      	@POST
      	@Path("jafds")
      	public DataSource jafds() {
      		return new WeirdDataSource(new WeirdClass("JAFDS"));
      	}
      }
      

      the jafds works fine. But jaf does not work. The log contains:

      javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class WeirdClass, and Java type class WeirdClass, and MIME media type application/octet-stream was not found.

      I assume Jersey should use JAF even for all Java classes, not only DataSource, and do something like:

      DataHandler dr = new DataHandler(<the return WeirdClass instance>, <Content-type>);  
      try {
         InputStream is = dr.getInputStream();
          } catch (UnsupportedDataTypeException e) {
      //no JAF, return
         }
         //Use this input stream from DataContentHandler (from DataContentHandlerFactory) instead of the stream from DataSource
      

        Issue Links

          Activity

          Hide
          jan.supol added a comment - - edited

          Oops, this test was about writing not reading, hence the section 4.2.2. item 7) applies:

          Else if a suitable data handler can be found using the JavaBeans Activation Framework[11] then use
          it to map the object to the entity body.

          Nevertheless, the DataHandler

          DataHandler dr = new DataHandler(<the return WeirdClass instance>, <@Produces>); 
          

          would be appropriate anyway.

          Show
          jan.supol added a comment - - edited Oops, this test was about writing not reading, hence the section 4.2.2. item 7) applies: Else if a suitable data handler can be found using the JavaBeans Activation Framework [11] then use it to map the object to the entity body. Nevertheless, the DataHandler DataHandler dr = new DataHandler(<the return WeirdClass instance>, <@Produces>); would be appropriate anyway.
          Hide
          Marek Potociar added a comment -

          Moved to 2.0 backlog.

          Show
          Marek Potociar added a comment - Moved to 2.0 backlog.
          Hide
          Marek Potociar added a comment -

          The final decision is to update the spec to not include those steps in the entity marshalling/un-marshalling algorithms. See issue JAX_RS_SPEC-249.

          Show
          Marek Potociar added a comment - The final decision is to update the spec to not include those steps in the entity marshalling/un-marshalling algorithms. See issue JAX_RS_SPEC-249 .

            People

            • Assignee:
              Marek Potociar
              Reporter:
              jan.supol
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 12 hours
                12h
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 6 hours Time Not Required
                6h