users@jersey.java.net

[Jersey] com.sun.jersey.api.MessageException ?

From: susmitha <susmitha.shali_at_tcs.com>
Date: Thu, 23 Jun 2011 00:02:39 -0700 (PDT)

Hello , i want to retrieve pictures from database and display list of images
using a web service. Logic is fine n i am able to retrieve pics from
database which are stored as Blob type. Everything is working fine but web
service giving "com.sun.jersey.api.MessageException". Return type is
ArrayList<Inputstream>.

My java code is:

package hai;

import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement


public class TestBlob
{
         
        Connection con;
        String url = "jdbc:mysql://localhost:3306/divinator";
        String Sqlusername ="root";
        String Sqlpassword ="root";
    Blob image=null;
        
        
        
                
        public ArrayList<InputStream> testImage() throws SQLException,
ClassNotFoundException

            {
                 ArrayList<Blob> imgData=new ArrayList<Blob> ();
                 java.sql.Blob b=null;
                 ArrayList<InputStream> is= new ArrayList<InputStream>();
                 
                     
                 try
                     {
                                Class.forName("com.mysql.jdbc.Driver");
                                con = DriverManager.getConnection(url, Sqlusername, Sqlpassword);
                                    Statement stmt = con.createStatement();
                                    String query = "select * from pictures where id=1";
                                    ResultSet rs = stmt.executeQuery(query);
                                                       
                                     while (rs.next ())
                                    {
                                            
                                             imgData .add(rs.getBlob("pic1"));
                                             imgData .add(rs.getBlob("pic2"));
                                             imgData .add(rs.getBlob("pic3"));
                                             imgData .add(rs.getBlob("pic4"));
                                             imgData .add(rs.getBlob("pic5"));
                                            
                                             
                                         System.out.println("imgData :"+imgData);
                                                                     
                                     
                                    }
                                     int i=imgData.size();
                                     System.out.println("size:"+i);
                                     
                                     for(int j=0; j&lt;i;j++)
                                     {
                                             b=imgData.get(j);
                                             InputStream str=null;
                                             str=b.getBinaryStream();
                                             System.out.println(&quot;blob is:&quot;+b);
                                             System.out.println(&quot;inputstream :&quot;+str);
                                             is.add(str);
                                             System.out.println(&quot;is:&quot;+is);
                                     }
                                     
                     }
                             
                     
                     catch (Exception e)
                            
                            {
                                    e.printStackTrace();
                                    
                                     return null;
                            }
                     
                     
                    return is;
            }
            
        
        public static void main(String args[]) throws SQLException,
ClassNotFoundException
        {
                
                System.out.println(&quot;from main :&quot; );
                
                TestBlob b=new TestBlob();
            b.testImage();
                
        }

}
            

  *****************************************


And My web service code is:


import hai.GetBlob;
import hai.TestBlob;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement


@Path(&quot;service&quot;)
public class webservice

{

            @GET
                @Path(&quot;testimage&quot;)
                @Produces(&quot;image/jpeg&quot;)
                
                public static ArrayList&lt;InputStream&gt; getTestImage() throws
FileNotFoundException
                        
                        {
                     ArrayList<InputStream> is=null;
                        
                                 
                                 
                          
                          try
                                
                                {
                                        
                                        
                                        TestBlob iw=new TestBlob();
                                is = iw.testImage();
                                System.out.println("from web service:"+is);
                                        
                                }
                                
                                catch (SQLException e)
                                
                                {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                                
                                catch (ClassNotFoundException e)
                                
                                {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                                
                                return is;
                        }
                        
                        
            }
                        
                        
                        
        **************************************


Suggest me plz.



        



--
View this message in context: http://jersey.576304.n2.nabble.com/com-sun-jersey-api-MessageException-tp6507380p6507380.html
Sent from the Jersey mailing list archive at Nabble.com.