Passing XML as parameter in HTTP service call from external system

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Passing XML as parameter in HTTP service call from external system

Alexander Niemann
Hello everyone,

I encountered a problem calling a HTTP service from an external system.
After struggling quite a while I found an easy way to solve it - but that
includes adding functionality to OFBiz's XmlSerializer. After all, I'm not
sure how clever I've been and if there isn't a better way to do it. May be
I'm barking of the wrong tree ... so any suggestions are very welcome!

What I need: The external system wants to send master data to our OFBiz.
This has to be done via HTTP request, the data is wrapped in a XML.

What I think I did right: I wrote a Java service expecting the XML as
parameter. The service uses a custom deserializer to unwrap the data and
process it. This is the service definition:

    <service name="importProduct" engine="java" export="true"
        location="org.ofbiz.dgverlag.product.DgvProductImportServices"
invoke="importProduct">
        <description>Import (i.e. create or update) a product
</description>
                <attribute name="productXML" type="String" mode="IN"
optional="false"/>
    </service>

Everything's working fine so far. Now the service should become callable
by HTTP, so I added another service definition as HTTP wrapper:

    <service name="testHttpImportProduct" engine="http" export="true"
            location="http://localhost:8080/webtools/control/httpService"
invoke="importProduct">
        <description>HTTP service wrapper around blabla</description>
        <attribute name="productXML" type="String" mode="IN" optional=
"false"/>
    </service>

Now I can call the service via HTTP. Reading the code I found out that I
have to add at least 2 parameters to the request, namely "serviceName" and
"serviceContext". "serviceName" contains "testHttpImportProduct" and
"serviceContext" is a XML containing a map of the expected attributes,
i.e. "productXML".

I stumbled building the XML context because one XML must be put into the
other one. I wouldn't expect that to be much of a problem normally, but it
is if you have to use an attribute. The <ofbiz-ser> format contains an
element named <std-String> but that's of no use because the parser wants
to parse the contained string. Normally I would use a CDATA section to
stop the parser from parsing the contained XML but that doesn't work with
attributes. Something like

<map-Key><std-String value="productXML"/></map-Key>
<map-Value><std-String value="<![CDATA[<?xml version="1.0"
...."/><map-Key>

just doesn't work  :-(

So I took org.ofbiz.entity.serialize.XmlSerializer and extended
deserializeCustom() by a new custom element named "cus-string". Within
this new element I can simply use CDATA and suddenly all works well:

<?xml version="1.0" encoding="UTF-8"?>
<ofbiz-ser>
  <map-HashMap>
    <map-Entry>
      <map-Key><std-String value="productXML"/></map-Key>
      <map-Value><cus-string><![CDATA[<?xml version="1.0"
encoding="UTF-8"?> ... quite complex XML goes here ...
]]></cus-string></map-Value>
    </map-Entry>
 </map-HashMap>
</ofbiz-ser>

Does anybody have a better solution? Did I do something wrong? Or do you
think this is a extension to the OFBiz framework someone had to come up
with sooner or later?

Sorry for the lengthy mail and thanks in advance


Alexander Niemann
Consultant AEW
Agrenon GmbH
Johanniskirchplatz 6
D-33615 Bielefeld
Fon: +49 521 5247-0
Fax: +49 521 5247-250
Mobil: +49 160 97 25 58 58


Company and Management Headquarters:
Agrenon GmbH, Johanniskirchplatz 6, D-33615 Bielefeld, Fon: +49 521 5247-0, Fax: +49 521 5247-250, www.agrenon.com

Court Registration: Amtsgericht Bielefeld HRB 36795
Chief Executive Officer: Dirk Osterkamp

 
----------------------------------------------------------------------------------------------------
This e-mail may contain trade secrets or privileged, undisclosed, or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying, or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation.
----------------------------------------------------------------------------------------------------