52North / wps-client-lib

WPS client library written in Java. Support for WPS 1.0.0 and 2.0.
Apache License 2.0
6 stars 4 forks source link

java.lang.IllegalArgumentException: Unrecognized property 'escapeCharacters' #6

Closed kr1zz closed 5 years ago

kr1zz commented 5 years ago

I tried running the example, but it stopped early when parsing the response to GetCapabilities, with the following exception:

java.lang.IllegalArgumentException: Unrecognized property 'escapeCharacters'
    at com.ctc.wstx.api.CommonConfig.setProperty(CommonConfig.java:110)
    at com.ctc.wstx.stax.WstxOutputFactory.setProperty(WstxOutputFactory.java:153)
    at org.n52.iceland.util.XmlFactories.createOutputFactory(XmlFactories.java:112)
    at org.n52.iceland.util.XmlFactories.<init>(XmlFactories.java:50)
    at org.n52.svalbard.decode.stream.xml.AbstractElementXmlStreamReader.<init>(AbstractElementXmlStreamReader.java:42)
    at org.n52.geoprocessing.wps.client.xml.WPSResponseReader.<init>(WPSResponseReader.java:40)
    at org.n52.geoprocessing.wps.client.WPSClientSession.parseInputStreamToString(WPSClientSession.java:549)
    at org.n52.geoprocessing.wps.client.WPSClientSession.retrieveResponseOrExceptionReportInpustream(WPSClientSession.java:491)
    at org.n52.geoprocessing.wps.client.WPSClientSession.retrieveCapsViaGET(WPSClientSession.java:468)
    at org.n52.geoprocessing.wps.client.WPSClientSession.connect(WPSClientSession.java:169)
    at WPSClientExample.requestGetCapabilities(WPSClientExample.java:142)
    at WPSClientExample.testExecute(WPSClientExample.java:56)
    at WPSClientExample.main(WPSClientExample.java:176)

I tried also different WPS providers and changing the version from 2.0.0 to 1.0.0 but it doesn't seem to affect the issue.

$ java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

I tried it on a machine running Windows 10 Enterprise

bpross-52n commented 5 years ago

I cannot reproduce this. Can you provide more information about how you run the example? E.g. from an IDE like eclipse or from the command line?

kr1zz commented 5 years ago

I use eclipse.

It keeps throwing the same exception. However, I tried starting a new Maven project from scratch, and it works smoothly. I wonder if it is a configuration issue.

Please find below the pom.xml for the new small project, whereas here is the one from the project I was working on.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>kr1zzTmpTests</groupId>
    <artifactId>kr1zzPreliminaryTests</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Preliminary Tests</name>

    <dependencies>
        <dependency>
            <groupId>org.n52.geoprocessing</groupId>
            <artifactId>wps-client-lib</artifactId>
            <version>1.0.1</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>n52-releases</id>
            <name>52n Releases</name>
            <url>http://52north.org/maven/repo/releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>
bpross-52n commented 5 years ago

This is a dependency issue. The client example will work, if you add this line to the code (e.g. in as first statement in the main method):

System.setProperty("javax.xml.stream.XMLOutputFactory", "com.sun.xml.internal.stream.XMLOutputFactoryImpl");

For further explanation, you could look at the javadoc of the javax.xml.stream.XMLOutputFactory.newFactory()-method.

kr1zz commented 5 years ago

Great, it worked! :-) 🥇

For the sake of getting better at spotting issues, what line of reasoning allowed you to detect it?

bpross-52n commented 5 years ago

Well, this needed some debugging. I looked at the method org.n52.iceland.util.XmlFactories.createOutputFactory() In this method, a new XMLOutputFactory is created via XMLOutputFactory.newFactory(). The newFactory()-method has different ways to find a matching factory class. The first way is to look for a specific system property. So I simply used this to solve the issue.

Some more background: In your project, you have a woodstox dependency that has the WstxOutputFactory class. I didn't thoroughly check why, but this class is found and used by the newFactory()-method I mentioned above. I checked what factory was found and used when the client example worked and this was com.sun.xml.internal.stream.XMLOutputFactoryImpl. So, I used this for the value of the javax.xml.stream.XMLOutputFactor system property.