Problems when PDF document transfers through WebService

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems when PDF document transfers through WebService

cheney zhao
Hi, All,
I faced a strange problem when viewing PDF files.
When I view the pdf file in IE directly through the following xpl:
            <p:processor name="oxf:url-generator">
                <p:input name="config" transform="oxf:unsafe-xslt" href="#instance">
                    <config xsl:version="2.0">
                        <url>file:\\temp\test.pdf</url>
                        <content-type>application/pdf</content-type>
                    </config>
                </p:input>
                <p:output name="data" ref="data" />
            </p:processor>
It works fine.  But when I make the xpl above as a webservice, call this webservice by the Document-Style in the following xpl:

<p:processor name="oxf:delegation">
        <p:input name="interface" href="#service-interface"/>
        <p:input name="call" href="#service-call"/>
        <p:output name="data" id="service-result" debug="data"/>
    </p:processor>
     
    <p:processor name="oxf:xslt">
        <p:input name="data" href="#service-result"/>
        <p:input name="config">
            <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                <xsl:template match="*">
                  <xsl:element name="{local-name()}">
                    <xsl:copy-of select="@*"/>
                    <xsl:apply-templates/>
                  </xsl:element>
                </xsl:template>
            </xsl:stylesheet>
        </p:input>
        <p:output name="data" id="test" ref="data"/>
    </p:processor>
The output of two pipelines are same:
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:base64Binary" content-type="application/pdf" last-modified="Tue, 16 Oct 2007 08:09:51 GMT">JVBERi0xLjUKJeLjz9MKMSAwIG9iaiA8PC9UeXBlL01ldGFkYXRhL0xlbmd0aC</document>
But I got the exception when invoking by this style:

ERROR ProcessorService  - Exception at line 327, column 53 of oxf:/config/epilogue-servlet.xpl (executing processor: name='{http://www.orbeon.com/oxf/processors}http-serializer')
java.lang.NullPointerException
        at org.orbeon.oxf.processor.serializer.BinaryTextContentHandler.characters(BinaryTextContentHandler.java:177)
        at org.orbeon.oxf.xml.SAXStore.replay(SAXStore.java:197)
Is there something changed during the transfer of webservice? I'm confused when the output of two pipelines have no difference?


Reply | Threaded
Open this post in threaded view
|

Re: Problems when PDF document transfers through WebService

cheney zhao
Thanks for your useful explanation!
Reply | Threaded
Open this post in threaded view
|

Re: Problems when PDF document transfers through WebService

Alessandro Vernet
Administrator
In reply to this post by cheney zhao
On Oct 27, 2008, at 8:43 AM, cheney zhao <[hidden email]> wrote:

> I faced a strange problem when viewing PDF files.
> When I view the pdf file in IE directly through the following xpl:
>            <p:processor name="oxf:url-generator">
>                <p:input name="config" transform="oxf:unsafe-xslt"
> href="#instance">
>                    <config xsl:version="2.0">
>                        <url>file:\\temp\test.pdf</url>
>                        <content-type>application/pdf</content-type>
>                    </config>
>                </p:input>
>                <p:output name="data" ref="data" />
>            </p:processor>
> It works fine.  But when I make the xpl above as a webservice, call
> this
> webservice by the Document-Style in the following xpl:
> [...]
> The output of two pipelines are same:
> <document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="xs:base64Binary" content-type="application/pdf"
> last-modified="Tue, 16 Oct 2007 08:09:51
> GMT">JVBERi0xLjUKJeLjz9MKMSAwIG9iaiA8PC9UeXBlL01ldGFkYXRhL0xlbmd0aC</
> document>
> But I got the exception when invoking by this style:
>
> ERROR ProcessorService  - Exception at line 327, column 53 of
> oxf:/config/epilogue-servlet.xpl (executing processor:
> name='{http://www.orbeon.com/oxf/processors}http-serializer')
> java.lang.NullPointerException
The pipeline that reads the PDF produces an XML document that contains
the binary PDF encoded in base64. This is how binary data can be
passed around in pipelines, since all the inputs and outputs of
pipelines and processors have to be XML. Now if your pipeline is
referenced from the page flow (view="pipeline.xpl"), then the output
goes to the epilogue which understand this as an XML document and
returns the binary data in the HTTP response instead of the XML
document.

When you expose the XPL as a service you want the XML document to be
returned. There are a few ways to do this. Maybe the simplest is to
remove the xsi:type attribute on the document produced by the URL
generator, say with an XSLT stylesheet just after the URL generator.

Alex
--
Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
Orbeon's Blog: http://www.orbeon.com/blog/
Personal Blog: http://avernet.blogspot.com/
Twitter - http://twitter.com/avernet


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Problems when PDF document transfers through WebService

cheney zhao
Thank you , Alex, I have fixed this problem.

Alessandro Vernet wrote
On Oct 27, 2008, at 8:43 AM, cheney zhao <cauzcy@126.com> wrote:
> I faced a strange problem when viewing PDF files.
> When I view the pdf file in IE directly through the following xpl:
>            <p:processor name="oxf:url-generator">
>                <p:input name="config" transform="oxf:unsafe-xslt"
> href="#instance">
>                    <config xsl:version="2.0">
>                        <url>file:\\temp\test.pdf</url>
>                        <content-type>application/pdf</content-type>
>                    </config>
>                </p:input>
>                <p:output name="data" ref="data" />
>            </p:processor>
> It works fine.  But when I make the xpl above as a webservice, call
> this
> webservice by the Document-Style in the following xpl:
> [...]
> The output of two pipelines are same:
> <document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="xs:base64Binary" content-type="application/pdf"
> last-modified="Tue, 16 Oct 2007 08:09:51
> GMT">JVBERi0xLjUKJeLjz9MKMSAwIG9iaiA8PC9UeXBlL01ldGFkYXRhL0xlbmd0aC</
> document>
> But I got the exception when invoking by this style:
>
> ERROR ProcessorService  - Exception at line 327, column 53 of
> oxf:/config/epilogue-servlet.xpl (executing processor:
> name='{http://www.orbeon.com/oxf/processors}http-serializer')
> java.lang.NullPointerException

The pipeline that reads the PDF produces an XML document that contains
the binary PDF encoded in base64. This is how binary data can be
passed around in pipelines, since all the inputs and outputs of
pipelines and processors have to be XML. Now if your pipeline is
referenced from the page flow (view="pipeline.xpl"), then the output
goes to the epilogue which understand this as an XML document and
returns the binary data in the HTTP response instead of the XML
document.

When you expose the XPL as a service you want the XML document to be
returned. There are a few ways to do this. Maybe the simplest is to
remove the xsi:type attribute on the document produced by the URL
generator, say with an XSLT stylesheet just after the URL generator.

Alex
--
Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
Orbeon's Blog: http://www.orbeon.com/blog/
Personal Blog: http://avernet.blogspot.com/
Twitter - http://twitter.com/avernet


--
You receive this message as a subscriber of the ops-users@ow2.org mailing list.
To unsubscribe: mailto:ops-users-unsubscribe@ow2.org
For general help: mailto:sympa@ow2.org?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws


-----
Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
Orbeon's Blog: http://www.orbeon.com/blog/
Personal Blog: http://avernet.blogspot.com/
Twitter - http://twitter.com/avernet