52North / WPS

**DEPRECATED** The 52°North Web Processing Service enables the deployment of geo-processes on the web in a standardized way.
GNU General Public License v2.0
63 stars 55 forks source link

WPS Client : Complex Data as non XML String #254

Open Gnatit opened 7 years ago

Gnatit commented 7 years ago

Hello,

When using the WPS Client API, I have a problem using the method addComplexData of class ExecuteRequestBuilder (the one using an IData object as value). In case the generator used returns a stream that is no XML, the method setComplexData will fail to read the stream.

Here is an example :

Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0));
IData data = new JTSGeometryBinding(geometry);
executeBuilder.addComplexData("start", data, null, null, "application/wkt");

The JTSGeometryBinding is used with WKTGenerator to generate a WKT description of the geometry (i.e. POINT(0 0)). This non XML String is not parsed by method setComplexData. So an empty input is generated.

Error is due to this code :

try {
    data.set(XmlObject.Factory.parse(stream));
} catch (XmlException e) {

LOGGER.warn("error parsing data stream as xml node, trying to parse data as xs:string");

String text = "";

int i = -1;

try {
    while ((i = stream.read()) != -1) {
        text = text + (char) i;
    }
} catch (IOException e1) {
    LOGGER.error("error parsing stream", e);
}

The stream is read twice but the position is not reseted so the second time, stream is empty. A solution would be to convert stream to a String before parsing.

If this is not clear, I can provide additional infos. Thanks for your work