[Geoserver-users] ExternalGraphicFactory custom URL causes java.net.MalformedURLException: unknown protocol

Hello,

I am using an ExternalGraphicFactory that returns an ImageIcon to display symbols for surface observations in GeoServer, and so I have registered my class in GeoTools with the META-INF/services/org.geotools.renderer.style.ExternalGraphicFactory file. The problem is, any SLD containing such custom URLs won't validate due to "not a valid 'anyURI' value", and when a layer with such an SLD is viewed, rather than handing the href to my Factory, GeoServer has an error:

15 Jan 01:54:09 ERROR [geoserver.ows] -
java.lang.RuntimeException: Errors while inspecting the location of an external graphic
...
Caused by: java.net.MalformedURLException: unknown protocol: sfcobs
         at java.net.URL.<init>(URL.java:574)
         at java.net.URL.<init>(URL.java:464)
         at java.net.URL.<init>(URL.java:413)
         at org.geotools.styling.ExternalGraphicImpl.getLocation(ExternalGraphicImpl.java:65)
         at org.geotools.styling.StyleAttributeExtractor.visit(StyleAttributeExtractor.java:446)
  ... 65 more

I checked the mailing list, and there doesn't seem to be a lot of discussion of the ExternalGraphicFactory system.

Here's a small SLD example; the URL looks like sfcobs://vv={$obs_vv} , where ${obs_vv} comes from the Feature.

<sld:StyledLayerDescriptor version="1.0.0" xmlns:gml="http://www.opengis.net/gml&quot;
   xmlns:ows="http://www.opengis.net/ows&quot; xmlns:sld="http://www.opengis.net/sld&quot;
   xmlns:wms="http://www.opengis.net/ows&quot; xmlns:xlink="http://www.w3.org/1999/xlink&quot;
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.opengis.net/ows http://sun420:8888/geoserver/schemas/sld/GetMap.xsd&quot;&gt;
   <sld:NamedLayer>
   <sld:Name>Not working</sld:Name>
    <UserStyle xmlns="http://www.opengis.net/sld&quot;&gt;
     <FeatureTypeStyle>
      <Rule>
             <PointSymbolizer>
                 <sld:Graphic>
                     <sld:ExternalGraphic>
                         <sld:OnlineResource
                          xlink:href="sfcobs://vv=${obs_vv}"/>
                         <Format>image/png</Format>
                     </sld:ExternalGraphic>
                     <sld:Size>15.0</sld:Size>
                </sld:Graphic>
            </PointSymbolizer>
      </Rule>
     </FeatureTypeStyle>
    </UserStyle>
   </sld:NamedLayer>
  </sld:StyledLayerDescriptor>

This seems close to the example SLD on http://geotools.codehaus.org/Dynamic+SLD+Graphic+objects .

Has anyone got a Factory to work with such non-standard URLs?

--
Nissim Chudnoff

Nissim Chudnoff ha scritto:

Hello,

I am using an ExternalGraphicFactory that returns an ImageIcon to display symbols for surface observations in GeoServer, and so I have registered my class in GeoTools with the META-INF/services/org.geotools.renderer.style.ExternalGraphicFactory file. The problem is, any SLD containing such custom URLs won't validate due to "not a valid 'anyURI' value", and when a layer with such an SLD is viewed, rather than handing the href to my Factory, GeoServer has an error:

Ouch right, I was aware of that issue but nobody worked on custom
external graphics factory so never found the time to fix it.
What is needed is a custom url handler that accepts the prefixes
created by the dynamic graphic factories.

I haven't looked into this deeply but I believe this article might
provide enough guidance:

http://java.sun.com/developer/onlineTraining/protocolhandlers/

Let me know if you are able to pull this up (and if so, can you provide a patch). If not, I'll have a look when I have some spare time.

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.