Issues with using text/plain as an input

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

Issues with using text/plain as an input

sammeek
Hi Benjamin,

I am attempting to send a plain text file as a text/plain from the java client and keep getting an error:

java.lang.IllegalArgumentException: error inserting node into execute request
        at org.n52.wps.client.ExecuteRequestBuilder.addComplexData(ExecuteRequestBuilder.java:153)
        at pillar.lbs.AuthoritativeDataClient.executeProcess(AuthoritativeDataClient.java:236)
        at pillar.lbs.AuthoritativeDataClient.testExecute(AuthoritativeDataClient.java:85)
        at pillar.lbs.AuthoritativeDataClient.main(AuthoritativeDataClient.java:416)
Caused by: org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA
        at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3511)
        at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1277)
        at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1264)
        at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
        at org.apache.xmlbeans.XmlObject$Factory.parse(XmlObject.java:688)
        at org.n52.wps.client.ExecuteRequestBuilder.addComplexData(ExecuteRequestBuilder.java:142)
        ... 3 more
Caused by: org.xml.sax.SAXParseException; systemId: file:; lineNumber: 1; columnNumber: 1; Unexpected element: CDATA
        at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.reportFatalError(Piccolo.java:1038)
        at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:723)
        at org.apache.xmlbeans.impl.st

The client code that I am using to do this is a follows:

GenericFileData inputMetFile = new GenericFileData(new File("<path to file> Sutton_Met_data.met"), "text/plain") ;

 inputs.put("inputMet", inputMetFile);

for (InputDescriptionType input : processDescription.getDataInputs()
                                .getInputArray()) {
                        String inputName = input.getIdentifier().getStringValue();
                        Object inputValue = inputs.get(inputName);
 
if(inputName.equals("inputMet")){
                               
                                IData data = new GenericFileDataBinding(new GenericFileData(
                                ((GenericFileData) inputValue).getBaseFile(true),"text/plain"));
                             
                                executeBuilder.addComplexData(inputName,
                                data, null, null, "text/plain");
                                }

For reference, the processdescription snippet is:

<Input maxOccurs="1" minOccurs="0">
<ows:Identifier>inputMet</ows:Identifier>
<ows:Title>inputMet</ows:Title>
<ComplexData>
<Default>
<Format>
<MimeType>text/plain</MimeType>
</Format>
</Default>
<Supported>
<Format>
<MimeType>text/plain</MimeType>
</Format>
</Supported>
</ComplexData>
</Input>

Any ideas?

Sam
Reply | Threaded
Open this post in threaded view
|

Re: Issues with using text/plain as an input

BenjaminPross
Hi Sam,

There seems to be an issue in the ExecuteRequestBuilder.

As a workaround, you could try to replace (ca. line 145):

     ComplexDataType data = input.addNewData().addNewComplexData();
     data.set(XmlObject.Factory.parse(stream));

with

     ComplexDataType data = input.addNewData().addNewComplexData();

     if(mimeType.contains("xml")){
         data.set(XmlObject.Factory.parse(stream));
     }else{

         String text = "";

         int i = -1;

         while((i = stream.read()) != -1){
             text = text + (char)i;
         }

         XmlString xml = XmlString.Factory.newInstance();

         xml.setStringValue(text);

         data.set(xml);
     }

Hope this helps.

Cheers,

Benjamin

Am 09.09.2014 10:19, schrieb sammeek:

> Hi Benjamin,
>
> I am attempting to send a plain text file as a text/plain from the java
> client and keep getting an error:
>
> java.lang.IllegalArgumentException: error inserting node into execute
> request
> at
> org.n52.wps.client.ExecuteRequestBuilder.addComplexData(ExecuteRequestBuilder.java:153)
> at
> pillar.lbs.AuthoritativeDataClient.executeProcess(AuthoritativeDataClient.java:236)
> at
> pillar.lbs.AuthoritativeDataClient.testExecute(AuthoritativeDataClient.java:85)
> at
> pillar.lbs.AuthoritativeDataClient.main(AuthoritativeDataClient.java:416)
> Caused by: org.apache.xmlbeans.XmlException: error: Unexpected element:
> CDATA
> at org.apache.xmlbeans.impl.store.Locale$SaxLoader.load(Locale.java:3511)
> at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1277)
> at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1264)
> at
> org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
> at org.apache.xmlbeans.XmlObject$Factory.parse(XmlObject.java:688)
> at
> org.n52.wps.client.ExecuteRequestBuilder.addComplexData(ExecuteRequestBuilder.java:142)
> ... 3 more
> Caused by: org.xml.sax.SAXParseException; systemId: file:; lineNumber: 1;
> columnNumber: 1; Unexpected element: CDATA
> at
> org.apache.xmlbeans.impl.piccolo.xml.Piccolo.reportFatalError(Piccolo.java:1038)
> at org.apache.xmlbeans.impl.piccolo.xml.Piccolo.parse(Piccolo.java:723)
> at org.apache.xmlbeans.impl.st
>
> The client code that I am using to do this is a follows:
>
> GenericFileData inputMetFile = new GenericFileData(new File("<path to file>
> Sutton_Met_data.met"), "text/plain") ;
>
>   inputs.put("inputMet", inputMetFile);
>
> for (InputDescriptionType input : processDescription.getDataInputs()
>                                  .getInputArray()) {
>                          String inputName =
> input.getIdentifier().getStringValue();
>                          Object inputValue = inputs.get(inputName);
>    
> if(inputName.equals("inputMet")){
>                                  
>                                   IData data = new GenericFileDataBinding(new
> GenericFileData(
>                                   ((GenericFileData)
> inputValue).getBaseFile(true),"text/plain"));
>                              
>                                   executeBuilder.addComplexData(inputName,
>                                   data, null, null, "text/plain");
>                                  }
>
> For reference, the processdescription snippet is:
>
> <Input maxOccurs="1" minOccurs="0">
> <ows:Identifier>inputMet</ows:Identifier>
> <ows:Title>inputMet</ows:Title>
> <ComplexData>
> <Default>
> <Format>
> <MimeType>text/plain</MimeType>
> </Format>
> </Default>
> <Supported>
> <Format>
> <MimeType>text/plain</MimeType>
> </Format>
> </Supported>
> </ComplexData>
> </Input>
>
> Any ideas?
>
> Sam
>
>
>
> --
> View this message in context: http://geoprocessing.forum.52north.org/Issues-with-using-text-plain-as-an-input-tp4025811.html
> Sent from the 52° North - Geoprocessing Community Forum mailing list archive at Nabble.com.
> _______________________________________________
> Geoprocessingservices mailing list
> [hidden email]
> http://list.52north.org/mailman/listinfo/geoprocessingservices
> http://geoprocessing.forum.52north.org


--
Benjamin Proß
Software Engineer
52°North Geoprocessing Community

52°North Initiative for Geospatial Open Source Software GmbH
Martin-Luther-King-Weg 24
Fon: +49-(0)-251–396371-42
Fax: +49-(0)-251–396371-11
[hidden email]
http://52north.org/

General Managers: Dr. Albert Remke, Dr. Andreas Wytzisk
Local Court Muenster HRB 10849

_______________________________________________
Geoprocessingservices mailing list
[hidden email]
http://list.52north.org/mailman/listinfo/geoprocessingservices
http://geoprocessing.forum.52north.org
Reply | Threaded
Open this post in threaded view
|

Re: Issues with using text/plain as an input

sammeek
Hi Benjamin,

Thank you for the reply, I can now parse the file. However, the file is altered when rebuilt on the server side:

Input file example:

weather.met.weather


latitude=       52.836726 (DECIMALDEGREES)
longitud=       -1.24681 (DECIMALDEGREES)

tav =   9.14 (oC)
amp =  11.93 (oC)

Year    Day     MaxT    MinT    Radn      Rain
()      ()      (oC)    (oC)    (MJ/m^2)  (mm)
2012    246     23.49   14.27   11.60     0
2012    247     21.36   9.33    12.96     0
2012    248     19.85   5.95    17.78     0.2

What the server receives after sent via client:

weather.met.weather


latitude=       52.836726 (DECIMALDEGREES)
longitud=       -1.24681 (DECIMALDEGREES)

tav =   9.14 (oC)
amp =  11.93 (oC)

Year    Day     MaxT    MinT    Radn      Rain
()      ()      (oC)    (oC)    (MJ/m^2)  (mm)
2012    246     23.49   14.27   11.60     0
2012    247     21.36   9.33    12.96     0
2012    248     19.85   5.95    17.78     0.2


Is this to do with the parser?

Sam
Reply | Threaded
Open this post in threaded view
|

Re: Issues with using text/plain as an input

BenjaminPross
This seems to be an issue with the encoding. is the ascii code for carriage return.
I could not reproduce this, however. Can you tell us some more about your setup, i.e. operating systems and Java Versions (client, server)?

Cheers,

Benjamin
Reply | Threaded
Open this post in threaded view
|

Re: Issues with using text/plain as an input

sammeek
Hi Benjamin

Tomcat 7, WPS 3.3 running on Ubuntu 14.04 for the server.

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

Client is being executed from Mac Mavericks:

java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

How do I pass the file as is avoiding the encoding? Failing that I can re-encode it server side although this is a little dirty!

Sam