I want to display the buddy picture in web msn application.
I have refered the MsnObjectMessenger.java.
First, I put a contact and messenger object to session.
I can sure that I can view the picture of this contact in live messenger.
I build my own servlet to show the picure.
However, I alway get the avatar is null.
Does any one tell me why?
thank you very much.
I want to display the buddy picture in web msn application.
I have refered the MsnObjectMessenger.java.
First, I put a contact and messenger object to session.
I can sure that I can view the picture of this contact in live messenger.
I build my own servlet to show the picure.
However, I alway get the avatar is null.
Does any one tell me why?
thank you very much.
Here is my servlet source code:
package com;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import net.sf.jml.*;
import net.sf.jml.event.MsnAdapter;
import net.sf.jml.DisplayPictureListener.ResultStatus;
import net.sf.jml.message.p2p.DisplayPictureRetrieveWorker;
public class showPhoto extends HttpServlet implements net.sf.jml.DisplayPictureListener
{
HttpServletResponse res=null;
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
{
HttpSession session=request.getSession();
this.res=response;
MsnContact buddy=(MsnContact)session.getAttribute("contact");
// Get the MSnObject
MsnObject avatar = buddy.getAvatar();
if (avatar==null)
{
this.res.setContentType("text/html");
PrintWriter out = this.res.getWriter();
out.println("Getting Photo failure");
out.close();
}
else
{
MsnMessenger messenger=(MsnMessenger)session.getAttribute("object");
messenger.retrieveDisplayPicture(avatar,this);
}
}
public void notifyMsnObjectRetrieval(MsnMessenger messenger,DisplayPictureRetrieveWorker worker,MsnObject msnObject,ResultStatus result,byte[] resultBytes,Object context)
{
if (result == ResultStatus.GOOD)
{// Create a new file to store the avatar
try {
BufferedOutputStream bos=new BufferedOutputStream(this.res.getOutputStream());
this.res.setContentType("image/png");
bos.write(resultBytes);
bos.close();
bos=null;
}
catch (FileNotFoundException e)
{
System.err.println("Critical error: Unable to find file we just created.");
}
catch (IOException e)
{
System.err.println("Critical error: Unable to write data to file system.");
}
}
else
{
try{
this.res.setContentType("text/html");
PrintWriter out = this.res.getWriter();
out.println("Download Photo failure");
out.close();
}catch (IOException er)
{
er.printStackTrace();
}
}
}
}