[ 
https://issues.apache.org/jira/browse/CXF-3380?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Glen Mazza reopened CXF-3380:
-----------------------------


Hi, this sample is still indicating a problem (perhaps one further down after 
the latest change made):
https://github.com/gmazza/jersey-samples-on-cxf/tree/master/simple-servlet

For this class within it:
https://github.com/gmazza/jersey-samples-on-cxf/blob/master/simple-servlet/src/main/java/com/sun/jersey/samples/servlet/resources/ResourceBean3.java

The traditional way as described in this JIRA (lines 153-164) works but the 
DataSoure way (143-151) doesn't.  

Steps to replicate:
1. Check out simple-servlet:
git clone https://github.com/gmazza/jersey-samples-on-cxf.git
(move to simple-servlet folder).

2. Run "mvn clean install" on it.

3. Run "mvn jetty:run" and go to this page in a browser:
http://localhost:8080/SimpleServlet/resources/start

4. From the top, select "Resource 3", press the "Test Resource" button, leave 
Fred & Barney as-is, choose "Selection Method" of "Query Parameter" and MIME 
type of image/jpg.

5. Select the lower "Test Resource" button. You'll see the Oracle Duke 
logo/picture.  Everything good.

6. In class ResourceBean3 listed above, comment out the "public InputStream 
getImageRep()" method and uncomment the "public DataSource getImageRep()" 
method; repeat steps 2-5 above.  This time, though, no picture is returned and 
server reports back "WARNING: No message body writer has been found for 
response class FileDataSource."

                
> JAX-RS: Support writing to DataSources
> --------------------------------------
>
>                 Key: CXF-3380
>                 URL: https://issues.apache.org/jira/browse/CXF-3380
>             Project: CXF
>          Issue Type: Improvement
>          Components: JAX-RS
>            Reporter: Glen Mazza
>            Assignee: Sergey Beryozkin
>             Fix For: 2.3.8, 2.4.5, 2.5.1
>
>
> CXF's JAX-RS implementation can presently read from but not write to data 
> sources (javax.activation.DataSource).  Provide an ability to write to data 
> sources so we can code this way:
> @Produces("image/jpg")
> @GET
> public DataSource getImageRep() {
>     URL jpgURL = this.getClass().getResource("myimage.jpg");
>     return new FileDataSource(jpgURL.getFile());     
> } 
> instead of something like this:
> @Produces("image/jpg")
> @GET
> public InputStream getImageRep() {
>    FileInputStream fis = null;
>    try {
>       URL jpgURL = this.getClass().getResource("myimage.jpg");
>       fis = new FileInputStream(new File(jpgURL.getPath()));
>    } catch (IOException e) {
>       System.out.println("Couldn't find file!");
>    }
>    return fis;
> }    

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to