Skip to content

Commit

Permalink
Updated MapML Spring MessageConverter configuration to work properly …
Browse files Browse the repository at this point in the history
…with Geoserver REST module's Spring configuration
  • Loading branch information
cmhodgson committed May 7, 2019
1 parent 6270dbe commit eca5d44
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 21 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@


package org.geoserver.mapml; package org.geoserver.mapml;


import java.nio.charset.Charset;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import org.springframework.http.MediaType;


public final class MapMLConstants { public final class MapMLConstants {


/** format mime type */ /** format mime type */
public static final String MIME_TYPE = "text/mapml"; public static final String MAPML_MIME_TYPE = "text/mapml";

/** format MediaType */
public static final MediaType MAPML_MEDIA_TYPE =
new MediaType("text", "mapml", Charset.forName("UTF-8"));


/** format name */ /** format name */
public static final String FORMAT_NAME = "MAPML"; public static final String FORMAT_NAME = "MAPML";
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class MapMLController {
@RequestMapping( @RequestMapping(
value = "/{layer}/{proj}", value = "/{layer}/{proj}",
method = {RequestMethod.GET, RequestMethod.POST}, method = {RequestMethod.GET, RequestMethod.POST},
produces = MIME_TYPE produces = MAPML_MIME_TYPE
) )
public Mapml mapML( public Mapml mapML(
HttpServletRequest request, HttpServletRequest request,
Expand Down Expand Up @@ -160,7 +160,7 @@ public Mapml mapML(
metas.add(meta); metas.add(meta);
meta = new Meta(); meta = new Meta();
meta.setHttpEquiv("Content-Type"); meta.setHttpEquiv("Content-Type");
meta.setContent(MIME_TYPE + ";projection=" + projType.value()); meta.setContent(MAPML_MIME_TYPE + ";projection=" + projType.value());
metas.add(meta); metas.add(meta);
meta = new Meta(); meta = new Meta();
meta.setName("projection"); meta.setName("projection");
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MapMLGetFeatureInfoOutputFormat extends GetFeatureInfoOutputFormat
private WMS wms; private WMS wms;


public MapMLGetFeatureInfoOutputFormat(WMS wms) { public MapMLGetFeatureInfoOutputFormat(WMS wms) {
super(MapMLConstants.MIME_TYPE); super(MapMLConstants.MAPML_MIME_TYPE);
this.wms = wms; this.wms = wms;
} }


Expand Down Expand Up @@ -80,7 +80,7 @@ public void write(
metas.add(meta); metas.add(meta);
meta = new Meta(); meta = new Meta();
meta.setHttpEquiv("Content-Type"); meta.setHttpEquiv("Content-Type");
meta.setContent(MapMLConstants.MIME_TYPE); // ;projection=" + projType.value()); meta.setContent(MapMLConstants.MAPML_MIME_TYPE); // ;projection=" + projType.value());
metas.add(meta); metas.add(meta);
mapml.setHead(head); mapml.setHead(head);


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public MapMLGetFeatureOutputFormat(GeoServer gs) {


@Override @Override
public String getMimeType(Object value, Operation operation) throws ServiceException { public String getMimeType(Object value, Operation operation) throws ServiceException {
return MapMLConstants.MIME_TYPE; return MapMLConstants.MAPML_MIME_TYPE;
} }


@Override @Override
Expand Down Expand Up @@ -89,7 +89,7 @@ protected void write(
metas.add(meta); metas.add(meta);
meta = new Meta(); meta = new Meta();
meta.setHttpEquiv("Content-Type"); meta.setHttpEquiv("Content-Type");
meta.setContent(MapMLConstants.MIME_TYPE); // ;projection=" + projType.value()); meta.setContent(MapMLConstants.MAPML_MIME_TYPE); // ;projection=" + projType.value());
metas.add(meta); metas.add(meta);
List<Link> links = head.getLinks(); List<Link> links = head.getLinks();


Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.geoserver.mapml;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import org.geoserver.rest.converters.BaseMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

public class MapMLMessageConverter extends BaseMessageConverter<Object> {

@Autowired private Jaxb2Marshaller mapmlMarshaller;

public MapMLMessageConverter() {
super(MapMLConstants.MAPML_MEDIA_TYPE);
}

@Override
public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType) {
return false;
}

@Override
public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) {
return (canWrite(mediaType) && mapmlMarshaller.supports(clazz));
}

@Override
protected boolean supports(Class<?> clazz) {
// should not be called, since we override canRead()/canWrite()
throw new UnsupportedOperationException();
}

@Override
protected void writeInternal(Object o, HttpOutputMessage outputMessage)
throws UnsupportedEncodingException, IOException {
OutputStreamWriter osw =
new OutputStreamWriter(
outputMessage.getBody(), geoServer.getSettings().getCharset());
Result result = new StreamResult(osw);
mapmlMarshaller.marshal(o, result);
osw.flush();
}
}
16 changes: 2 additions & 14 deletions src/community/mapml/src/main/resources/applicationContext.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,19 +27,7 @@
<bean id="wmsGetFeatureInfoMapML" class="org.geoserver.mapml.MapMLGetFeatureInfoOutputFormat"> <bean id="wmsGetFeatureInfoMapML" class="org.geoserver.mapml.MapMLGetFeatureInfoOutputFormat">
<constructor-arg ref="wms"/> <constructor-arg ref="wms"/>
</bean> </bean>
<mvc:annotation-driven> <bean class="org.geoserver.mapml.MapMLMessageConverter" id="mapmlMessageConverter"/>
<mvc:message-converters>
<bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="mapmlMarshaller"></property>
<property name="unmarshaller" ref="mapmlMarshaller"></property>
<property name="supportedMediaTypes">
<list>
<value>text/mapml</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller" id="mapmlMarshaller"> <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller" id="mapmlMarshaller">
<property name="contextPath" value="org.geoserver.mapml.xml"/> <property name="contextPath" value="org.geoserver.mapml.xml"/>
<property name="marshallerProperties"> <property name="marshallerProperties">
Expand All @@ -52,5 +40,5 @@
</entry> </entry>
</map> </map>
</property> </property>
</bean> </bean>
</beans> </beans>

0 comments on commit eca5d44

Please sign in to comment.