diff --git a/app/wms/pom.xml b/app/wms/pom.xml
index 7b388ae..4089ec6 100644
--- a/app/wms/pom.xml
+++ b/app/wms/pom.xml
@@ -6,7 +6,7 @@
org.orbisgis.server
orbiswms-lib
jar
- 1.0-SNAPSHOT
+ 1.0.1-SNAPSHOT
orbiswms-lib
http://www.orbisgis.org
diff --git a/app/wms/src/main/java/org/orbisgis/server/wms/GetCapabilitiesHandler.java b/app/wms/src/main/java/org/orbisgis/server/wms/GetCapabilitiesHandler.java
index cfaed49..80ac3cd 100644
--- a/app/wms/src/main/java/org/orbisgis/server/wms/GetCapabilitiesHandler.java
+++ b/app/wms/src/main/java/org/orbisgis/server/wms/GetCapabilitiesHandler.java
@@ -56,10 +56,9 @@
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.*;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.cts.crs.CRSException;
import org.cts.crs.CoordinateReferenceSystem;
+import org.cts.registry.RegistryException;
/**
* Creates the answer to a getCapabilities request and writes it into the output
@@ -364,8 +363,11 @@ public void sourceAdded(SourceEvent e) {
}
layerMap.put(name, layer);
} catch (NoSuchTableException ex) {
+ LOGGER.error("Cannot find the data "+ name, ex);
} catch (DataSourceCreationException ex) {
+ LOGGER.error("Cannot find the data "+ name, ex);
} catch (DriverException ex) {
+ LOGGER.error("Cannot acces to the data "+ name, ex);
}
}
}
diff --git a/app/wms/src/main/java/org/orbisgis/server/wms/GetFeatureInfoHandler.java b/app/wms/src/main/java/org/orbisgis/server/wms/GetFeatureInfoHandler.java
index a990fe9..1b5415b 100644
--- a/app/wms/src/main/java/org/orbisgis/server/wms/GetFeatureInfoHandler.java
+++ b/app/wms/src/main/java/org/orbisgis/server/wms/GetFeatureInfoHandler.java
@@ -84,9 +84,20 @@ public void getFeatureInfo(GetFeatureInfoParameters params, OutputStream output,
params.getSld(), params.getExceptionsFormat(), output, wmsResponse, serverStyles);
int width = params.getWidth();
int height = params.getHeight();
+ int i = params.getI();
+ int j = params.getJ();
+
+ if(i<=0 || i>=width){
+ throw new WMSException("GetFeatureInfo request contains invalid I value. ");
+ }
+
+ if(j<=0 || j>=height){
+ throw new WMSException("GetFeatureInfo request contains invalid J value. ");
+ }
+
double[] bBox = params.getbBox();
DataSourceFactory dsf = Services.getService(DataManager.class).getDataSourceFactory();
- Envelope env = getEnvelopeRequest(bBox,width, height, params.getI(), params.getJ());
+ Envelope env = getEnvelopeRequest(bBox,width, height, i, j);
ILayer[] children = layers.getChildren();
IndexManager im = dsf.getIndexManager();
for(ILayer c : children){
diff --git a/app/wms/src/main/java/org/orbisgis/server/wms/GetMapParameters.java b/app/wms/src/main/java/org/orbisgis/server/wms/GetMapParameters.java
index 42d6144..460e761 100644
--- a/app/wms/src/main/java/org/orbisgis/server/wms/GetMapParameters.java
+++ b/app/wms/src/main/java/org/orbisgis/server/wms/GetMapParameters.java
@@ -35,33 +35,76 @@
* @author Alexis Guéganno.
*/
public class GetMapParameters {
+ /**
+ * Mandatory
+ */
public static final String VERSION = "VERSION";
+ /**
+ * Mandatory
+ */
public static final String REQUEST = "REQUEST";
+ /**
+ * Shall be present if SLD is absent, and absent if SLD is present
+ */
public static final String LAYERS = "LAYERS";
+ /**
+ * Shall be present if SLD is absent, and absent if SLD is present
+ */
public static final String STYLES = "STYLES";
+ /**
+ * Shall be present if STYLES and LAYERS are absent, and absent if STYLES and LAYERS are present
+ */
public static final String SLD = "SLD";
+ /**
+ * Mandatory
+ */
public static final String CRS = "CRS";
+ /**
+ * Mandatory
+ */
public static final String BBOX = "BBOX";
+ /**
+ * Mandatory
+ */
public static final String WIDTH = "WIDTH";
+ /**
+ * Mandatory
+ */
public static final String HEIGHT = "HEIGHT";
+ /**
+ * Mandatory
+ */
public static final String FORMAT = "FORMAT";
+ /**
+ * Optional
+ */
public static final String TRANSPARENT = "TRANSPARENT";
+ /**
+ * Optional
+ */
public static final String BGCOLOR = "BGCOLOR";
+ /**
+ * Optional
+ */
public static final String EXCEPTIONS = "EXCEPTIONS";
+ /**
+ * Optional
+ */
public static final String TIME = "TIME";
public static final String ELEVATION = "ELEVATION";
public static final Set MANDATORY_PARAMETERS;
static {
Set temp = new HashSet();
- temp.add(LAYERS);
- temp.add(STYLES);
temp.add(BBOX);
temp.add(WIDTH);
temp.add(HEIGHT);
temp.add(FORMAT);
temp.add(CRS);
MANDATORY_PARAMETERS = Collections.unmodifiableSet(temp);
+ for(String s : MANDATORY_PARAMETERS){
+ System.out.println("Mandatory : "+s);
+ }
}
@@ -97,26 +140,53 @@ public GetMapParameters(Map queryParameters) throws WMSExcepti
throw new WMSException("The following parameter is mandatory: "+s);
}
}
+ if(!qp.containsKey(SLD)){
+ if(!qp.containsKey(LAYERS) || !qp.containsKey(STYLES)){
+ throw new WMSException("Both layers and styles must be defined when SLD is absent");
+ }
+ } else {
+ if(qp.containsKey(LAYERS) || qp.containsKey(STYLES)){
+ throw new WMSException("Both layers and styles must not be defined when SLD is present");
+ }
+ }
crs = qp.get(CRS)[0];
bBox = parseBBox(qp.get(BBOX)[0]);
width = parseInteger(qp.get(WIDTH)[0]);
height = parseInteger(qp.get(HEIGHT)[0]);
- layerList = parseLayers(qp.get(LAYERS)[0]);
- if (!qp.get(STYLES)[0].isEmpty()) {
- styleList = qp.get(STYLES)[0].split(",");
- } else {
- styleList = new String[0];
+ if(width<=0 || height<=0){
+ throw new WMSException("The width and the height must be greater than 0.");
+ }
+ if(qp.containsKey(LAYERS)){
+ layerList = parseLayers(qp.get(LAYERS)[0]);
+ }
+ if(qp.containsKey(STYLES)){
+ if (!qp.get(STYLES)[0].isEmpty()) {
+ styleList = qp.get(STYLES)[0].split(",");
+ } else {
+ styleList = new String[0];
+ }
}
if (qp.containsKey("PIXELSIZE")) {
- pixelSize = Double.valueOf(qp.get("PIXELSIZE")[0]);
+ try{
+ pixelSize = Double.valueOf(qp.get("PIXELSIZE")[0]);
+ } catch(NumberFormatException nfe){
+ throw new WMSException("The pixel size must be a double value.", nfe);
+ }
+ }
+ if (pixelSize<=0){
+ throw new WMSException("The pixel siz must be greater than 0.");
}
imageFormat = qp.get(FORMAT)[0];
if (qp.containsKey(TRANSPARENT)) {
- transparent = Boolean.valueOf(qp.get(TRANSPARENT)[0]);
+ try {
+ transparent = Boolean.valueOf(qp.get(TRANSPARENT)[0]);
+ } catch (NumberFormatException nfe) {
+ throw new WMSException("The transparent parameter must be expressed with true or false terms.", nfe);
+ }
}
if (qp.containsKey(BGCOLOR)) {
@@ -164,12 +234,15 @@ protected final int parseInteger(String s) throws WMSException{
} catch (NumberFormatException nfe){
throw new WMSException("The given int value is not valid: "+s, nfe);
}
- }
+ }
/**
- * Parses s as an array of comma separated doubles, transforming the potential NumberFormatException in a WMSException
- * We want a BBOx, so there shall be exactly four double values.
+ * Parses s as an array of comma separated doubles, transforming the potential
+ * NumberFormatException in a WMSException
+ * We want a BBox, so there shall be exactly four double values
+ * that represent minx, miny, maxx, maxy.
+ *
* @param s The input String
* @return The parsed array of double values
* @throws WMSException
@@ -195,7 +268,7 @@ private double[] parseBBox(String s) throws WMSException{
* @return A copy of the array of layers that must be queried
*/
public String[] getLayerList() {
- return Arrays.copyOf(layerList, layerList.length);
+ return layerList != null ? Arrays.copyOf(layerList, layerList.length) : new String[0];
}
/**
@@ -203,7 +276,7 @@ public String[] getLayerList() {
* @return A copy of the array of style used to draw the layers that must be queried
*/
public String[] getStyleList() {
- return Arrays.copyOf(styleList, styleList.length);
+ return styleList!= null ? Arrays.copyOf(styleList, styleList.length) : new String[0];
}
/**
diff --git a/app/wms/src/test/java/org/orbisgis/server/wms/GetFeatureInfoHandlerTest.java b/app/wms/src/test/java/org/orbisgis/server/wms/GetFeatureInfoHandlerTest.java
index fbcf0f0..6e10413 100644
--- a/app/wms/src/test/java/org/orbisgis/server/wms/GetFeatureInfoHandlerTest.java
+++ b/app/wms/src/test/java/org/orbisgis/server/wms/GetFeatureInfoHandlerTest.java
@@ -48,5 +48,6 @@ public void testComputeEnvelope() throws Exception {
//Upper left corner as geographic coordinate (20,50)
System.out.println(envelope);
assertTrue(envelope.equals(new Envelope(27,28,43,42)));
- }
+ }
+
}
diff --git a/app/wms/src/test/java/org/orbisgis/server/wms/ParametersTest.java b/app/wms/src/test/java/org/orbisgis/server/wms/ParametersTest.java
index 40861f5..873860b 100644
--- a/app/wms/src/test/java/org/orbisgis/server/wms/ParametersTest.java
+++ b/app/wms/src/test/java/org/orbisgis/server/wms/ParametersTest.java
@@ -181,6 +181,13 @@ public void testInvalidWidth() throws Exception {
map.put("WIDTH", new String[]{"potato"});
mapBuildFail(map);
}
+
+ @Test
+ public void testInvalidWidth2() throws Exception {
+ Map map= getMapMap();
+ map.put("WIDTH", new String[]{"0"});
+ mapBuildFail(map);
+ }
@Test
public void testInvalidHeight() throws Exception {
@@ -188,6 +195,13 @@ public void testInvalidHeight() throws Exception {
map.put("HEIGHT", new String[]{"potato"});
mapBuildFail(map);
}
+
+ @Test
+ public void testInvalidHeight2() throws Exception {
+ Map map= getMapMap();
+ map.put("HEIGHT", new String[]{"0"});
+ mapBuildFail(map);
+ }
@Test
public void testInvalidLayerList() throws Exception {
@@ -199,6 +213,23 @@ public void testInvalidLayerList() throws Exception {
mapBuildFail(map);
}
+ @Test
+ public void testMapSLDAndStyles(){
+ Map map= getMapMap();
+ map.put(GetMapParameters.SLD,new String[]{"sld"});
+ mapBuildFail(map);
+ }
+
+ @Test
+ public void testMapSLDAlone() throws Exception {
+ Map map= getMapMap();
+ map.put(GetMapParameters.SLD,new String[]{"sld"});
+ map.remove(GetMapParameters.LAYERS);
+ map.remove(GetMapParameters.STYLES);
+ GetMapParameters params = new GetMapParameters(map);
+ assertTrue(params.getSld().equals("sld"));
+ }
+
private void missingMapParameter(String param){
Map map= getMapMap();
map.remove(param);
diff --git a/app/wms/src/test/java/org/orbisgis/server/wms/WMSTest.java b/app/wms/src/test/java/org/orbisgis/server/wms/WMSTest.java
index fa2b23d..8433dc7 100644
--- a/app/wms/src/test/java/org/orbisgis/server/wms/WMSTest.java
+++ b/app/wms/src/test/java/org/orbisgis/server/wms/WMSTest.java
@@ -58,232 +58,333 @@
*/
public class WMSTest {
- private File f;
- private File fshp;
- private File fshx;
- private File fdbf;
- private File fprj;
- WMS wms = new WMS();
-
- /**
- *
- * @throws Exception
- */
- @Before
- public void setUp() throws Exception {
- f = File.createTempFile("wms", null);
- f.delete();
- CoreWorkspace c = new CoreWorkspace();
- c.setWorkspaceFolder(f.getAbsolutePath());
- WMSProperties props = new WMSProperties();
- props.putProperty(WMSProperties.TITLE,"test");
- wms.init(c, Collections.emptyMap(), Collections.emptyMap(), props);
-
- fshp = File.createTempFile("gdms", ".shp");
- fshp.delete();
- FileUtils.copy(WMSTest.class.getResourceAsStream("cantons.shp"), fshp);
- String name = FileUtils.getFileNameWithoutExtensionU(fshp);
- fdbf = new File(fshp.getParentFile(), name + ".dbf");
- FileUtils.copy(WMSTest.class.getResourceAsStream("cantons.dbf"), fdbf);
- fprj = new File(fshp.getParentFile(), name + ".prj");
- FileUtils.copy(WMSTest.class.getResourceAsStream("cantons.prj"), fprj);
- fshx = new File(fshp.getParentFile(), name + ".shx");
- FileUtils.copy(WMSTest.class.getResourceAsStream("cantons.shx"), fshx);
-
- SourceManager sm = Services.getService(DataManager.class).getSourceManager();
- sm.register("cantons", fshp);
+ private File f;
+ private File fshp;
+ private File fshx;
+ private File fdbf;
+ private File fprj;
+ WMS wms = new WMS();
+
+ /**
+ *
+ * @throws Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ f = File.createTempFile("wms", null);
+ f.delete();
+ CoreWorkspace c = new CoreWorkspace();
+ c.setWorkspaceFolder(f.getAbsolutePath());
+ WMSProperties props = new WMSProperties();
+ props.putProperty(WMSProperties.TITLE, "test");
+ wms.init(c, Collections.emptyMap(), Collections.emptyMap(), props);
+
+ fshp = File.createTempFile("gdms", ".shp");
+ fshp.delete();
+ FileUtils.copy(WMSTest.class.getResourceAsStream("cantons.shp"), fshp);
+ String name = FileUtils.getFileNameWithoutExtensionU(fshp);
+ fdbf = new File(fshp.getParentFile(), name + ".dbf");
+ FileUtils.copy(WMSTest.class.getResourceAsStream("cantons.dbf"), fdbf);
+ fprj = new File(fshp.getParentFile(), name + ".prj");
+ FileUtils.copy(WMSTest.class.getResourceAsStream("cantons.prj"), fprj);
+ fshx = new File(fshp.getParentFile(), name + ".shx");
+ FileUtils.copy(WMSTest.class.getResourceAsStream("cantons.shx"), fshx);
+
+ SourceManager sm = Services.getService(DataManager.class).getSourceManager();
+ sm.register("cantons", fshp);
+ }
+
+ /**
+ *
+ */
+ @After
+ public void tearDown() {
+ wms.destroy();
+ FileUtils.deleteDir(f);
+ FileUtils.deleteDir(fshp);
+ FileUtils.deleteDir(fdbf);
+ FileUtils.deleteDir(fshx);
+ FileUtils.deleteDir(fprj);
+ }
+
+ @Test
+ public void testReprojection4326() throws Exception {
+ DummyResponse r = new DummyResponse("http://localhost:9000/wms/wms");
+ HashMap h = new HashMap();
+ final String toCRS = "EPSG:4326";
+ h.put("REQUEST", new String[]{"GetMap"});
+ h.put("SERVICE", new String[]{"WMS"});
+ h.put("LAYERS", new String[]{"cantons"});
+ h.put("STYLES", new String[]{""});
+ h.put("CRS", new String[]{toCRS});
+ h.put("BBOX", new String[]{"-6.022502267873058,46.52667702045907,10.239619617329726,56.28550253867566"});
+ h.put("WIDTH", new String[]{"874"});
+ h.put("HEIGHT", new String[]{"593"});
+ h.put("FORMAT", new String[]{"image/png"});
+ h.put("VERSION", new String[]{"1.3.0"});
+ h.put("TRANSPARENT", new String[]{"TRUE"});
+ // Get the original source
+ DataSource source = wms.getContext().getDataManager().getDataSource("cantons");
+ source.open();
+ Value geom;
+ try {
+ int geomIndex = MetadataUtilities.getGeometryFieldIndex(source.getMetadata());
+ geom = source.getFieldValue(0, geomIndex);
+ } finally {
+ source.close();
}
-
- /**
- *
- */
- @After
- public void tearDown() {
- wms.destroy();
- FileUtils.deleteDir(f);
- FileUtils.deleteDir(fshp);
- FileUtils.deleteDir(fdbf);
- FileUtils.deleteDir(fshx);
- FileUtils.deleteDir(fprj);
+ FileOutputStream fileOutputStream = new FileOutputStream(new File("target/testReprojection4326.png"));
+ wms.processRequests(h, fileOutputStream, r);
+ // Get the projection source name
+ String sourceName = GetMapHandler.getProjectionSourceName("cantons", toCRS);
+ DataSource projSource = wms.getContext().getDataManager().getDataSource(sourceName);
+ projSource.open();
+ try {
+ int geomIndex = MetadataUtilities.getGeometryFieldIndex(projSource.getMetadata());
+ Geometry projGeom = projSource.getFieldValue(0, geomIndex).getAsGeometry();
+ ST_Transform transformFunction = new ST_Transform();
+ Value res = transformFunction.evaluate(wms.getContext().getDataSourceFactory(), geom, ValueFactory.createValue(toCRS));
+ assertTrue(res.getAsGeometry().equals(projGeom));
+ } finally {
+ projSource.close();
}
-
- @Test
- public void testReprojection() throws Exception {
- DummyResponse r = new DummyResponse("http://localhost:9000/wms/wms");
- HashMap h = new HashMap();
- final String toCRS = "EPSG:4326";
- h.put("REQUEST", new String[]{"GetMap"});
- h.put("SERVICE", new String[]{"WMS"});
- h.put("LAYERS", new String[]{"cantons"});
- h.put("STYLES", new String[]{""});
- h.put("CRS", new String[]{toCRS});
- h.put("BBOX", new String[]{"-5.372757617915,9.326100042301633,41.3630420705024,51.089386147807105"});
- h.put("WIDTH", new String[]{"874"});
- h.put("HEIGHT", new String[]{"593"});
- h.put("FORMAT", new String[]{"image/png"});
- h.put("VERSION", new String[]{"1.3.0"});
- h.put("TRANSPARENT", new String[]{"TRUE"});
- // Get the original source
- DataSource source = wms.getContext().getDataManager().getDataSource("cantons");
- source.open();
- Value geom;
- try {
- int geomIndex = MetadataUtilities.getGeometryFieldIndex(source.getMetadata());
- geom = source.getFieldValue(0, geomIndex);
- } finally {
- source.close();
- }
- FileOutputStream fileOutputStream = new FileOutputStream(new File("target/testReprojection.png"));
- wms.processRequests(h, fileOutputStream, r);
- // Get the projection source name
- String sourceName = GetMapHandler.getProjectionSourceName("cantons",toCRS);
- DataSource projSource = wms.getContext().getDataManager().getDataSource(sourceName);
- projSource.open();
- try {
- int geomIndex = MetadataUtilities.getGeometryFieldIndex(projSource.getMetadata());
- Geometry projGeom = projSource.getFieldValue(0,geomIndex).getAsGeometry();
- ST_Transform transformFunction = new ST_Transform();
- Value res = transformFunction.evaluate(wms.getContext().getDataSourceFactory(),geom, ValueFactory.createValue(toCRS));
- assertTrue(res.getAsGeometry().equals(projGeom));
- } finally {
- projSource.close();
- }
-
+ }
+
+ @Test
+ public void testReprojection3857() throws Exception {
+ DummyResponse r = new DummyResponse("http://localhost:9000/wms/wms");
+ HashMap h = new HashMap();
+ final String toCRS = "EPSG:3857";
+ h.put("REQUEST", new String[]{"GetMap"});
+ h.put("SERVICE", new String[]{"WMS"});
+ h.put("LAYERS", new String[]{"cantons"});
+ h.put("STYLES", new String[]{""});
+ h.put("CRS", new String[]{toCRS});
+ h.put("BBOX", new String[]{"-670421.885760964,5865155.04961359,1139869.24171796,7615462.350663964"});
+ h.put("WIDTH", new String[]{"874"});
+ h.put("HEIGHT", new String[]{"593"});
+ h.put("FORMAT", new String[]{"image/png"});
+ h.put("VERSION", new String[]{"1.3.0"});
+ h.put("TRANSPARENT", new String[]{"TRUE"});
+ // Get the original source
+ DataSource source = wms.getContext().getDataManager().getDataSource("cantons");
+ source.open();
+ Value geom;
+ try {
+ int geomIndex = MetadataUtilities.getGeometryFieldIndex(source.getMetadata());
+ geom = source.getFieldValue(0, geomIndex);
+ } finally {
+ source.close();
}
- /**
- * Checks the error response for any missing parameter;
- *
- * @throws Exception
- */
- @Test
- public void testParameterErrors() throws Exception {
- DummyResponse r = new DummyResponse("http://localhost:9000/wms/wms");
- HashMap h = new HashMap();
-
- h.put("REQUEST", new String[]{"GetMap"});
- h.put("SERVICE", new String[]{"WMS"});
- h.put("LAYERS", new String[]{"cantons"});
- h.put("STYLES", new String[]{""});
- h.put("CRS", new String[]{"EPSG:27582"});
- h.put("BBOX", new String[]{"2677441.0,1197822.0,1620431.0,47680.0"});
- h.put("WIDTH", new String[]{"874"});
- h.put("HEIGHT", new String[]{"593"});
- h.put("FORMAT", new String[]{"image/png"});
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- wms.processRequests(h, out, r);
- assertEquals(400, r.responseCode);
- assertEquals("text/xml;charset=UTF-8", r.contentType);
- h.put("VERSION", new String[]{"1.3.0"});
-
- h.remove("REQUEST");
- wms.processRequests(h, out, r);
- assertEquals(400, r.responseCode);
- assertEquals("text/xml;charset=UTF-8", r.contentType);
- h.put("REQUEST", new String[]{"GetMap"});
-
- h.remove("SERVICE");
- wms.processRequests(h, out, r);
- assertEquals(400, r.responseCode);
- assertEquals("text/xml;charset=UTF-8", r.contentType);
- h.put("SERVICE", new String[]{"WMS"});
-
- h.remove("CRS");
- wms.processRequests(h, out, r);
- assertEquals(400, r.responseCode);
- assertEquals("text/xml;charset=UTF-8", r.contentType);
- h.put("CRS", new String[]{"EPSG:27582"});
-
- h.remove("BBOX");
- wms.processRequests(h, out, r);
- assertEquals(400, r.responseCode);
- assertEquals("text/xml;charset=UTF-8", r.contentType);
- h.put("BBOX", new String[]{"2677441.0,1197822.0,1620431.0,47680.0"});
-
- h.remove("WIDTH");
- wms.processRequests(h, out, r);
- assertEquals(400, r.responseCode);
- assertEquals("text/xml;charset=UTF-8", r.contentType);
- h.put("WIDTH", new String[]{"874"});
-
- h.remove("HEIGHT");
- wms.processRequests(h, out, r);
- assertEquals(400, r.responseCode);
- assertEquals("text/xml;charset=UTF-8", r.contentType);
- h.put("HEIGHT", new String[]{"593"});
-
- h.remove("FORMAT");
- wms.processRequests(h, out, r);
- assertEquals(400, r.responseCode);
- assertEquals("text/xml;charset=UTF-8", r.contentType);
+ FileOutputStream fileOutputStream = new FileOutputStream(new File("target/testReprojection3857.png"));
+ wms.processRequests(h, fileOutputStream, r);
+ // Get the projection source name
+ String sourceName = GetMapHandler.getProjectionSourceName("cantons", toCRS);
+ DataSource projSource = wms.getContext().getDataManager().getDataSource(sourceName);
+ projSource.open();
+ try {
+ int geomIndex = MetadataUtilities.getGeometryFieldIndex(projSource.getMetadata());
+ Geometry projGeom = projSource.getFieldValue(0, geomIndex).getAsGeometry();
+ ST_Transform transformFunction = new ST_Transform();
+ Value res = transformFunction.evaluate(wms.getContext().getDataSourceFactory(), geom, ValueFactory.createValue(toCRS));
+ assertTrue(res.getAsGeometry().equals(projGeom));
+ } finally {
+ projSource.close();
}
-
- /**
- * Checking the ability to display a map in any supported output format
- *
- * @throws Exception
- */
- @Test
- public void testImageFormat() throws Exception {
- DummyResponse r = new DummyResponse("http://localhost:9000/wms/wms");
- HashMap h = new HashMap();
-
- DataSourceFactory dsf = Services.getService(DataManager.class).getDataSourceFactory();
- dsf.getDataSource("cantons").open();
-
- h.put("REQUEST", new String[]{"GetMap"});
- h.put("VERSION", new String[]{"1.3.0"});
- h.put("SERVICE", new String[]{"WMS"});
- h.put("LAYERS", new String[]{"cantons"});
- h.put("STYLES", new String[]{""});
- h.put("CRS", new String[]{"EPSG:27582"});
- h.put("BBOX", new String[]{"2677441.0,1197822.0,1620431.0,47680.0"});
- h.put("WIDTH", new String[]{"874"});
- h.put("HEIGHT", new String[]{"593"});
- h.put("FORMAT", new String[]{"image/png"});
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- wms.processRequests(h, out, r);
- assertEquals(200, r.responseCode);
- assertEquals("image/png", r.contentType);
-
- h.put("FORMAT", new String[]{"image/jpeg"});
- wms.processRequests(h, out, r);
- assertEquals(200, r.responseCode);
- assertEquals("image/jpeg", r.contentType);
-
- h.put("FORMAT", new String[]{"image/tiff"});
- wms.processRequests(h, out, r);
- assertEquals(200, r.responseCode);
- assertEquals("image/tiff", r.contentType);
-
+ }
+
+ /**
+ * Checks the error response for any missing parameter;
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testParameterErrors() throws Exception {
+ DummyResponse r = new DummyResponse("http://localhost:9000/wms/wms");
+ HashMap h = new HashMap();
+
+ h.put("REQUEST", new String[]{"GetMap"});
+ h.put("SERVICE", new String[]{"WMS"});
+ h.put("LAYERS", new String[]{"cantons"});
+ h.put("STYLES", new String[]{""});
+ h.put("CRS", new String[]{"EPSG:27582"});
+ h.put("BBOX", new String[]{"2677441.0,1197822.0,1620431.0,47680.0"});
+ h.put("WIDTH", new String[]{"874"});
+ h.put("HEIGHT", new String[]{"593"});
+ h.put("FORMAT", new String[]{"image/png"});
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ wms.processRequests(h, out, r);
+ assertEquals(400, r.responseCode);
+ assertEquals("text/xml;charset=UTF-8", r.contentType);
+ h.put("VERSION", new String[]{"1.3.0"});
+
+ h.remove("REQUEST");
+ wms.processRequests(h, out, r);
+ assertEquals(400, r.responseCode);
+ assertEquals("text/xml;charset=UTF-8", r.contentType);
+ h.put("REQUEST", new String[]{"GetMap"});
+
+ h.remove("SERVICE");
+ wms.processRequests(h, out, r);
+ assertEquals(400, r.responseCode);
+ assertEquals("text/xml;charset=UTF-8", r.contentType);
+ h.put("SERVICE", new String[]{"WMS"});
+
+ h.remove("CRS");
+ wms.processRequests(h, out, r);
+ assertEquals(400, r.responseCode);
+ assertEquals("text/xml;charset=UTF-8", r.contentType);
+ h.put("CRS", new String[]{"EPSG:27572"});
+
+ h.remove("BBOX");
+ wms.processRequests(h, out, r);
+ assertEquals(400, r.responseCode);
+ assertEquals("text/xml;charset=UTF-8", r.contentType);
+ h.put("BBOX", new String[]{"2677441.0,1197822.0,1620431.0,47680.0"});
+
+ h.remove("WIDTH");
+ wms.processRequests(h, out, r);
+ assertEquals(400, r.responseCode);
+ assertEquals("text/xml;charset=UTF-8", r.contentType);
+ h.put("WIDTH", new String[]{"874"});
+
+ h.remove("HEIGHT");
+ wms.processRequests(h, out, r);
+ assertEquals(400, r.responseCode);
+ assertEquals("text/xml;charset=UTF-8", r.contentType);
+ h.put("HEIGHT", new String[]{"593"});
+
+ h.remove("FORMAT");
+ wms.processRequests(h, out, r);
+ assertEquals(400, r.responseCode);
+ assertEquals("text/xml;charset=UTF-8", r.contentType);
+ }
+
+ /**
+ * Checking the ability to display a map in any supported output format
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testImageFormat() throws Exception {
+ DummyResponse r = new DummyResponse("http://localhost:9000/wms/wms");
+ HashMap h = new HashMap();
+
+ DataSourceFactory dsf = Services.getService(DataManager.class).getDataSourceFactory();
+ dsf.getDataSource("cantons").open();
+
+ h.put("REQUEST", new String[]{"GetMap"});
+ h.put("VERSION", new String[]{"1.3.0"});
+ h.put("SERVICE", new String[]{"WMS"});
+ h.put("LAYERS", new String[]{"cantons"});
+ h.put("STYLES", new String[]{""});
+ h.put("CRS", new String[]{"EPSG:27572"});
+ h.put("BBOX", new String[]{"47680,1620431, 1197822,2677441"});
+ h.put("WIDTH", new String[]{"874"});
+ h.put("HEIGHT", new String[]{"593"});
+ h.put("FORMAT", new String[]{"image/png"});
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ wms.processRequests(h, out, r);
+ assertEquals(200, r.responseCode);
+ assertEquals("image/png", r.contentType);
+
+ h.put("FORMAT", new String[]{"image/jpeg"});
+ wms.processRequests(h, out, r);
+ assertEquals(200, r.responseCode);
+ assertEquals("image/jpeg", r.contentType);
+
+ h.put("FORMAT", new String[]{"image/tiff"});
+ wms.processRequests(h, out, r);
+ assertEquals(200, r.responseCode);
+ assertEquals("image/tiff", r.contentType);
+
+ }
+
+ @Test
+ public void testGetFeatureInfoText() throws Exception {
+ DummyResponse r = new DummyResponse("http://localhost:9000/wms/wms");
+ HashMap h = new HashMap();
+
+ DataSourceFactory dsf = Services.getService(DataManager.class).getDataSourceFactory();
+ dsf.getDataSource("cantons").open();
+
+ h.put("REQUEST", new String[]{"GetFeatureInfo"});
+ h.put("VERSION", new String[]{"1.3.0"});
+ h.put("SERVICE", new String[]{"WMS"});
+ h.put("LAYERS", new String[]{"cantons"});
+ h.put("STYLES", new String[]{""});
+ h.put("CRS", new String[]{"EPSG:27572"});
+ h.put("BBOX", new String[]{"270213.9595191681,2293124.7156245164, 309188.95846363576,2257614.1610306683"});
+ h.put("FORMAT", new String[]{"image/png"});
+ h.put("WIDTH", new String[]{"874"});
+ h.put("HEIGHT", new String[]{"593"});
+ h.put("QUERY_LAYERS", new String[]{"cantons"});
+ h.put("INFO_FORMAT", new String[]{"text/plain"});
+ h.put("FEATURE_COUNT", new String[]{"10"});
+ h.put("I", new String[]{"10"});
+ h.put("J", new String[]{"12"});
+ FileOutputStream out = new FileOutputStream(new File("target/featureinfo.txt"));
+ wms.processRequests(h, out, r);
+ assertTrue(r.getResponseCode() == 200);
+ }
+
+ @Test
+ public void testGetMapWithSLD() throws Exception {
+ DummyResponse r = new DummyResponse("http://localhost:9000/wms/wms");
+ HashMap h = new HashMap();
+
+ DataSourceFactory dsf = Services.getService(DataManager.class).getDataSourceFactory();
+ dsf.getDataSource("cantons").open();
+
+ h.put("REQUEST", new String[]{"GetMap"});
+ h.put("VERSION", new String[]{"1.3.0"});
+ h.put("SERVICE", new String[]{"WMS"});
+ h.put("CRS", new String[]{"EPSG:27582"});
+ h.put("BBOX", new String[]{"270213.9595191681,2293124.7156245164, 309188.95846363576,2257614.1610306683"});
+ h.put("FORMAT", new String[]{"image/png"});
+ h.put("WIDTH", new String[]{"874"});
+ h.put("HEIGHT", new String[]{"593"});
+ String location = "file://"+System.getProperty("user.dir")+"/src/test/resources/org/orbisgis/server/wms/polygons.sld";
+ System.out.println("Location is"+location);
+ h.put("SLD", new String[]{location});
+ FileOutputStream out = new FileOutputStream(new File("target/sld.png"));
+ wms.processRequests(h, out, r);
+ System.out.println("Response code is "+r.getResponseCode());
+ assertTrue(r.getResponseCode() == 200);
+
+ }
+
+ private static class DummyResponse implements WMSResponse {
+
+ private String contentType;
+ private String requestUrl;
+ private int responseCode;
+
+ DummyResponse(String requestUrl) {
+ this.requestUrl = requestUrl;
}
- private static class DummyResponse implements WMSResponse {
-
- private String contentType;
- private String requestUrl;
- private int responseCode;
-
- DummyResponse(String requestUrl) {
- this.requestUrl = requestUrl;
- }
+ @Override
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
- @Override
- public void setContentType(String contentType) {
- this.contentType = contentType;
- }
+ @Override
+ public String getRequestUrl() {
+ return requestUrl;
+ }
- @Override
- public String getRequestUrl() {
- return requestUrl;
- }
+ @Override
+ public void setResponseCode(int code) {
+ responseCode = code;
+ }
- @Override
- public void setResponseCode(int code) {
- responseCode = code;
- }
+ public int getResponseCode(){
+ return responseCode;
}
+ }
}
diff --git a/app/wms/src/test/resources/org/orbisgis/server/wms/polygons.sld b/app/wms/src/test/resources/org/orbisgis/server/wms/polygons.sld
new file mode 100644
index 0000000..87df341
--- /dev/null
+++ b/app/wms/src/test/resources/org/orbisgis/server/wms/polygons.sld
@@ -0,0 +1,26 @@
+
+
+
+ cantons
+
+
+
+
+ Area symbolizer
+
+ #0000ee
+ 0.6
+
+
+
+ #000000
+ 1.0
+
+ 0.1
+
+
+
+
+
+
+
diff --git a/project/Build.scala b/project/Build.scala
index aaaa77c..a0c3915 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -8,7 +8,7 @@ object ApplicationBuild extends Build {
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
- "org.orbisgis.server" % "orbiswms-lib" % "1.0-SNAPSHOT" changing(),
+ "org.orbisgis.server" % "orbiswms-lib" % "1.0.1-SNAPSHOT" changing(),
"com.sun.xml.bind" % "jaxb-impl" % "2.2.2",
"com.kitfox.svg" % "svg-salamander" % "1.0" from "http://repo.orbisgis.org/com/kitfox/svg/svg-salamander/1.0/svg-salamander-1.0.jar",
"javax.media" % "jai_core" % "1.1.3" from "http://repo.orbisgis.org/javax/media/jai_core/1.1.3/jai_core-1.1.3.jar",