public static void checkValidationErrors(Parser parser, XmlRequestReader requestReader) { // TODO: HACK, disabling validation for transaction if (!"Transaction".equalsIgnoreCase(requestReader.getElement().getLocalPart())) { if (!parser.getValidationErrors().isEmpty()) { WFSException exception = new WFSException("Invalid request", "InvalidParameterValue"); for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext(); ) { Exception error = (Exception) e.next(); exception.getExceptionText().add(error.getLocalizedMessage()); } throw exception; } } }
private List<Exception> validate11(Object input, EntityResolver entityResolver) throws IOException { Parser p = createSld11Parser(input, null, entityResolver); try { p.validate(toReader(input)); return p.getValidationErrors(); } catch (Exception e) { throw new IOException(e); } }
public Object read(Object request, Reader reader, Map kvp) throws Exception { // TODO: make this configurable? configuration.getProperties().add(Parser.Properties.PARSE_UNKNOWN_ELEMENTS); Parser parser = new Parser(configuration); // set the input source with the correct encoding InputSource source = new InputSource(reader); source.setEncoding(wfs.getCharSet().name()); Object parsed = parser.parse(source); // valid request? this should definitley be a configuration option // TODO: HACK, disabling validation for transaction if (!"Transaction".equalsIgnoreCase(getElement().getLocalPart())) { if (!parser.getValidationErrors().isEmpty()) { WFSException exception = new WFSException("Invalid request", "InvalidParameterValue"); for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext();) { Exception error = (Exception) e.next(); exception.getExceptionText().add(error.getLocalizedMessage()); } throw exception; } } return parsed; } }
@SuppressWarnings("unchecked") public Object read(Object request, Reader reader, Map kvp) throws Exception { Parser parser = new Parser(configuration); parser.setValidating(true); Object parsed; try { parsed = parser.parse(reader); } catch(Exception e) { throw new WPSException("Could not parse XML request.", e); } if (!parser.getValidationErrors().isEmpty()) { WPSException exception = new WPSException("Invalid request", "InvalidParameterValue"); for(Exception error : (List<Exception>)parser.getValidationErrors()) { LOGGER.warning( error.getLocalizedMessage() ); exception.getExceptionText().add(error.getLocalizedMessage()); } } return parsed; } }
@SuppressWarnings("unchecked") public Object read(Object request, Reader reader, Map kvp) throws Exception { Parser parser = new Parser(configuration); parser.setValidating(true); parser.setEntityResolver(resolverProvider.getEntityResolver()); Object parsed; try { parsed = parser.parse(reader); } catch (Exception e) { throw new WPSException("Could not parse XML request.", e); } if (!parser.getValidationErrors().isEmpty()) { WPSException exception = new WPSException("Invalid request", "InvalidParameterValue"); for (Exception error : (List<Exception>) parser.getValidationErrors()) { LOGGER.warning(error.getLocalizedMessage()); exception.getExceptionText().add(error.getLocalizedMessage()); } } return parsed; } }
@SuppressWarnings("unchecked") public Object read(Object request, Reader reader, Map kvp) throws Exception { Parser parser = new Parser(configuration); parser.setValidating(true); parser.setFailOnValidationError(true); parser.setStrict(true); Object parsed; try { parsed = parser.parse(reader); } catch (Exception e) { throw new ServiceException("Could not parse XML request.", e); } if (!parser.getValidationErrors().isEmpty()) { ServiceException exception = new ServiceException("Invalid request", "InvalidParameterValue"); for (Exception error : (List<Exception>) parser.getValidationErrors()) { LOGGER.warning(error.getLocalizedMessage()); exception.getExceptionText().add(error.getLocalizedMessage()); } } return parsed; } }
if (strict.booleanValue() && !parser.getValidationErrors().isEmpty()) { WFSException exception = new WFSException("Invalid request", "InvalidParameterValue"); for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext(); ) { Exception error = (Exception) e.next(); exception.getExceptionText().add(error.getLocalizedMessage());
@SuppressWarnings("unchecked") public Object read(Object request, Reader reader, Map kvp) throws Exception { Parser parser = new Parser(configuration); parser.setValidating(true); parser.setFailOnValidationError(true); parser.setStrict(true); parser.setEntityResolver(resolverProvider.getEntityResolver()); Object parsed; try { parsed = parser.parse(reader); } catch (Exception e) { throw new ServiceException("Could not parse XML request.", e); } if (!parser.getValidationErrors().isEmpty()) { ServiceException exception = new ServiceException("Invalid request", "InvalidParameterValue"); for (Exception error : (List<Exception>) parser.getValidationErrors()) { LOGGER.warning(error.getLocalizedMessage()); exception.getExceptionText().add(error.getLocalizedMessage()); } } return parsed; } }
if (!parser.getValidationErrors().isEmpty()) { WFSException exception = new WFSException("Invalid request", "InvalidParameterValue"); for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext();) { Exception error = (Exception) e.next(); exception.getExceptionText().add(error.getLocalizedMessage());
/** * Validates a document against the * * @param dom * @param configuration */ protected void checkValidationErrors(Document dom, Configuration configuration) throws Exception { Parser p = new Parser(configuration); p.setValidating(true); p.parse(new DOMSource(dom)); if (!p.getValidationErrors().isEmpty()) { for (Iterator e = p.getValidationErrors().iterator(); e.hasNext();) { SAXParseException ex = (SAXParseException) e.next(); System.out.println(ex.getLineNumber() + "," + ex.getColumnNumber() + " -" + ex.toString()); } fail("Document did not validate."); } }
/** * Validates a document against the * @param dom * @param configuration */ protected void checkValidationErrors(Document dom, Configuration configuration) throws Exception { Parser p = new Parser(configuration); p.setValidating( true ); p.parse( new DOMSource( dom ) ); if ( !p.getValidationErrors().isEmpty() ) { for ( Iterator e = p.getValidationErrors().iterator(); e.hasNext(); ) { SAXParseException ex = (SAXParseException) e.next(); System.out.println( ex.getLineNumber() + "," + ex.getColumnNumber() + " -" + ex.toString() ); } fail( "Document did not validate."); } }
/** * Validates a document against the * * @param dom * @param configuration */ @SuppressWarnings("rawtypes") protected void checkWms13ValidationErrors(Document dom) throws Exception { Parser p = new Parser( (Configuration) Class.forName("org.geotools.wms.v1_3.WMSConfiguration") .newInstance()); p.setValidating(true); p.parse(new DOMSource(dom)); if (!p.getValidationErrors().isEmpty()) { for (Iterator e = p.getValidationErrors().iterator(); e.hasNext(); ) { SAXParseException ex = (SAXParseException) e.next(); System.out.println( ex.getLineNumber() + "," + ex.getColumnNumber() + " -" + ex.toString()); } fail("Document did not validate."); } }
@Test public void testValid() throws Exception { Parser parser = new Parser(configuration()); parser.parse(getClass().getResourceAsStream("GetFeature.xml")); assertEquals(0, parser.getValidationErrors().size()); }
/** * Validates a document against the * * @param dom * @param configuration */ @SuppressWarnings("rawtypes") protected void checkValidationErrors(Document dom) throws Exception { Parser p = new Parser(new WCSConfiguration()); p.setValidating(true); p.parse(new DOMSource(dom)); if (!p.getValidationErrors().isEmpty()) { for (Iterator e = p.getValidationErrors().iterator(); e.hasNext(); ) { SAXParseException ex = (SAXParseException) e.next(); System.out.println( ex.getLineNumber() + "," + ex.getColumnNumber() + " -" + ex.toString()); } fail("Document did not validate."); } }
@Test public void testInvalid() throws Exception { Parser parser = new Parser(configuration()); parser.setValidating(true); parser.parse(getClass().getResourceAsStream("GetFeature-invalid.xml")); assertTrue(parser.getValidationErrors().size() > 0); } }
@Test public void testValidCapabilitiesDocument() throws Exception { print(getAsDOM("wfs?service=WFS&version=2.0.0&request=getCapabilities")); InputStream in = get("wfs?service=WFS&version=2.0.0&request=getCapabilities"); Parser p = new Parser(new WFSConfiguration()); p.setValidating(true); p.validate(in); for (Exception e : (List<Exception>) p.getValidationErrors()) { System.out.println(e.getLocalizedMessage()); } assertTrue(p.getValidationErrors().isEmpty()); }
@Test public void testListStoredQueries() throws Exception { MockHttpServletResponse response = getAsServletResponse("wfs?request=ListStoredQueries&service=wfs&version=2.0.0"); Document dom = dom(new ByteArrayInputStream(response.getContentAsByteArray())); XMLAssert.assertXpathExists( "//wfs:StoredQuery[@id = '" + StoredQuery.DEFAULT.getName() + "']", dom); // schema validate the response FeatureTypeSchemaBuilder sb = new FeatureTypeSchemaBuilder.GML3(getGeoServer()); WFSConfiguration configuration = new WFSConfiguration(getGeoServer(), sb, new org.geoserver.wfs.xml.v1_1_0.WFS(sb)); Parser parser = new Parser(configuration); parser.parse(new ByteArrayInputStream(response.getContentAsByteArray())); assertEquals(0, parser.getValidationErrors().size()); }