use of com.revolsys.geometry.io.GeometryReaderFactory in project com.revolsys.open by revolsys.
the class GeometryHttpMessageConverter method read.
@Override
public Geometry read(final Class<? extends Geometry> clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
final HttpHeaders headers = inputMessage.getHeaders();
final MediaType mediaType = headers.getContentType();
try {
Charset charset = mediaType.getCharSet();
if (charset == null) {
charset = StandardCharsets.UTF_8;
}
final InputStream body = inputMessage.getBody();
final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
final GeometryReaderFactory readerFactory = IoFactory.factoryByMediaType(GeometryReaderFactory.class, mediaTypeString);
if (readerFactory == null) {
throw new HttpMessageNotReadableException("Cannot read data in format" + mediaType);
} else {
final Reader<Geometry> reader = readerFactory.newGeometryReader(new InputStreamResource("geometryUpload", body));
GeometryFactory factory = this.geometryFactory;
final ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
final String srid = requestAttributes.getParameter("srid");
if (srid != null && srid.trim().length() > 0) {
factory = GeometryFactory.floating3d(Integer.parseInt(srid));
}
reader.setProperty(IoConstants.GEOMETRY_FACTORY, factory);
for (final Geometry geometry : reader) {
if (clazz.isAssignableFrom(geometry.getClass())) {
return geometry;
}
}
return null;
}
} catch (final Throwable e) {
Logs.error(this, "Error reading data using " + mediaType, e);
throw new HttpMessageNotReadableException("Error reading data using" + mediaType);
}
}
use of com.revolsys.geometry.io.GeometryReaderFactory in project com.revolsys.open by revolsys.
the class GeometryReaderHttpMessageConverter method read.
@Override
public GeometryReader read(final Class<? extends GeometryReader> clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
try {
final HttpHeaders headers = inputMessage.getHeaders();
final MediaType mediaType = headers.getContentType();
Charset charset = mediaType.getCharSet();
if (charset == null) {
charset = StandardCharsets.UTF_8;
}
final InputStream body = inputMessage.getBody();
final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
final GeometryReaderFactory readerFactory = IoFactory.factoryByMediaType(GeometryReaderFactory.class, mediaTypeString);
if (readerFactory == null) {
throw new HttpMessageNotReadableException("Cannot read data in format" + mediaType);
} else {
final InputStreamResource resource = new InputStreamResource("geometryInput", body);
final GeometryReader reader = readerFactory.newGeometryReader(resource);
GeometryFactory factory = this.geometryFactory;
final ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
final String srid = requestAttributes.getParameter("srid");
if (srid != null && srid.trim().length() > 0) {
factory = GeometryFactory.floating3d(Integer.parseInt(srid));
}
reader.setProperty(IoConstants.GEOMETRY_FACTORY, factory);
return reader;
}
} catch (final IOException e) {
throw new HttpMessageNotReadableException("Error reading data", e);
}
}
Aggregations