From: RIOU Y. PP-D. S. <yva...@in...> - 2023-09-21 14:20:32
|
Good evening, First, I would like to thank you a lot for your hard work to offer us such an impressive API ! I'm new to Geotools and Java coding too so I apology for my question . I'm trying to display a wfs layer that was published in Geoserver within a MapContent (org.geotools.map.MapContent). For the symbology's wfs layer , i'm trying to parse a ysld file also stored in GeoServer and queried via the rest interface. But , I'm not able to correctly parse the file into a StyleLayerDescriptor object for further rendering. I'd be very grateful if a skilled guru would tell me what's wrong with my bad coding. I tried to add a newline , a tab , a space between each line read in inputLine but the result is always the same error : /Unable to turn ... into reader/ /while ((inputLine = in.readLine()) != null) {// // response.append(inputLine); // ///response.append('\n');///// } /Here is the ysld file content , the java class, the pom.xml and the errors reported : /----------------------------------------------------------------------------------------------------------------------------------------------------------------// //gare.ysld : //title: gare// //symbolizers:// //- point:// // size: 4// // symbols:// // - mark:// // shape: circle// // fill-color: '#ff00ff'// // //----------------------------------------------------------------------------------------------------------------------------------------------------------------// //affWFS.java: ///*// // * 2023 - Septembre// // *// // * API GeoTools// // *// // * Test affichage WFS GeoServer// //// //*/// // package sig;// //// //import java.io.BufferedReader;// //import java.io.InputStreamReader;// //import java.net.URL;// //import java.net.URLConnection;// //import java.util.Base64;// //import java.util.HashMap;// //import java.util.Map;// //import java.util.logging.Level;// //import java.util.logging.Logger;// //import org.geotools.data.DataStore;// //import org.geotools.data.DataStoreFinder;// //// //import org.geotools.data.simple.SimpleFeatureSource;// //import org.geotools.map.FeatureLayer;// //import org.geotools.map.Layer;// //import org.geotools.map.MapContent;// //import org.geotools.styling.Style;// //import org.geotools.styling.StyledLayer;// //import org.geotools.styling.StyledLayerDescriptor;// //import org.geotools.swing.JMapFrame;// //import org.geotools.ysld.Ysld;// //// //public class affWFS {// //// // private static final Logger LOGGER = org.geotools.util.logging.Logging.getLogger(affWFS.class);// // /**// // * GeoTools Quickstart demo application. Prompts the user for a shapefile and displays its// // * contents on the screen in a map frame// // * @param args// // * @throws java.lang.Exception// // */// // public static void main(String[] args) throws Exception {// // // display a data store file chooser dialog for shapefiles// // LOGGER.info( "Quickstart");// // LOGGER.config( "Welcome Developers");// // LOGGER.log(Level.INFO, "java.util.logging.config.file={0}", System.getProperty("java.util.logging.config.file"));// //// // String getCapabilities = "http://xxx.xx.x.xxx:8080/geoserver/wfs?REQUEST=GetCapabilities";// // String featureClass = "sde:gare";// //// // Map connectionParameters = new HashMap();// //connectionParameters.put("WFSDataStoreFactory:GET_CAPABILITIES_URL", getCapabilities );// //connectionParameters.put("WFSDataStoreFactory.WFS_STRATEGY.key", "geoserver");// //// // DataStore dataStore = DataStoreFinder.getDataStore( connectionParameters );// //// // SimpleFeatureSource featureSource = dataStore.getFeatureSource(featureClass);// //// // MapContent map = new MapContent();// // map.setTitle("Service OGS WFS " + featureClass);// //// // String urlString = "http://xxx.xx.x.xx:8080/geoserver/rest/workspaces/sde/styles/gare.ysld";// // String username = "xxxxx";// // String password = "xxxxxxx";// // String userpass = username + ":" + password;// // String basicAuth;// // basicAuth = "Basic " + new String(Base64.getEncoder().encode(userpass.getBytes()));// //// // URL url = new URL(urlString);// // URLConnection conn = url.openConnection();// // conn.setRequestProperty("Authorization" , basicAuth);// //// //// // BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));// //// // StringBuilder response = new StringBuilder();// // String inputLine;// //// // while ((inputLine = in.readLine()) != null) {// // response.append(inputLine);// // }// //// // in.close(); // //// // System.out.println(response);// //// // StyledLayerDescriptor gareSldDesc = Ysld.parse(response);// //// // StyledLayer gareStyle = gareSldDesc.getStyledLayers()[0];// //// // Style gareFsStyle = (Style)gareStyle;// //// // //Style style = SLD.createSimpleStyle(featureSource.getSchema());// // //Layer layer = new FeatureLayer(featureSource, style);// //// // Layer layer = new FeatureLayer(featureSource, gareFsStyle);// // map.addLayer(layer);// //// // // Now display the map// // JMapFrame.showMap(map);// //// // //SimpleFeatureType schema = data.getSchema( typeName );// //// // //FeatureSource<SimpleFeatureType, SimpleFeature> source = data.getFeatureSource( typeName );// // //System.out.println( "Metadata Bounds: " + source.getBounds() );// // }// //}// //// //----------------------------------------------------------------------------------------------------------------------------------------------------------------// //pom.xml : //<?xml version="1.0" encoding="UTF-8"?>// //// //<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>sig</groupId>// // <artifactId>consultation</artifactId>// // <version>1.0-SNAPSHOT</version>// //// // <name>consultation</name>// // <!-- FIXME change it to the project's website -->// // <url>http://www.example.com</url>// //// // <properties>// //<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>// //<maven.compiler.source>1.7</maven.compiler.source>// //<maven.compiler.target>1.7</maven.compiler.target>// //<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>// // <geotools.version>29.2</geotools.version>// // <maven.deploy.skip>true</maven.deploy.skip>// // </properties>// //// // <dependencies>// // <dependency>// // <groupId>junit</groupId>// // <artifactId>junit</artifactId>// // <version>4.13</version>// // <scope>test</scope>// // </dependency>// // <dependency>// // <groupId>org.geotools</groupId>// // <artifactId>gt-swing</artifactId>// // <version>${geotools.version}</version>// // </dependency>// // <dependency>// // <groupId>org.geotools</groupId>// // <artifactId>gt-opengis</artifactId>// // <version>${geotools.version}</version>// // </dependency>// // <dependency>// // <groupId>org.geotools</groupId>// // <artifactId>gt-ysld</artifactId>// // <version>${geotools.version}</version>// // </dependency>// // <dependency>// // <groupId>org.geotools</groupId>// // <artifactId>gt-epsg-hsql</artifactId>// // <version>${geotools.version}</version>// // </dependency>// // <dependency>// // <groupId>org.geotools</groupId>// // <artifactId>gt-wfs-ng</artifactId>// // <version>${geotools.version}</version>// // </dependency>// // </dependencies>// // <repositories>// // <repository>// // <id>osgeo</id>// // <name>OSGeo Release Repository</name>// //<url>https://repo.osgeo.org/repository/release/</url>// //<snapshots><enabled>false</enabled></snapshots>// //<releases><enabled>true</enabled></releases>// // </repository>// // <repository>// // <id>osgeo-snapshot</id>// // <name>OSGeo Snapshot Repository</name>// //<url>https://repo.osgeo.org/repository/snapshot/</url>// //<snapshots><enabled>true</enabled></snapshots>// //<releases><enabled>false</enabled></releases>// // </repository>// // </repositories>// // <build>// // <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->// // <plugins>// // <plugin>// // <inherited>true</inherited>// //<groupId>org.apache.maven.plugins</groupId>// //<artifactId>maven-compiler-plugin</artifactId>// // <version>3.10.1</version>// // <configuration>// // <source>1.8</source>// // <target>1.8</target>// // </configuration>// // </plugin>// // <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->// // <plugin>// //<artifactId>maven-clean-plugin</artifactId>// // <version>3.1.0</version>// // </plugin>// // <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->// // <plugin>// //<artifactId>maven-resources-plugin</artifactId>// // <version>3.0.2</version>// // </plugin>// // <plugin>// //<artifactId>maven-surefire-plugin</artifactId>// // <version>2.22.1</version>// // </plugin>// // <plugin>// //<artifactId>maven-jar-plugin</artifactId>// // <version>3.0.2</version>// // </plugin>// // <plugin>// //<artifactId>maven-install-plugin</artifactId>// // <version>2.5.2</version>// // </plugin>// // <plugin>// //<artifactId>maven-deploy-plugin</artifactId>// // <version>2.8.2</version>// // </plugin>// // <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->// // <plugin>// //<artifactId>maven-site-plugin</artifactId>// // <version>3.7.1</version>// // </plugin>// // <plugin>// //<artifactId>maven-project-info-reports-plugin</artifactId>// // <version>3.0.0</version>// // </plugin>// // </plugins>// // </pluginManagement>// // </build>// //</project>// //// //----------------------------------------------------------------------------------------------------------------------------------------------------------------// ////error report: //cd /home/yvan/NetBeansProjects/consultation; JAVA_HOME=/usr/lib/jvm/java-19-openjdk-amd64 /usr/lib/apache-netbeans/java/maven/bin/mvn -Dexec.vmArgs= "-Dexec.args=${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}" -Dexec.appArgs= -Dexec.mainClass=sig.affWFS -Dexec.executable=/usr/lib/jvm/java-19-openjdk-amd64/bin/java --no-transfer-progress process-classes org.codehaus.mojo:exec-maven-plugin:3.1.0:exec// //Scanning for projects...// //// //-----------------< sig:consultation >-----------------// //Building consultation 1.0-SNAPSHOT// // from pom.xml// //--------------------------------[ jar ]---------------------------------// //// //--- resources:3.0.2:resources (default-resources) @ consultation ---// //Using 'UTF-8' encoding to copy filtered resources.// //skip non existing resourceDirectory /home/yvan/NetBeansProjects/consultation/src/main/resources// //// //--- compiler:3.10.1:compile (default-compile) @ consultation ---// //Nothing to compile - all classes are up to date// //// //--- exec:3.1.0:exec (default-cli) @ consultation ---// //sept. 21, 2023 3:16:29 PM sig.affWFS main// //INFOS: Quickstart// //sept. 21, 2023 3:16:29 PM sig.affWFS main// //INFOS: java.util.logging.config.file=null// ////title: garesymbolizers:- point: size: 4 symbols: - mark: shape: circle fill-color: '#ff00ff' Exception in thread "main" java.lang.IllegalArgumentException: Unable to turn title: garesymbolizers:- point: size: 4 symbols: - mark: shape: circle fill-color: '#ff00ff' into reader// // at org.geotools.ysld.Ysld.reader(Ysld.java:79)// // at org.geotools.ysld.Ysld.parse(Ysld.java:156)// // at org.geotools.ysld.Ysld.parse(Ysld.java:181)// // at sig.affWFS.main(affWFS.java:89)// //Command execution failed.// //org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)// // at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)// // at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)// // at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:1000)// // at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:947)// // at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:471)// // at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)// // at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)// // at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)// // at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)// // at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)// // at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)// // at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)// // at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)// // at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)// // at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)// // at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)// // at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)// // at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)// // at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)// // at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)// // at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)// // at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)// // at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)// // at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)// // at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)// // at java.lang.reflect.Method.invoke (Method.java:578)// // at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)// // at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)// // at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)// // at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)// //------------------------------------------------------------------------// //BUILD FAILURE// //------------------------------------------------------------------------// //Total time: 6.140 s// //Finished at: 2023-09-21T15:16:33+02:00// //------------------------------------------------------------------------// //Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:exec (default-cli) on project consultation: Command execution failed.: Process exited with an error: 1 (Exit value: 1) -> [Help 1]// //// //To see the full stack trace of the errors, re-run Maven with the -e switch.// //Re-run Maven using the -X switch to enable full debug logging.// //// //For more information about the errors and possible solutions, please read the following articles:// //[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException/ Thank you for your help :) |