WE HAVE SUNSET THIS LISTSERV - Join us at collectionspace@lyrasislists.org
View all threadsDear all,
I've been a bit further in this access problem.
Using WireShark on packets received by CollectionSpace, I can say the following:
· When sending the following command through command line:
curl http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content -o /tmp/billede.jpg
... CollectionSpace receives this:
GET /cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content HTTP/1.1
Authorization: Basic YWRtaW5Ac21rLmRrOkFkbWluaXN0cmF0b3I=
User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
Host: csdev-seb:8180
Accept: /
... and sends the image back.
· When sending the same request through iReport
(i.e. the image expression in the iReport is http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content)
... then CollectionSpace receives this:
GET /cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content HTTP/1.1
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.6.0
Host: csdev-seb:8180
Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
Connection: keep-alive
... and doesn't send the image back.
· When sending the same request through Mozilla, CollectionSpace receives this:
GET /cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content HTTP/1.1
Host: csdev-seb:8180
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: da,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: JSESSIONID=7AE77169561FD264731339356D5FE659
Authorization: Basic YWRtaW5Ac21rLmRrOkFkbWluaXN0cmF0b3I=
... and sends the image back.
It's seems like JasperServer doesn't transfer the credentials (i.e. this line: Authorization: Basic YWRtaW5Ac21rLmRrOkFkbWluaXN0cmF0b3I=) in its request to CollectionSpace.
As said in my previous mail, I came to understand that this could be configured through applicationContext-security.xml, without certainty.
I've been looking at this today, and it's a real pain in the neck. So, my first question is:
· Could somebody confirm that it's really through applicationContext-security.xml configuration that it's possible to transfer credentials from JasperServer to CollectionSpace?
And the second question, yes, you've guessed:
· If so, does anyone has a hint how to do so?! (I couldn't find out up until now)
Thank you all!
And have a nice day.
Best regards,
Sébastien
Fra: talk-bounces@lists.collectionspace.org [mailto:talk-bounces@lists.collectionspace.org] På vegne af Sébastien Brossard
Sendt: 1. oktober 2012 16:38
Til: 'Aron Roberts'
Cc: CollectionSpace Talk List
Emne: Re: [Talk] iReport - insert image blob
Hi all,
Thank you very much for your help.
Rick and Aron, your curl command worked:
curl http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content -o /tmp/billede.jpg
... and I was able to download the picture (or at least to download something, since the file couldn't be properly read - but at least the CS's log seemed to show that the blob was read.)
After that, I used the link in the following image expression in iReport:
String.format("http://admin%%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/%s/blob/derivatives/Medium/contenthttp://admin%25%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/%25s/blob/derivatives/Medium/content", $F{mediacsid})
... and it worked well in iReport's preview windows - although I had to insert manually the id/pwd in a logging window that popped-up on my first try.
Thus, it was not a total surprise that, once the .jasper file was generated and placed in /usr/local/share/apache-tomcat-6.0.33/cspace/reports, I still got a 401 access error in CollectionSpace when trying to visualize the report - here's an excerpt from the log:
java.io.IOException::Server returned HTTP response code: 401 for URL: http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
I don't know nothing about the working protocol and interactions between the JasperReport server and CollectionSpace, and I can't really understand why CollectionSpace reacts differently when I make a call through curl than when I do it through Japser.
Looking on the web, I found out this security file in JasperReport (applicationContext-security.xml) could be the answer... but it seems quite complex (linkhttp://blog.springsource.com/2010/03/06/behind-the-spring-security-namespace/ found in the comments of CollectionSpace's applicationContext-security.xml) and I hasn't made a breakthrough yet - still has to figure out what is this file really about, and if it's helpful at all.
Anyway, any idea would be of great help! Thank you by advance -again- for your kind help.
Best regards,
Sébastien
-----Oprindelig meddelelse-----
Fra: aronroberts@gmail.commailto:aronroberts@gmail.com [mailto:aronroberts@gmail.com]mailto:[mailto:aronroberts@gmail.com] På vegne af Aron Roberts
Sendt: 29. september 2012 01:44
Til: Sébastien Brossard
Cc: Rick Jaffe; CollectionSpace Talk List
Emne: Re: [Talk] iReport - insert image blob
One more thing about which Rick reminded me:
Any credentials (such as a username and password) that might be stored in any persistent way are sensitive data, and need to be protected appropriately.
As well, if you haven't already done so, you might consider creating a special CollectionSpace account to use when generating these reports that is associated with a very limited role, one which has been granted only the minimum privileges required, such as read-only privileges only on some selected record types.
On Fri, Sep 28, 2012 at 3:50 PM, Aron Roberts <aron@socrates.berkeley.edumailto:aron@socrates.berkeley.edu> wrote:
Hi Sébastien,
On Fri, Sep 28, 2012 at 3:25 PM, Rick Jaffe <rjaffe@berkeley.edumailto:rjaffe@berkeley.edu> wrote:
I've been able to download an image using the services API similar to the one you tried in your iReport by including the authentication credentials in the body of the GET URL:
curl
http://admin%40core.collectionspace.org:Administrator@demo.collection
space.org:8180/cspace-services/media/9b5c1b2e-5a6b-47f4-ace1/blob/der
ivatives/Medium/content -o /tmp/Southern_Right_Whale_101_Medium.jpg
Would this work within your iReport?
Expanding just a bit on Rick's excellent suggestion here, if iReport
doesn't give you some way to independently specify the username and
password you need to supply in order to download an image file via
CollectionSpace's services layer, you can instead try embedding that
username and password directly into the URL, using this
Internet-standard syntax (from RFC 1738,
http://<user>:<password>@<host>:<port>/<url-pathhttp://%3cuser%3e:%3cpassword%3e@%3chost%3e:%3cport%3e/%3curl-path>
Since a CollectionSpace username is an email address, which contains
an 'at sign' ('@'), you'll need to encode that character as '%40', as
Rick has shown in his example above. Hence if you were trying to
download an image file as the user 'admin@core.collectionspace.org",
with the password "Administrator", from the CollectionSpace server at
the host "demo.collectionspace.org" at port 8180, the URL would begin
like this:
http://admin%40core.collectionspace.org:Administrator@demo.collectionspace.org:8180/...
Aron
On Sep 28, 2012, at 2:42 PM, Aron Roberts wrote:
Thanks much, Rick!
A bit more on file corruption when downloading image files from
CollectionSpace (or any other source) via the command-line 'curl'
utility:
Curl's '-i" option (which spits out HTTP headers to the console, and
for that reason is ordinarily very useful) seems to be what's
corrupting the JPEG images. When using that option, saved image
files begin with bits of extraneous text - the HTTP headers - which
corrupts them. Apparently adding the '--dump-header' option (which
dumps HTTP headers to a file, if given an optional filename
argument), counteracts that by suppressing the output of '-i', and
allows the images to be saved without corruption.
By implication, by omitting both options, -i and --dump-header,
you can still successfully save JPEG images via curl; I was just now
able to do so under Mac OS X, with the saved image viewable in OS
X's Preview application.
curl -u admin@core.collectionspace.org:Administratormailto:admin@core.collectionspace.org:Administrator
5a6b-47f4-ace1/blob/content -o
PATH/TO/WHERE/ON/YOUR/MACHINE/YOU/WANT/TO/SAVE/THE/FILE/Southern_Rig
ht_Whale_8.jpg
Aron
On Fri, Sep 28, 2012 at 1:51 PM, Rick Jaffe <rjaffe@berkeley.edumailto:rjaffe@berkeley.edu> wrote:
Sébastien,
I've just had success downloading an image using cURL. It wouldn't
open in Preview.app on the Mac, though, until I added the option
that dumped the headers. Perhaps something similar is happening in your case #2 below?
Here's the cURL command I ran against demo.collectionspace.org (the
-o option saves the bits as a file):
curl --dump-header -i -u
-5a6b-47f4-ace1/blob/content
-o
PATH/TO/WHERE/ON/YOUR/MACHINE/YOU/WANT/TO/SAVE/THE/FILE/Southern_Ri
ght_Whale_8.jpg
Rick
Rick Jaffe
University of California Berkeley
IST-Research & Content Technologies
250-32 Earl Warren Hall (2195 Hearst) #4876 Berkeley, CA
94720-4876
(510) 642-0590
On Sep 26, 2012, at 7:26 AM, Sébastien Brossard wrote:
Dear all,
I'm currently working with reports on CS v2.6 (and iReport v4.0.2)
It worked pretty well until I had to insert dynamic images in the
report (i.e. media related to the CollectionObject shown in the report).
There are two mains points here:
1/
Having created an Image field, I tried to access image through URL:
<reportElement positionType="Float" x="6" y="256"
width="165" height="115" isPrintWhenDetailOverflows="true"/>
<imageExpression class="java.awt.Image">
-4aae-b3ef/blob/derivatives/Medium/content
")]]>
</imageExpression> </image>
Unfortunately I got a blank "Authentication required" popup back in
iReport's main windows.
Chris told me that I had to set HTTP' Authentication header to my
request but... how?! Where in iReport?!
After crawling the Web, results are poor (not to say worrying, as
this same problem has been on Stackoverflow's website for the past
two years waiting for an answer)
2/
Anyway, I managed to get the media by another mean (which is not
pretty, I must admit):
<reportElement positionType="Float" x="6" y="256"
width="165" height="115" isPrintWhenDetailOverflows="true"/>
<imageExpression class="java.awt.Image">
</imageExpression> </image>
But here, I'm still not able to show the picture in the report.
It seems like I've used all possible <imageExpression> type combinations.
I used also an image loader (i.e.
"net.sf.jasperreports.engine.util.JRImageLoader.loadImage") but without any
success.
(remark: using an URL pointing to a "jpeg" file works well).
Question is, what is exactly the format returned by this kind of request
(i.e.
Thank you by advance for your kindly help.
Best regards,
Sébastien
Talk mailing list
Talk mailing list
Hi Sébastien,
Thanks for this detailed summary - it's very helpful! As you've
identified, it appears that iReport Designer is not sending the
'Authorization:' HTTP header to convey your BASE64-encoded
username:password pair, in your requests to obtain image files via the
CollectionSpace Services REST APIs.
With apologies for the delayed response, I've taken a few minutes
here and there at times over the last week to try to find some clear
suggestions for you from posts on the Jaspersoft forums about how to
proceed, without finding anything much there obviously useful. There
are lots of unanswered questions asked on that forum.
According to one of those posts, with an older version of iReport,
someone actually went to the extent of locally modifying its source
code and recompiling (!) to transmit credentials they provided via
'http://username:password@host:port/...'-style URLs:
http://community.jaspersoft.com/questions/527131/solved-how-use-web-service-datasource
As well, it's also potentially worth looking at the **
/demo/samples/images folder ** in the JasperReports (not iReport)
distribution, which you can download for v4.5.1 from here:
http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%204.5.1/
(see the two "jasperreports-4.5.1-project..." links)
In particular, you might look at the sample report (which I haven't
personally yet looked at), and at the documentation file,
/demo/samples/images/docs/index.xml, which notes that this sample
report and associated files:
"Shows how images could be used in a report template ... using the
build-in image element." This document suggests that one option you
can provide for the source of the image, in that image element, is a
java.net.URL expression, which conceivably might take HTTP Basic-style
username/password credentials.
Aron
P.S. This article also looked interesting, as a potential example - at
a superficial first look, at least - of how we might try to integrate
data from CollectionSpace Services REST API calls alongside data from
SQL queries:
"HOWTO: Use remote XML data source for chart generation in JasperReports"
http://blog.altosresearch.com/use-xml-data-source-for-chart-generation-in-jasperreports/
On Tue, Oct 2, 2012 at 7:38 AM, Sébastien Brossard
Sebastien.Brossard@smk.dk wrote:
Dear all,
I’ve been a bit further in this access problem.
Using WireShark on packets received by CollectionSpace, I can say the
following:
· When sending the following command through command line:
curl
http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
-o /tmp/billede.jpg
… CollectionSpace receives this:
GET
/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
HTTP/1.1
Authorization: Basic YWRtaW5Ac21rLmRrOkFkbWluaXN0cmF0b3I=
User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o
zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
Host: csdev-seb:8180
Accept: /
… and sends the image back.
· When sending the same request through iReport
(i.e. the image expression in the iReport is
http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content)
… then CollectionSpace receives this:
GET
/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
HTTP/1.1
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.6.0
Host: csdev-seb:8180
Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
Connection: keep-alive
… and doesn’t send the image back.
· When sending the same request through Mozilla, CollectionSpace
receives this:
GET
/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
HTTP/1.1
Host: csdev-seb:8180
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101
Firefox/15.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: da,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: JSESSIONID=7AE77169561FD264731339356D5FE659
Authorization: Basic YWRtaW5Ac21rLmRrOkFkbWluaXN0cmF0b3I=
… and sends the image back.
It’s seems like JasperServer doesn’t transfer the credentials (i.e. this
line: Authorization: Basic YWRtaW5Ac21rLmRrOkFkbWluaXN0cmF0b3I=) in its
request to CollectionSpace.
As said in my previous mail, I came to understand that this could be
configured through applicationContext-security.xml, without certainty.
I’ve been looking at this today, and it’s a real pain in the neck. So, my
first question is:
· Could somebody confirm that it’s really through
applicationContext-security.xml configuration that it’s possible to transfer
credentials from JasperServer to CollectionSpace?
And the second question, yes, you’ve guessed:
· If so, does anyone has a hint how to do so?! (I couldn’t find out
up until now)
Thank you all!
And have a nice day.
Best regards,
Sébastien
Fra: talk-bounces@lists.collectionspace.org
[mailto:talk-bounces@lists.collectionspace.org] På vegne af Sébastien
Brossard
Sendt: 1. oktober 2012 16:38
Til: 'Aron Roberts'
Cc: CollectionSpace Talk List
Emne: Re: [Talk] iReport - insert image blob
Hi all,
Thank you very much for your help.
Rick and Aron, your curl command worked:
curl
http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
-o /tmp/billede.jpg
... and I was able to download the picture (or at least to download
something, since the file couldn’t be properly read – but at least the CS’s
log seemed to show that the blob was read.)
After that, I used the link in the following image expression in iReport:
String.format("http://admin%%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/%s/blob/derivatives/Medium/content",
$F{mediacsid})
... and it worked well in iReport's preview windows – although I had to
insert manually the id/pwd in a logging window that popped-up on my first
try.
Thus, it was not a total surprise that, once the .jasper file was generated
and placed in /usr/local/share/apache-tomcat-6.0.33/cspace/reports, I still
got a 401 access error in CollectionSpace when trying to visualize the
report – here’s an excerpt from the log:
java.io.IOException::Server returned HTTP response code: 401 for URL:
http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
I don’t know nothing about the working protocol and interactions between the
JasperReport server and CollectionSpace, and I can’t really understand why
CollectionSpace reacts differently when I make a call through curl than when
I do it through Japser.
Looking on the web, I found out this security file in JasperReport
(applicationContext-security.xml) could be the answer… but it seems quite
complex (link found in the comments of CollectionSpace’s
applicationContext-security.xml) and I hasn’t made a breakthrough yet –
still has to figure out what is this file really about, and if it’s helpful
at all.
Anyway, any idea would be of great help! Thank you by advance –again- for
your kind help.
Best regards,
Sébastien
-----Oprindelig meddelelse-----
Fra: aronroberts@gmail.com [mailto:aronroberts@gmail.com] På vegne af Aron
Roberts
Sendt: 29. september 2012 01:44
Til: Sébastien Brossard
Cc: Rick Jaffe; CollectionSpace Talk List
Emne: Re: [Talk] iReport - insert image blob
One more thing about which Rick reminded me:
Any credentials (such as a username and password) that might be stored in
any persistent way are sensitive data, and need to be protected
appropriately.
As well, if you haven't already done so, you might consider creating a
special CollectionSpace account to use when generating these reports that is
associated with a very limited role, one which has been granted only the
minimum privileges required, such as read-only privileges only on some
selected record types.
On Fri, Sep 28, 2012 at 3:50 PM, Aron Roberts aron@socrates.berkeley.edu
wrote:
Hi Sébastien,
On Fri, Sep 28, 2012 at 3:25 PM, Rick Jaffe rjaffe@berkeley.edu wrote:
I've been able to download an image using the services API similar to the
one you tried in your iReport by including the authentication credentials in
the body of the GET URL:
curl
http://admin%40core.collectionspace.org:Administrator@demo.collection
space.org:8180/cspace-services/media/9b5c1b2e-5a6b-47f4-ace1/blob/der
ivatives/Medium/content -o /tmp/Southern_Right_Whale_101_Medium.jpg
Would this work within your iReport?
Expanding just a bit on Rick's excellent suggestion here, if iReport
doesn't give you some way to independently specify the username and
password you need to supply in order to download an image file via
CollectionSpace's services layer, you can instead try embedding that
username and password directly into the URL, using this
Internet-standard syntax (from RFC 1738,
http://<user>:<password>@<host>:<port>/<url-path>
Since a CollectionSpace username is an email address, which contains
an 'at sign' ('@'), you'll need to encode that character as '%40', as
Rick has shown in his example above. Hence if you were trying to
download an image file as the user 'admin@core.collectionspace.org",
with the password "Administrator", from the CollectionSpace server at
the host "demo.collectionspace.org" at port 8180, the URL would begin
like this:
http://admin%40core.collectionspace.org:Administrator@demo.collectionspace.org:8180/...
Aron
On Sep 28, 2012, at 2:42 PM, Aron Roberts wrote:
Thanks much, Rick!
A bit more on file corruption when downloading image files from
CollectionSpace (or any other source) via the command-line 'curl'
utility:
Curl's '-i" option (which spits out HTTP headers to the console, and
for that reason is ordinarily very useful) seems to be what's
corrupting the JPEG images. When using that option, saved image
files begin with bits of extraneous text - the HTTP headers - which
corrupts them. Apparently adding the '--dump-header' option (which
dumps HTTP headers to a file, if given an optional filename
argument), counteracts that by suppressing the output of '-i', and
allows the images to be saved without corruption.
By implication, by omitting both options, -i and --dump-header,
you can still successfully save JPEG images via curl; I was just now
able to do so under Mac OS X, with the saved image viewable in OS
X's Preview application.
curl -u admin@core.collectionspace.org:Administrator
5a6b-47f4-ace1/blob/content -o
PATH/TO/WHERE/ON/YOUR/MACHINE/YOU/WANT/TO/SAVE/THE/FILE/Southern_Rig
ht_Whale_8.jpg
Aron
On Fri, Sep 28, 2012 at 1:51 PM, Rick Jaffe rjaffe@berkeley.edu wrote:
Sébastien,
I've just had success downloading an image using cURL. It wouldn't
open in Preview.app on the Mac, though, until I added the option
that dumped the headers. Perhaps something similar is happening in your
case #2 below?
Here's the cURL command I ran against demo.collectionspace.org (the
-o option saves the bits as a file):
curl --dump-header -i -u
admin@core.collectionspace.org:Administrator
-5a6b-47f4-ace1/blob/content
-o
PATH/TO/WHERE/ON/YOUR/MACHINE/YOU/WANT/TO/SAVE/THE/FILE/Southern_Ri
ght_Whale_8.jpg
Rick
Rick Jaffe
University of California Berkeley
IST-Research & Content Technologies
250-32 Earl Warren Hall (2195 Hearst) #4876 Berkeley, CA
94720-4876
(510) 642-0590
On Sep 26, 2012, at 7:26 AM, Sébastien Brossard wrote:
Dear all,
I'm currently working with reports on CS v2.6 (and iReport v4.0.2)
It worked pretty well until I had to insert dynamic images in the
report (i.e. media related to the CollectionObject shown in the
report).
There are two mains points here:
1/
Having created an Image field, I tried to access image through URL:
<reportElement positionType="Float" x="6" y="256"
width="165" height="115" isPrintWhenDetailOverflows="true"/>
<imageExpression class="java.awt.Image">
-4aae-b3ef/blob/derivatives/Medium/content
")]]>
</imageExpression> </image>
Unfortunately I got a blank "Authentication required" popup back in
iReport's main windows.
Chris told me that I had to set HTTP' Authentication header to my
request but... how?! Where in iReport?!
After crawling the Web, results are poor (not to say worrying, as
this same problem has been on Stackoverflow’s website for the past
two years waiting for an answer)
2/
Anyway, I managed to get the media by another mean (which is not
pretty, I must admit):
<reportElement positionType="Float" x="6" y="256"
width="165" height="115" isPrintWhenDetailOverflows="true"/>
<imageExpression class="java.awt.Image">
</imageExpression> </image>
But here, I’m still not able to show the picture in the report.
It seems like I’ve used all possible <imageExpression> type
combinations.
I used also an image loader (i.e.
“net.sf.jasperreports.engine.util.JRImageLoader.loadImage”) but without
any
success.
(remark: using an URL pointing to a “jpeg” file works well).
Question is, what is exactly the format returned by this kind of
request
(i.e.
Thank you by advance for your kindly help.
Best regards,
Sébastien
Talk mailing list
Talk mailing list
Hi Aron,
Thank you for your time and researches.
I'll look at links you sent trying to find out a solution here and I'll come back to you.
Best regards,
Sébastien
-----Oprindelig meddelelse-----
Fra: aronroberts@gmail.com [mailto:aronroberts@gmail.com] På vegne af Aron Roberts
Sendt: 12. oktober 2012 02:29
Til: Sébastien Brossard
Cc: CollectionSpace Talk List; John Lowe
Emne: Re: [Talk] iReport - insert image blob
Hi Sébastien,
Thanks for this detailed summary - it's very helpful! As you've identified, it appears that iReport Designer is not sending the 'Authorization:' HTTP header to convey your BASE64-encoded username:password pair, in your requests to obtain image files via the CollectionSpace Services REST APIs.
With apologies for the delayed response, I've taken a few minutes here and there at times over the last week to try to find some clear suggestions for you from posts on the Jaspersoft forums about how to proceed, without finding anything much there obviously useful. There are lots of unanswered questions asked on that forum.
According to one of those posts, with an older version of iReport, someone actually went to the extent of locally modifying its source code and recompiling (!) to transmit credentials they provided via 'http://username:password@host:port/...'-style URLs:
http://community.jaspersoft.com/questions/527131/solved-how-use-web-service-datasource
As well, it's also potentially worth looking at the ** /demo/samples/images folder ** in the JasperReports (not iReport) distribution, which you can download for v4.5.1 from here:
http://sourceforge.net/projects/jasperreports/files/jasperreports/JasperReports%204.5.1/
(see the two "jasperreports-4.5.1-project..." links)
In particular, you might look at the sample report (which I haven't personally yet looked at), and at the documentation file, /demo/samples/images/docs/index.xml, which notes that this sample report and associated files:
"Shows how images could be used in a report template ... using the build-in image element." This document suggests that one option you can provide for the source of the image, in that image element, is a java.net.URL expression, which conceivably might take HTTP Basic-style username/password credentials.
Aron
P.S. This article also looked interesting, as a potential example - at a superficial first look, at least - of how we might try to integrate data from CollectionSpace Services REST API calls alongside data from SQL queries:
"HOWTO: Use remote XML data source for chart generation in JasperReports"
http://blog.altosresearch.com/use-xml-data-source-for-chart-generation-in-jasperreports/
On Tue, Oct 2, 2012 at 7:38 AM, Sébastien Brossard Sebastien.Brossard@smk.dk wrote:
Dear all,
I've been a bit further in this access problem.
Using WireShark on packets received by CollectionSpace, I can say the
following:
· When sending the following command through command line:
curl
http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/med
ia/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
-o /tmp/billede.jpg
. CollectionSpace receives this:
GET
/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium
/content
HTTP/1.1
Authorization: Basic YWRtaW5Ac21rLmRrOkFkbWluaXN0cmF0b3I=
User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0
OpenSSL/0.9.8o
zlib/1.2.3.4 libidn/1.15 libssh2/1.2.6
Host: csdev-seb:8180
Accept: /
. and sends the image back.
· When sending the same request through iReport
(i.e. the image expression in the iReport is
http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/med
ia/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content)
. then CollectionSpace receives this:
GET
/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium
/content
HTTP/1.1
Cache-Control: no-cache
Pragma: no-cache
User-Agent: Java/1.6.0
Host: csdev-seb:8180
Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
Connection: keep-alive
. and doesn't send the image back.
· When sending the same request through Mozilla, CollectionSpace
receives this:
GET
/cspace-services/media/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium
/content
HTTP/1.1
Host: csdev-seb:8180
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0)
Gecko/20100101
Firefox/15.0.1
Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: da,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: JSESSIONID=7AE77169561FD264731339356D5FE659
Authorization: Basic YWRtaW5Ac21rLmRrOkFkbWluaXN0cmF0b3I=
. and sends the image back.
It's seems like JasperServer doesn't transfer the credentials (i.e.
this
line: Authorization: Basic YWRtaW5Ac21rLmRrOkFkbWluaXN0cmF0b3I=) in
its request to CollectionSpace.
As said in my previous mail, I came to understand that this could be
configured through applicationContext-security.xml, without certainty.
I've been looking at this today, and it's a real pain in the neck. So,
my first question is:
· Could somebody confirm that it's really through
applicationContext-security.xml configuration that it's possible to
transfer credentials from JasperServer to CollectionSpace?
And the second question, yes, you've guessed:
· If so, does anyone has a hint how to do so?! (I couldn't find out
up until now)
Thank you all!
And have a nice day.
Best regards,
Sébastien
Fra: talk-bounces@lists.collectionspace.org
[mailto:talk-bounces@lists.collectionspace.org] På vegne af Sébastien
Brossard
Sendt: 1. oktober 2012 16:38
Til: 'Aron Roberts'
Cc: CollectionSpace Talk List
Emne: Re: [Talk] iReport - insert image blob
Hi all,
Thank you very much for your help.
Rick and Aron, your curl command worked:
curl
http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/med
ia/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
-o /tmp/billede.jpg
... and I was able to download the picture (or at least to download
something, since the file couldn't be properly read - but at least the
CS's log seemed to show that the blob was read.)
After that, I used the link in the following image expression in iReport:
String.format("http://admin%%40smk.dk:Administrator@csdev-seb:8180/csp
ace-services/media/%s/blob/derivatives/Medium/content",
$F{mediacsid})
... and it worked well in iReport's preview windows - although I had
to insert manually the id/pwd in a logging window that popped-up on my
first try.
Thus, it was not a total surprise that, once the .jasper file was
generated and placed in
/usr/local/share/apache-tomcat-6.0.33/cspace/reports, I still got a
401 access error in CollectionSpace when trying to visualize the report - here's an excerpt from the log:
java.io.IOException::Server returned HTTP response code: 401 for URL:
http://admin%40smk.dk:Administrator@csdev-seb:8180/cspace-services/med
ia/1923b43b-0e5f-4b7c-ab96/blob/derivatives/Medium/content
I don't know nothing about the working protocol and interactions
between the JasperReport server and CollectionSpace, and I can't
really understand why CollectionSpace reacts differently when I make a
call through curl than when I do it through Japser.
Looking on the web, I found out this security file in JasperReport
(applicationContext-security.xml) could be the answer. but it seems
quite complex (link found in the comments of CollectionSpace's
applicationContext-security.xml) and I hasn't made a breakthrough yet
Anyway, any idea would be of great help! Thank you by advance -again-
for your kind help.
Best regards,
Sébastien
-----Oprindelig meddelelse-----
Fra: aronroberts@gmail.com [mailto:aronroberts@gmail.com] På vegne af
Aron Roberts
Sendt: 29. september 2012 01:44
Til: Sébastien Brossard
Cc: Rick Jaffe; CollectionSpace Talk List
Emne: Re: [Talk] iReport - insert image blob
One more thing about which Rick reminded me:
Any credentials (such as a username and password) that might be stored
in any persistent way are sensitive data, and need to be protected
appropriately.
As well, if you haven't already done so, you might consider creating a
special CollectionSpace account to use when generating these reports
that is associated with a very limited role, one which has been
granted only the minimum privileges required, such as read-only
privileges only on some selected record types.
On Fri, Sep 28, 2012 at 3:50 PM, Aron Roberts
aron@socrates.berkeley.edu
wrote:
Hi Sébastien,
On Fri, Sep 28, 2012 at 3:25 PM, Rick Jaffe rjaffe@berkeley.edu wrote:
I've been able to download an image using the services API similar
to the one you tried in your iReport by including the authentication
credentials in the body of the GET URL:
curl
http://admin%40core.collectionspace.org:Administrator@demo.collectio
n
space.org:8180/cspace-services/media/9b5c1b2e-5a6b-47f4-ace1/blob/de
r
ivatives/Medium/content -o /tmp/Southern_Right_Whale_101_Medium.jpg
Would this work within your iReport?
Expanding just a bit on Rick's excellent suggestion here, if
iReport
doesn't give you some way to independently specify the username and
password you need to supply in order to download an image file via
CollectionSpace's services layer, you can instead try embedding that
username and password directly into the URL, using this
Internet-standard syntax (from RFC 1738,
http://<user>:<password>@<host>:<port>/<url-path>
Since a CollectionSpace username is an email address, which
contains
an 'at sign' ('@'), you'll need to encode that character as '%40', as
Rick has shown in his example above. Hence if you were trying to
download an image file as the user 'admin@core.collectionspace.org",
with the password "Administrator", from the CollectionSpace server at
the host "demo.collectionspace.org" at port 8180, the URL would begin
like this:
http://admin%40core.collectionspace.org:Administrator@demo.collectionspace.org:8180/...
Aron
On Sep 28, 2012, at 2:42 PM, Aron Roberts wrote:
Thanks much, Rick!
A bit more on file corruption when downloading image files from
CollectionSpace (or any other source) via the command-line 'curl'
utility:
Curl's '-i" option (which spits out HTTP headers to the console,
and
for that reason is ordinarily very useful) seems to be what's
corrupting the JPEG images. When using that option, saved image
files begin with bits of extraneous text - the HTTP headers - which
corrupts them. Apparently adding the '--dump-header' option (which
dumps HTTP headers to a file, if given an optional filename
argument), counteracts that by suppressing the output of '-i', and
allows the images to be saved without corruption.
By implication, by omitting both options, -i and --dump-header,
you can still successfully save JPEG images via curl; I was just
now
able to do so under Mac OS X, with the saved image viewable in OS
X's Preview application.
curl -u admin@core.collectionspace.org:Administrator
5a6b-47f4-ace1/blob/content -o
PATH/TO/WHERE/ON/YOUR/MACHINE/YOU/WANT/TO/SAVE/THE/FILE/Southern_Ri
g
ht_Whale_8.jpg
Aron
On Fri, Sep 28, 2012 at 1:51 PM, Rick Jaffe rjaffe@berkeley.edu wrote:
Sébastien,
I've just had success downloading an image using cURL. It wouldn't
open in Preview.app on the Mac, though, until I added the option
that dumped the headers. Perhaps something similar is happening in
your case #2 below?
Here's the cURL command I ran against demo.collectionspace.org
(the
-o option saves the bits as a file):
curl --dump-header -i -u
admin@core.collectionspace.org:Administrator
-5a6b-47f4-ace1/blob/content
-o
PATH/TO/WHERE/ON/YOUR/MACHINE/YOU/WANT/TO/SAVE/THE/FILE/Southern_R
i
ght_Whale_8.jpg
Rick
Rick Jaffe
University of California Berkeley
IST-Research & Content Technologies
250-32 Earl Warren Hall (2195 Hearst) #4876 Berkeley, CA
94720-4876
(510) 642-0590
On Sep 26, 2012, at 7:26 AM, Sébastien Brossard wrote:
Dear all,
I'm currently working with reports on CS v2.6 (and iReport v4.0.2)
It worked pretty well until I had to insert dynamic images in the
report (i.e. media related to the CollectionObject shown in the
report).
There are two mains points here:
1/
Having created an Image field, I tried to access image through URL:
<reportElement positionType="Float" x="6" y="256"
width="165" height="115" isPrintWhenDetailOverflows="true"/>
<imageExpression class="java.awt.Image">
-4aae-b3ef/blob/derivatives/Medium/content
")]]>
</imageExpression> </image>
Unfortunately I got a blank "Authentication required" popup back
in
iReport's main windows.
Chris told me that I had to set HTTP' Authentication header to my
request but... how?! Where in iReport?!
After crawling the Web, results are poor (not to say worrying, as
this same problem has been on Stackoverflow's website for the past
two years waiting for an answer)
2/
Anyway, I managed to get the media by another mean (which is not
pretty, I must admit):
<reportElement positionType="Float" x="6" y="256"
width="165" height="115" isPrintWhenDetailOverflows="true"/>
<imageExpression class="java.awt.Image">
</imageExpression> </image>
But here, I'm still not able to show the picture in the report.
It seems like I've used all possible <imageExpression> type
combinations.
I used also an image loader (i.e.
"net.sf.jasperreports.engine.util.JRImageLoader.loadImage") but
without any
success.
(remark: using an URL pointing to a "jpeg" file works well).
Question is, what is exactly the format returned by this kind of
request
(i.e.
http://csdev-seb:8180/collectionspace/tenant/smk/download/f42214dd
-0599-4862-8cf2/Medium?)
Thank you by advance for your kindly help.
Best regards,
Sébastien
Talk mailing list
Talk mailing list
Talk mailing list
Talk@lists.collectionspace.org
http://lists.collectionspace.org/mailman/listinfo/talk_lists.collectio
nspace.org