-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated MapML Spring MessageConverter configuration to work properly …
…with Geoserver REST module's Spring configuration
- Loading branch information
Showing
6 changed files
with
64 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/community/mapml/src/main/java/org/geoserver/mapml/MapMLMessageConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters