How to wrap a text/plain response to xforms:submission so it becomes XML

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

How to wrap a text/plain response to xforms:submission so it becomes XML

Mahender Didwania
Hi,

I work with an XML DB which, for certain operations, returns non-XML text/plain responses.  Those operations are invoked using xforms submissions processor and I get this error in the logs:

ERROR XFormsServer  -                   xforms-submit-error - setting throwable {throwable: "org.orbeon.oxf.xforms.submission.XFormsSubmissionException:  (processing instance replacement): Body received with non-XML media type for replace="instance": text/plain
null, line -1, column -1: Body received with non-XML media type for replace="instance": text/plain

Also, as a side-effect, the document which was submitted using xforms:submissions is populated in the response.  I actually want to send the text/plain status response I receive from XML DB as the pipeline output.

I tried replace="text" targetref="/" on the submission but that does not help.

Any pointers on how to make xforms submissions processor happy with non-XML responses?

Thanks,
Mahender.


--
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: How to wrap a text/plain response to xforms:submission so it becomes XML

Erik Bruchez
Administrator
Mahender,

The way oxf:xforms-submission works is that if an error occurs, the
same instance that was passed in is returned.

You can't use targetref="/", because that would attempt to store text
at the root of an XML document, which is not allowed. Also, do I
understand right that in some cases, XML is returned, and in others,
text that is not XML?

You could try something like this:

<xforms:action ev:event="xforms-submit-error">
  <xforms:insert context="/" origin="xxforms:element('text')"/>
  <xforms:setvalue ref="/*" value="event('response-body')"/>
</xforms:action

-Erik

On Fri, Dec 17, 2010 at 2:58 PM, Mahender Didwania
<[hidden email]> wrote:

> Hi,
>
> I work with an XML DB which, for certain operations, returns non-XML text/plain responses.  Those operations are invoked using xforms submissions processor and I get this error in the logs:
>
> ERROR XFormsServer  -                   xforms-submit-error - setting throwable {throwable: "org.orbeon.oxf.xforms.submission.XFormsSubmissionException:  (processing instance replacement): Body received with non-XML media type for replace="instance": text/plain
> null, line -1, column -1: Body received with non-XML media type for replace="instance": text/plain
>
> Also, as a side-effect, the document which was submitted using xforms:submissions is populated in the response.  I actually want to send the text/plain status response I receive from XML DB as the pipeline output.
>
> I tried replace="text" targetref="/" on the submission but that does not help.
>
> Any pointers on how to make xforms submissions processor happy with non-XML responses?
>
> Thanks,
> Mahender.
>
>
> --
> 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
>
>


--
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: Re: How to wrap a text/plain response to xforms:submission so it becomes XML

Mahender Didwania
In reply to this post by Mahender Didwania
Hi,

>Also, do I
understand right that in some cases, XML is returned, and in others,
text that is not XML?

Yes.

>You could try something like this:

<xforms:action ev:event="xforms-submit-error">
  <xforms:insert context="/" origin="xxforms:element('text')"/>
  <xforms:setvalue ref="/*" value="event('response-body')"/>
</xforms:action

--

That doesn't seem to work, especially because it does not modify the response, only the default-instance...please correct me if that is not the case.  Could not find xxforms:element in the docs...(where) is it documented (for more information on it)?

I want to capture the responses as returned by XML DB, but am stuck due to two things:
a) text/plain responses lead to xforms-submit-error and I have not yet been able to find a way to encapsulate that plain-text response in XML (could not find a processor that takes a plain text input and outputs XML (found the reverse though))
b) response is not preserved by xforms processor in case of an error, it is replaced with the document submitted

I actually want to give status report to the user incrementally which means that the XPL output (once I am able to find a workaround for a) and b) above) should flush out to browser incrementally - how to achieve that?

Thanks,
Mahender.


--
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: Re: How to wrap a text/plain response to xforms:submission so it becomes XML

Mahender Didwania
Further to the email below, I have found that xforms submissions processor actually does not throw an error if response is set to none.

However, in my XPL pipeline, I carry out xforms submissions a few times and I want to present the user (by way of output or textarea element on the original xform which called the XPL) with the actual result sent by XML DB as soon as as a submission finishes...

so, one xforms submission deletes a collection...user is notified, 2nd xforms submission creates a collection...user notification is updated with the response received, 3rd and 4th xforms submissions retrieve a doc from a URL (say CMS) and add that doc to the collection respectively...user notification is again updated with the results...

It all works, except the user-notification update/'actual' XML DB response capture via XPL output (for text/plain responses; and whether or not the submission succeeded).

Thanks,
Mahender.


----- Original Message -----
From: "Mahender Didwania" <[hidden email]>
To: [hidden email]
Sent: Saturday, December 18, 2010 10:40:02 PM GMT +00:00 GMT Britain, Ireland, Portugal
Subject: Re: [ops-users] Re: How to wrap a text/plain response to xforms:submission so it becomes XML

Hi,

>Also, do I
understand right that in some cases, XML is returned, and in others,
text that is not XML?

Yes.

>You could try something like this:

<xforms:action ev:event="xforms-submit-error">
  <xforms:insert context="/" origin="xxforms:element('text')"/>
  <xforms:setvalue ref="/*" value="event('response-body')"/>
</xforms:action

--

That doesn't seem to work, especially because it does not modify the response, only the default-instance...please correct me if that is not the case.  Could not find xxforms:element in the docs...(where) is it documented (for more information on it)?

I want to capture the responses as returned by XML DB, but am stuck due to two things:
a) text/plain responses lead to xforms-submit-error and I have not yet been able to find a way to encapsulate that plain-text response in XML (could not find a processor that takes a plain text input and outputs XML (found the reverse though))
b) response is not preserved by xforms processor in case of an error, it is replaced with the document submitted

I actually want to give status report to the user incrementally which means that the XPL output (once I am able to find a workaround for a) and b) above) should flush out to browser incrementally - how to achieve that?

Thanks,
Mahender.


--
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: Re: Re: How to wrap a text/plain response to xforms:submission so it becomes XML

Erik Bruchez
Administrator
In reply to this post by Mahender Didwania
> That doesn't seem to work, especially because it does not modify the response, only the default-instance...please correct me if that is not the case.

In xforms-submission.xpl (the implementation of
oxf:xforms-submission), the default instance should be the same as the
response instance.

> Could not find xxforms:element in the docs...(where) is it documented (for more information on it)?

http://wiki.orbeon.com/forms/doc/developer-guide/xforms-xpath-functions#TOC-xxforms:element-

> I want to capture the responses as returned by XML DB, but am stuck due to two things:
> a) text/plain responses lead to xforms-submit-error and I have not yet been able to find a way to encapsulate that plain-text response in XML (could not find a processor that takes a plain text input and outputs XML (found the reverse though))
> b) response is not preserved by xforms processor in case of an error, it is replaced with the document submitted
>
> I actually want to give status report to the user incrementally which means that the XPL output (once I am able to find a workaround for a) and b) above) should flush out to browser incrementally - how to achieve that?

I see in your next message that you now have a solution.

This said, I think a solution to the above would probably be to always
store the result as text first with replace="text", but also store the
result content-type, and then use saxon:parse() to produce actual XML
if the content-type is XML. The main issue as you pointed out is that
oxf:xforms-submission uses only one instance for input/output (except
in the case of shared instances but that's another story):

https://github.com/orbeon/orbeon-forms/blob/master/src/resources-packaged/ops/xforms/xforms-submission.xpl

xforms-submission.xpl could be improved to do this better I think.

-Erik


--
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: Re: Re: Re: How to wrap a text/plain response to xforms:submission so it becomes XML

Mahender Didwania
In reply to this post by Mahender Didwania
Hi,

>In xforms-submission.xpl (the implementation of
oxf:xforms-submission), the default instance should be the same as the
response instance.

Okay, maybe it did not work because of the '/' being used as context (judging from orbeon log).  The following works so far as context resolution is concerned, however, as in the code below, I am trying to put the result of submission failure (it is not a failure, merely a text/plain response, but submissions processor treats it as a failure) in a different input (I connect that to the pipeline output).  But I get the error: org.orbeon.saxon.trans.XPathException: Failed to load document input:results2.

          <p:processor name="oxf:xforms-submission">
            <p:input name="submission" transform="oxf:xslt" href="#TargetURL">
              <xforms:submission xsl:version="2.0" method="post" action="{/TargetURL/text()}" xxforms:username="admin" xxforms:password="admin"  mediatype="text/xml;">
                <xforms:message ev:event="xforms-submit-error" level="xxforms:log-error">A submission error occurred:
                  <xforms:output value="event('error-type')"/>
                </xforms:message>
                <xforms:action ev:event="xforms-submit-error">
                   <!-- this works but modifies the default-instance
                   <xforms:insert context="fn:context()" origin="xxforms:element('Result')"/>
                   <xforms:setvalue ref="fn:context()/Result"
                   -->
                   <!-- this does not work -->
                   <xforms:insert context="fn:doc('input:results2')/Results" origin="xxforms:element('Result')"/>
                   <xforms:setvalue ref="fn:doc('input:results2')/Results/Result"

                   value="fn:choose(fn:string-length('response-reason-phrase')>0,fn:string-join((event('response-status-code') cast as xs:string,event('resource-uri'),event('response-body')),':'),'Dont know')"/>
                </xforms:action>
              </xforms:submission>
            </p:input>
            <p:input name="request" href="#xml"/>
            <p:input name="results2" href="#results"/>
            <p:output name="response" ref="output2"/>
          </p:processor>

Where it works, replacing <xforms:setvalue ref="fn:context()/Result" with <xforms:setvalue ref="fn:context()/*" leads to no change in the outcome.  The result is the creation of an additional <Result> element in the default-instance.

#results at the time of invoking the above processor is:
        <p:processor name="oxf:identity">
                <p:input name="data">
                        <Results />
                </p:input>
                <p:output name="data" id="results"/>
        </p:processor>

Regards,
Mahender


--
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: Re: Re: Re: Re: How to wrap a text/plain response to xforms:submission so it becomes XML

Erik Bruchez
Administrator
Mahender,

input:results2 won't work: the XForms processor used does not support
extra inputs, and anyway, modifying an output document wouldn't do
much good.

You could also try something like this:

<root>
  <in>
    <document-to-submit>...</document-to-submit>
  </in>
  <out/>
</root>

Then use ref="/root/in/*" on the submission.

Upon successful  XML response, the output will be the XML document
returned by the service.

Upon "unsucccessful" text response, the output will look like:

<root>
  <in>
    <document-to-submit>...</document-to-submit>
  </in>
  <out>Response text</out>
</root>

You could also delete the <in> element upon xforms-submit-error.

Not sure if that helps. It is not too pretty for sure!

-Erik

On Tue, Dec 21, 2010 at 7:43 AM, Mahender Didwania
<[hidden email]> wrote:

> Hi,
>
>>In xforms-submission.xpl (the implementation of
> oxf:xforms-submission), the default instance should be the same as the
> response instance.
>
> Okay, maybe it did not work because of the '/' being used as context (judging from orbeon log).  The following works so far as context resolution is concerned, however, as in the code below, I am trying to put the result of submission failure (it is not a failure, merely a text/plain response, but submissions processor treats it as a failure) in a different input (I connect that to the pipeline output).  But I get the error: org.orbeon.saxon.trans.XPathException: Failed to load document input:results2.
>
>          <p:processor name="oxf:xforms-submission">
>            <p:input name="submission" transform="oxf:xslt" href="#TargetURL">
>              <xforms:submission xsl:version="2.0" method="post" action="{/TargetURL/text()}" xxforms:username="admin" xxforms:password="admin"  mediatype="text/xml;">
>                <xforms:message ev:event="xforms-submit-error" level="xxforms:log-error">A submission error occurred:
>                  <xforms:output value="event('error-type')"/>
>                </xforms:message>
>                <xforms:action ev:event="xforms-submit-error">
>                   <!-- this works but modifies the default-instance
>                   <xforms:insert context="fn:context()" origin="xxforms:element('Result')"/>
>                   <xforms:setvalue ref="fn:context()/Result"
>                   -->
>                   <!-- this does not work -->
>                   <xforms:insert context="fn:doc('input:results2')/Results" origin="xxforms:element('Result')"/>
>                   <xforms:setvalue ref="fn:doc('input:results2')/Results/Result"
>
>                   value="fn:choose(fn:string-length('response-reason-phrase')>0,fn:string-join((event('response-status-code') cast as xs:string,event('resource-uri'),event('response-body')),':'),'Dont know')"/>
>                </xforms:action>
>              </xforms:submission>
>            </p:input>
>            <p:input name="request" href="#xml"/>
>            <p:input name="results2" href="#results"/>
>            <p:output name="response" ref="output2"/>
>          </p:processor>
>
> Where it works, replacing <xforms:setvalue ref="fn:context()/Result" with <xforms:setvalue ref="fn:context()/*" leads to no change in the outcome.  The result is the creation of an additional <Result> element in the default-instance.
>
> #results at the time of invoking the above processor is:
>        <p:processor name="oxf:identity">
>                <p:input name="data">
>                        <Results />
>                </p:input>
>                <p:output name="data" id="results"/>
>        </p:processor>
>
> Regards,
> Mahender
>
>
> --
> 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
>
>


--
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: Re: Re: Re: Re: Re: How to wrap a text/plain response to xforms:submission so it becomes XML

Mahender Didwania
In reply to this post by Mahender Didwania
>input:results2 won't work: the XForms processor used does not support
extra inputs

I thought maybe due to embedded xslt transformation, the extra input will be passed further on as a user-defined-input to the xslt processor, clearly that's not the case.

>You could also try something like this:

<root>
  <in>
    <document-to-submit>...</document-to-submit>
  </in>
  <out/>
</root>

Then use ref="/root/in/*" on the submission.
---

I achieved (kind-of) somewhat the desired output using the code I posted earlier plus:

<p:processor name="oxf:identity">
    <p:input name="data" href="aggregate('PopulateXMLDBResults',#output#xpointer(//Result))"/>
    <p:output name="data" ref="data"/>
</p:processor>

It'll sort-of work as long as there are no other Result elements in the data than the ones I created (I could rename Result to something else more likely to be unique, but I do not have a Result element in any of data I attempt to load to XML DB).

Many thanks for your ideas Erik, much appreciated.

Regards,
Mahender.


--
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