Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented support of XML and SOAP encoding for WMS 1.3.0 #598

Merged
merged 20 commits into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public class CommonNamespaces {
*/
public static final String OWS_11_NS = "http://www.opengis.net/ows/1.1";

/**
* The OWS_11_NS namespace is bound to: "http://www.opengis.net/ows/2.0"
*/
public static final String OWS_20_NS = "http://www.opengis.net/ows/2.0";

/**
* The ISO19115NS namespace is bound to: "http://schemas.opengis.net/iso19115full"
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,29 @@ public static double getRequiredElementTextAsDouble( XMLStreamReader reader, QNa
return result;
}

/**
* Returns the text in the required element as a inz. If the name of the reader does not match the given qName, an
* exception will be thrown. If the value is not a double, an exception will be thrown. Post: reader will be
* unchanged or at {@link XMLStreamConstants #END_ELEMENT} of the matching element or at
* {@link XMLStreamConstants #START_ELEMENT} of the next element if requested.
*
* @param reader
* @param elementName
* @param nextElemOnSucces
* if true the reader will be move to the next element if the operation was successful.
* @return the double value of the required element.
* @throws XMLStreamException
*/
public static int getRequiredElementTextAsInteger( XMLStreamReader reader, QName elementName,
boolean nextElemOnSucces )
throws XMLStreamException {
if ( !elementName.equals( reader.getName() ) ) {
throw new XMLParsingException( reader, "The current element: " + reader.getName() + " is not expected: "
+ elementName );
}
return getElementTextAsInteger( reader );
}

/**
* Move the reader to the first element which matches the given name. The reader will be positioned on the
* {@link XMLStreamConstants#START_ELEMENT} event or after the {@link XMLStreamConstants#END_DOCUMENT} which ever
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public class OWSCommonXMLAdapter extends XMLAdapter {
*/
public static final String OWS110_NS = "http://www.opengis.net/ows/1.1";

/**
* ows 2.0 version
*/
public static final String OWS200_NS = "http://www.opengis.net/ows/2.0";

/**
* normal xml namespace
*/
Expand All @@ -87,6 +92,11 @@ public class OWSCommonXMLAdapter extends XMLAdapter {
*/
public static final String OWS110_PREFIX = "ows110";

/**
* the ows 2.0.0 prefix
*/
public static final String OWS200_PREFIX = "ows200";

/**
* the xml prefix
*/
Expand All @@ -98,9 +108,10 @@ public class OWSCommonXMLAdapter extends XMLAdapter {
// add to common namespaces from xml adapter
nsContext.addNamespace( OWS_PREFIX, OWS_NS );
nsContext.addNamespace( OWS110_PREFIX, OWS110_NS );
nsContext.addNamespace( OWS200_PREFIX, OWS200_NS );
nsContext.addNamespace( XML_PREFIX, XML_NS );
}

/**
* Parses the given element of type <code>ows:BoundingBoxType</code>.
*
Expand Down Expand Up @@ -282,5 +293,5 @@ public static void exportPositionType( XMLStreamWriter writer, Point pos )
writer.writeCharacters( "" + coord );
needsDelim = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ public GetCapabilities parse110()
return new GetCapabilities( null, Arrays.asList( versions ), sections, formats, updateSequence, languages );
}

/**
* Parses an OWS 2.0.0 <code>GetCapabilitiesType</code> into a {@link GetCapabilities} object.
*
* @return <code>GetCapabilities</code> object corresponding to the input document
* @throws XMLParsingException
* if the document contains syntactic or semantic errors
*/
public GetCapabilities parse200()
throws XMLParsingException {
// @updateSequence (optional)
String updateSequence = rootElement.getAttributeValue( new QName( "updateSequence" ) );
// ows200:AcceptVersions (optional)
String[] versions = getNodesAsStrings( rootElement, new XPath( "ows200:AcceptVersions/ows200:Version/text()",
nsContext ) );
// ows200:Sections (optional)
List<String> sections = parseSections( OWS200_PREFIX );
// ows200:AcceptFormats (optional)
List<String> formats = parse200Formats();
// ows200:AcceptLanguages (optional)
List<String> languages = parse200Languages();
return new GetCapabilities( null, Arrays.asList( versions ), sections, formats, updateSequence, languages );
}

/**
* @return all parsed Sections
*/
Expand All @@ -180,4 +203,26 @@ private List<String> parseSections( String nsPrefix ) {
}
return sections;
}
}

private List<String> parse200Formats() {
List<OMElement> formatElements = getElements( rootElement,
new XPath( "ows200:AcceptFormats/ows200:OutputFormat", nsContext ) );
List<String> formats = new ArrayList<String>( formatElements.size() );
for ( OMElement formatElement : formatElements ) {
formats.add( formatElement.getText() );
}
return formats;
}

private List<String> parse200Languages() {
List<OMElement> languageElements = getElements( rootElement,
new XPath( "ows200:AcceptLanguages/ows200:Language", nsContext ) );
List<String> languages = new ArrayList<String>();
for ( OMElement languageElement : languageElements ) {
String language = languageElement.getText();
languages.add( language );
}
return languages;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2009 by:
Department of Geography, University of Bonn
Department of Geography, University of Bonn
and
lat/lon GmbH
lat/lon GmbH

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Expand Down Expand Up @@ -32,27 +32,30 @@
http://www.geographie.uni-bonn.de/deegree/

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.protocol.ows.capabilities;
----------------------------------------------------------------------------*/
package org.deegree.protocol.ows.getcapabilities;

import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.net.URL;
import java.util.List;
import java.util.Set;

import org.deegree.commons.tom.ows.Version;
import org.deegree.protocol.ows.getcapabilities.GetCapabilities;
import org.deegree.protocol.ows.getcapabilities.GetCapabilitiesXMLParser;
import org.junit.Test;

/**
* Test cases for {@link GetCapabilitiesXMLParser}.
*
*
* @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
* @author last edited by: $Author:$
*
*
* @version $Revision:$, $Date:$
*/
public class GetCapabilitiesXMLParserTest {
Expand All @@ -62,7 +65,7 @@ public class GetCapabilitiesXMLParserTest {
*/
@Test
public void testParsing100() {
URL docURL = GetCapabilitiesXMLParserTest.class.getResource( "GetCapabilitiesOWS100.xml" );
URL docURL = GetCapabilitiesXMLParserTest.class.getResource( "../capabilities/GetCapabilitiesOWS100.xml" );
GetCapabilitiesXMLParser parser = new GetCapabilitiesXMLParser();
parser.load( docURL );
GetCapabilities request = parser.parse100();
Expand All @@ -71,8 +74,8 @@ public void testParsing100() {
// check accept versions
assertNotNull( request.getAcceptVersions() );
assertEquals( 2, request.getAcceptVersions().size() );
assertEquals( Version.parseVersion( "1.0.0" ), request.getAcceptVersionsAsVersions().get(1) );
assertEquals( Version.parseVersion( "1.1.0" ), request.getAcceptVersionsAsVersions().get(0) );
assertEquals( Version.parseVersion( "1.0.0" ), request.getAcceptVersionsAsVersions().get( 1 ) );
assertEquals( Version.parseVersion( "1.1.0" ), request.getAcceptVersionsAsVersions().get( 0 ) );

// check sections
assertNotNull( request.getSections() );
Expand All @@ -94,7 +97,7 @@ public void testParsing100() {
*/
@Test
public void testParsing110() {
URL docURL = GetCapabilitiesXMLParserTest.class.getResource( "GetCapabilitiesOWS110.xml" );
URL docURL = GetCapabilitiesXMLParserTest.class.getResource( "../capabilities/GetCapabilitiesOWS110.xml" );
GetCapabilitiesXMLParser parser = new GetCapabilitiesXMLParser();
parser.load( docURL );
GetCapabilities request = parser.parse110();
Expand All @@ -103,8 +106,8 @@ public void testParsing110() {
// check accept versions
assertNotNull( request.getAcceptVersions() );
assertEquals( 3, request.getAcceptVersions().size() );
assertEquals( Version.parseVersion( "1.0.0" ), request.getAcceptVersionsAsVersions().get(0) );
assertEquals( Version.parseVersion( "2.0.0" ), request.getAcceptVersionsAsVersions().get(1) );
assertEquals( Version.parseVersion( "1.0.0" ), request.getAcceptVersionsAsVersions().get( 0 ) );
assertEquals( Version.parseVersion( "2.0.0" ), request.getAcceptVersionsAsVersions().get( 1 ) );

// check sections
assertNotNull( request.getSections() );
Expand All @@ -120,4 +123,38 @@ public void testParsing110() {

assertNull( request.getUpdateSequence() );
}
}

/**
* Tests the parsing of an OWS 2.0.0 GetCapabilities document.
*/
@Test
public void testParsing200() {
URL docURL = GetCapabilitiesXMLParserTest.class.getResource( "../capabilities/GetCapabilitiesOWS200.xml" );
GetCapabilitiesXMLParser parser = new GetCapabilitiesXMLParser();
parser.load( docURL );
GetCapabilities request = parser.parse200();

// check accept versions
List<String> acceptVersions = request.getAcceptVersions();
assertThat( acceptVersions.size(), is( 3 ) );
assertThat( acceptVersions, hasItems( "1.0.0", "2.0.0", "1.1.0" ) );

// check sections
Set<String> sections = request.getSections();
assertThat( sections.size(), is( 3 ) );
assertThat( sections, hasItems( "ServiceIdentification", "ServiceProvider", "OperationsMetadata" ) );

// check accept formats
Set<String> acceptFormats = request.getAcceptFormats();
assertThat( acceptFormats.size(), is( 1 ) );
assertThat( acceptFormats, hasItems( "text/xml" ) );

// check accept formats
List<String> acceptLanguages = request.getAcceptLanguages();
assertThat( acceptLanguages.size(), is( 2 ) );
assertThat( acceptLanguages, hasItems( "en", "de" ) );

assertThat( request.getUpdateSequence(), is( "2" ) );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<GetCapabilities xmlns="http://www.opengis.net/ows/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/ows/2.0 http://schemas.opengis.net/ows/2.0/owsGetCapabilities.xsd"
updateSequence="2">
<AcceptVersions>
<Version>1.0.0</Version>
<Version>2.0.0</Version>
<Version>1.1.0</Version>
</AcceptVersions>
<Sections>
<Section>ServiceIdentification</Section>
<Section>ServiceProvider</Section>
<Section>OperationsMetadata</Section>
</Sections>
<AcceptFormats>
<OutputFormat>text/xml</OutputFormat>
</AcceptFormats>
<AcceptLanguages>
<Language>en</Language>
<Language>de</Language>
</AcceptLanguages>
</GetCapabilities>
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,9 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//$HeadURL$
/*----------------------------------------------------------------------------
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2015 by:
- Department of Geography, University of Bonn -
and
- lat/lon GmbH -

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Contact information:

lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/

Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
package org.deegree.protocol.wms;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.deegree.commons.tom.ows.Version;
import org.deegree.commons.utils.kvp.InvalidParameterValueException;
import org.deegree.commons.xml.CommonNamespaces;
import org.deegree.commons.xml.stax.XMLStreamUtils;

/**
* Contains common methods for WMS Parsers.
*
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz</a>
*/
public class AbstractWmsParser {

private static final String VERSION_130 = "1.3.0";

/**
* Skips to the start elment of the documents and checks the version attribute.
*
* @param request
* WMS request, never <code>null</code>
* @return the version from the document, if version is null the namespace is evaluated, never <code>null</code>
* @throws XMLStreamException
* if an exeption occured during parsing
* @throw {@link InvalidParameterValueException} if the version could not be parsed
*/
protected Version forwardToStartAndDetermineVersion( XMLStreamReader request )
throws XMLStreamException {
XMLStreamUtils.skipStartDocument( request );
String versionAttributeValue = request.getAttributeValue( null, "version" );
if ( CommonNamespaces.WMSNS.equals( request.getNamespaceURI() ) ) {
if ( versionAttributeValue.isEmpty() ) {
versionAttributeValue = VERSION_130;
}
}
return Version.parseVersion( versionAttributeValue );
}

}
Loading