/** * gets the message, encoding it with the proper escaped xml characters. If requested it prints * the whole stack trace in the response. * * @param printStackTrace set to <tt>true</tt> if the full stack trace should be returned to * client apps. * @return The message of this error, with xml escapes. * @task REVISIT: The stack trace printing is not that efficient, but it should be relatively * small. Once we convert errors to print directly to the servlet output stream we can make * it faster. */ public String getXmlMessage(boolean printStackTrace) { StringBuffer mesg = new StringBuffer(); // this distinction no longer so much applies, as we don't always // throw Service exceptions for all expected exceptions. // if (!isEmpty(this.preMessage)) { // mesg.append(this.preMessage + ": "); // } // mesg.append(ResponseUtils.encodeXML(this.getMessage()) + "\n"); // if (printStackTrace) { if (printStackTrace) { mesg.append(createStackTrace()); } else { mesg.append(this.getMessage()); } return ResponseUtils.encodeXML(mesg.toString()); }
public static List validate( Source xml, URL schemaURL, boolean skipTargetNamespaceException, EntityResolver entityResolver) { try { Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(schemaURL); Validator v = schema.newValidator(); if (entityResolver != null) { v.setResourceResolver( new EntityResolverToLSResourceResolver( v.getResourceResolver(), entityResolver)); } Handler handler = new Handler(skipTargetNamespaceException, entityResolver); v.setErrorHandler(handler); v.validate(xml); return handler.errors; } catch (SAXException e) { return exception(e); } catch (IOException e) { return exception(e); } }
/** * Profixies a data link url interpreting a localhost url as a back reference to the server. * * <p>If <tt>link</tt> is not a localhost url it is left untouched. */ public static String proxifyDataLink(DataLinkInfo link, String baseURL) { String content = link.getContent(); content = proxifyLink(content, baseURL); return content; }
@Test public void testProxyMetadataURLBackReferenceNoProxyBaseUrl() throws Exception { createAppContext(null); MetadataLinkInfo link = new MetadataLinkInfoImpl(); link.setContent("/metadata.xml?foo=bar"); String url = ResponseUtils.proxifyMetadataLink(link, "http://localhost/geoserver"); assertEquals("http://localhost/geoserver/metadata.xml?foo=bar", url); }
@Test public void testProxyDataURLBackReference() throws Exception { createAppContext("http://foo.org/geoserver"); DataLinkInfo link = new DataLinkInfoImpl(); link.setContent("/metadata.xml?foo=bar"); String url = ResponseUtils.proxifyDataLink(link, "http://localhost/geoserver"); assertEquals("http://foo.org/geoserver/metadata.xml?foo=bar", url); }
/** * validate a .sld against the schema * * @param xml input stream representing the .sld file * @return list of SAXExceptions (0 if the file's okay) */ public List validateSLD(InputSource xml) { URL schemaURL = SLDValidator.class.getResource("/schemas/sld/StyledLayerDescriptor.xsd"); return ResponseUtils.validate(xml, schemaURL, false, entityResolver); } }
@Test public void testProxyMetadataURLBackReference() throws Exception { createAppContext("http://foo.org/geoserver"); MetadataLinkInfo link = new MetadataLinkInfoImpl(); link.setContent("/metadata.xml?foo=bar"); String url = ResponseUtils.proxifyMetadataLink(link, "http://localhost/geoserver"); assertEquals("http://foo.org/geoserver/metadata.xml?foo=bar", url); }
@Test public void testDataURLBackReferenceNoProxyBaseUrl() throws Exception { createAppContext(null); DataLinkInfo link = new DataLinkInfoImpl(); link.setContent("/metadata.xml?foo=bar"); String url = ResponseUtils.proxifyDataLink(link, "http://localhost/geoserver"); assertEquals("http://localhost/geoserver/metadata.xml?foo=bar", url); } }
public static List validate( InputSource xml, URL schemaURL, boolean skipTargetNamespaceException, EntityResolver entityResolver) { StreamSource source = null; if (xml.getCharacterStream() != null) { source = new StreamSource(xml.getCharacterStream()); } else if (xml.getByteStream() != null) { source = new StreamSource(xml.getByteStream()); } else { throw new IllegalArgumentException("Could not turn input source to stream source"); } return validate(source, schemaURL, skipTargetNamespaceException, entityResolver); }
@Test public void testProxyMetadataURL() throws Exception { createAppContext("http://foo.org/geoserver"); MetadataLinkInfo link = new MetadataLinkInfoImpl(); link.setContent("http://bar.com/geoserver/metadata.xml?foo=bar"); String url = ResponseUtils.proxifyMetadataLink(link, "http://localhost/geoserver"); assertEquals(link.getContent(), url); }
@Test public void testProxyDataURL() throws Exception { createAppContext("http://foo.org/geoserver"); DataLinkInfo link = new DataLinkInfoImpl(); link.setContent("http://bar.com/geoserver/metadata.xml?foo=bar"); String url = ResponseUtils.proxifyDataLink(link, "http://localhost/geoserver"); assertEquals(link.getContent(), url); }
/** * validate a GETMAP against the schema * * @param xml input stream representing the GETMAP file * @param SchemaUrl location of the schemas. Normally use * ".../capabilities/sld/StyleLayerDescriptor.xsd" * @return list of SAXExceptions (0 if the file's okay) */ public List validateGETMAP(InputSource xml, URL SchemaUrl) { EntityResolverProvider provider = GeoServerExtensions.bean(EntityResolverProvider.class); return ResponseUtils.validate(xml, SchemaUrl, true, provider.getEntityResolver()); } }
/** * Profixies a metadata link url interpreting a localhost url as a back reference to the server. * * <p>If <tt>link</tt> is not a localhost url it is left untouched. */ public static String proxifyMetadataLink(MetadataLinkInfo link, String baseURL) { String content = link.getContent(); content = proxifyLink(content, baseURL); return content; }
protected void handleMetadataLink(MetadataLinkInfo mdl, String linkType) { AttributesImpl attributes = new AttributesImpl(); if ((mdl.getAbout() != null) && (mdl.getAbout() != "")) { attributes.addAttribute("", "about", "about", "", mdl.getAbout()); } if ((linkType != null) && (linkType != "")) { attributes.addAttribute("", "xlink:type", "xlink:type", "", linkType); } if ((mdl.getContent() != null) && (mdl.getContent() != "")) { attributes.addAttribute( "", "xlink:href", "xlink:href", "", ResponseUtils.proxifyMetadataLink(mdl, request.getBaseUrl())); element("ows:Metadata", null, attributes); } }
/** * Turns the data URL list to XML * * @param keywords */ private void handleDataList(Collection<DataLinkInfo> dataURLs) { if (dataURLs == null) { return; } for (DataLinkInfo link : dataURLs) { start("DataURL"); element("Format", link.getType()); String content = ResponseUtils.proxifyDataLink(link, request.getBaseUrl()); AttributesImpl orAtts = new AttributesImpl(); orAtts.addAttribute("", "xmlns:xlink", "xmlns:xlink", "", XLINK_NS); orAtts.addAttribute(XLINK_NS, "xlink:type", "xlink:type", "", "simple"); orAtts.addAttribute("", "xlink:href", "xlink:href", "", content); element("OnlineResource", null, orAtts); end("DataURL"); } }
/** * Turns the metadata URL list to XML * * @param keywords */ private void handleMetadataList(Collection<MetadataLinkInfo> metadataURLs) { if (metadataURLs == null) { return; } for (MetadataLinkInfo link : metadataURLs) { if (!SUPPORTED_MDLINK_TYPES.contains(link.getMetadataType())) { continue; } AttributesImpl lnkAtts = new AttributesImpl(); lnkAtts.addAttribute("", "type", "type", "", link.getMetadataType()); start("MetadataURL", lnkAtts); element("Format", link.getType()); String content = ResponseUtils.proxifyMetadataLink(link, request.getBaseUrl()); AttributesImpl orAtts = new AttributesImpl(); orAtts.addAttribute("", "xmlns:xlink", "xmlns:xlink", "", XLINK_NS); orAtts.addAttribute(XLINK_NS, "xlink:type", "xlink:type", "", "simple"); orAtts.addAttribute("", "xlink:href", "xlink:href", "", content); element("OnlineResource", null, orAtts); end("MetadataURL"); } }
/** * Turns the data URL list to XML * * @param keywords */ private void handleDataList(Collection<DataLinkInfo> dataURLs) { if (dataURLs == null) { return; } for (DataLinkInfo link : dataURLs) { start("DataURL"); element("Format", link.getType()); String content = ResponseUtils.proxifyDataLink(link, request.getBaseUrl()); AttributesImpl orAtts = attributes("xlink:type", "simple", "xlink:href", content); element("OnlineResource", null, orAtts); end("DataURL"); } }
String url = ResponseUtils.proxifyMetadataLink(gsMetadata, baseUrl); try { gwcMetadataLinks.add(
element( "MetadataURL", ResponseUtils.proxifyMetadataLink(link, request.getBaseUrl()), mtAtts);
protected void handleMetadataLink(MetadataLinkInfo mdl, String linkType) { AttributesImpl attributes = new AttributesImpl(); if ((mdl.getAbout() != null) && (mdl.getAbout() != "")) { attributes.addAttribute("", "about", "about", "", mdl.getAbout()); } if ((mdl.getMetadataType() != null) && (mdl.getMetadataType() != "")) { attributes.addAttribute( "", "metadataType", "metadataType", "", mdl.getMetadataType()); } if ((linkType != null) && (linkType != "")) { attributes.addAttribute("", "xlink:type", "xlink:type", "", linkType); } if ((mdl.getContent() != null) && (mdl.getContent() != "")) { attributes.addAttribute( "", "xlink:href", "xlink:href", "", ResponseUtils.proxifyMetadataLink(mdl, request.getBaseUrl())); } if (attributes.getLength() > 0) { element("ows:Metadata", null, attributes); } }