• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Is it possible to return an image with a web service ?

 
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post.
I have a big problem for showing Charts in my jsf portlet , there is no library to use.
so i come to this idea to make a web service and , the web service take parameters and create chart using Jfree, .... .
and then web service return the chart to my jsf portlet . i can use that chart and show it to my visitors.

now my question is :
1-How i can return an image with a web service ?
2-how i can show that image ?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you think that you can't use JFree in connection with a JSF-based portlet? Figuring out what the perceived problem on that is sounds a lot easier than creating a web service that sends images (although that is certainly possible).
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you for reply.
as you know Jfree , CeWolf ....
all of them use Servlets to render the chart , and portlets (at least jsf portlets) does not works with servlets.

for example , i tried to use jenia4faces which is charting component for jsf
but when i tried , it return varity of errors from NPE to an empty image
i never could make it works inside a portlet.
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have info about Jchart and JSF so I can only tell you it is possible to send a picture via web service.
I think you can code the picture (for example base64) then send as a string.
On client you get the String of code, you can decode it and cast it to other object (if there is any image object in java).
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JFree does not use servlets - it is a class library that works in whichever Java context you care to use it. Servlets, applets, applications, web service ... whereever you can use a Java class, you can use JFree.

cewolf is a tag library, so you would need a JSP enviroment for that. I don't see why it wouldn't work in conjunction with JSF.
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you for your helps.
i post a extened explanation of my problem in :
https://coderanch.com/t/362001/Servlets/java/servlet-url-mapping
i will be happy if you could take a look at it.
 
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless I'm missing something here, why not just keep using it as a servlet? Your portlet just decides which HTML img url to insert, but the servlet responds to the request for the image. Just deploy the servlet as a servlet. Portlets are responsible for rendering a section of an HTML document, not for rendering assets external to the document but referred to by that document.
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for reply , can you please give me more information , i can not understand what you mean.

Should i write another web application to render the images ?


Thank you
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlets can return text, HTML, images, pdf or whatever you want. Use the servlet to generate the chart and return it to the user. The process works something like this.

Your portlet generates the HTML. It sets the image src to some servlet with a customized query string. The browser renders the HTML. The browser has no idea this is a portlet. At this point it is just HTML. It renders the HTML as it knows how to do. When it finds an <img src=""> tag it makes another request to the server for the image.

When your portlet sets the image source it should do something like this http://www.yourcompany.com/servlets/MyImageChartRenderer?imageData=whateverYouNeed&lots=more Inside the MyImageChartRenderer servlet set it's content type to whatever image type you want to return instead of HTML. Have the MyImageChartRenderer servlet use the query string data to render the chart image however you normally would with JFree. Then return the image back to the user instead of HTML.

Doing it this way your portlet only needs to dynamicaly change the url for the image source. That is just text manipulation. Portlet or not, this should always work.
[ January 23, 2006: Message edited by: Rusty Enisin ]
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Thank you very much , this solution will help.
I just think that i create a seperate web application with just one servlet ,
in my jsf page i should set image source attribute to that sevlet and i should pass all of my parameters.
now i just have some questions

1-in some times there maybe more that one person request a chart , i know that servlet will return the image as a stream.
what will happen when 10 people request the page that contain that chart ?
as you know diffrent page may need different charts with different parameters.
will the servlet return correct chart for each of them ?

2-How mych long my url for image source could be ?
can it contain 20 parameters ?


Thank you
 
Rusty Enisin
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


1-will the servlet return correct chart for each of them ?


Yes. Be sure the variable containing the chart that you return is a method local variable. No static variables. No class instance variables. Create it only inside the method. Servlets share static and instance variables.



2-How mych long my url for image source could be ?
can it contain 20 parameters ?


20 parameters will be fine. I think GET requests are limited to 256 characters, or something there near ( ??? ). But POST is unlimited. So if you are worried about it, do a POST request.
[ January 24, 2006: Message edited by: Rusty Enisin ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I just think that i create a seperate web application with just one servlet


NO - not a separate web application, a servlet that lives in the same web application as the JSP. That way you can use the session to store any amount of variable detail and your img tag can simply provide a key to retrieve the parameters from the session.
Bill
 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for advice about using a servlet in same web application.
I described my problem with servlet in same web application in the following thread , sorry if i do not post it again because i describe it extensivly and pasting it here will just make the topic so long .

https://coderanch.com/t/362001/Servlets/java/servlet-url-mapping

i will be hapy if you take a look at that thread
thank you again
 
Whatever. Here's a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic