use of org.springframework.web.context.request.RequestAttributes in project com.revolsys.open by revolsys.
the class HttpMessageConverterView method renderMergedOutputModel.
@Override
protected void renderMergedOutputModel(final Map<String, Object> model, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
final String path = (String) requestAttributes.getAttribute("httpMessageConverterTemplatePath", RequestAttributes.SCOPE_REQUEST);
if (path == null || !Arrays.asList(MediaType.TEXT_HTML, MediaType.APPLICATION_XHTML_XML).contains(this.mediaType)) {
render(response);
} else {
final Charset charSet = this.mediaType.getCharSet();
if (charSet == null) {
response.setContentType(this.mediaType.toString() + "; charset=UTF-8");
} else {
response.setContentType(this.mediaType.toString());
}
final HttpMessageConverterView savedView = getMessageConverterView();
requestAttributes.setAttribute(NAME, this, RequestAttributes.SCOPE_REQUEST);
if (!PathViewController.include(request, response, path)) {
render(response);
}
requestAttributes.setAttribute(NAME, savedView, RequestAttributes.SCOPE_REQUEST);
}
}
use of org.springframework.web.context.request.RequestAttributes in project com.revolsys.open by revolsys.
the class HttpMessageConverterView method getMessageConverterView.
public static HttpMessageConverterView getMessageConverterView() {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
final HttpMessageConverterView view = (HttpMessageConverterView) requestAttributes.getAttribute(NAME, RequestAttributes.SCOPE_REQUEST);
return view;
}
use of org.springframework.web.context.request.RequestAttributes in project com.revolsys.open by revolsys.
the class PathAliasController method handleRequest.
@Override
public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
String path = request.getServletPath() + request.getPathInfo();
if (path.startsWith(this.prefix)) {
if (getOriginalPrefix().length() == 0) {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
requestAttributes.setAttribute(PATH_PREFIX, this.prefix.replaceAll(this.aliasPrefix + "$", ""), RequestAttributes.SCOPE_REQUEST);
}
path = path.replaceFirst(this.prefix, this.aliasPrefix);
if (!forward(request, response, path)) {
throw new PageNotFoundException();
}
}
return null;
}
use of org.springframework.web.context.request.RequestAttributes in project com.revolsys.open by revolsys.
the class RecordHttpMessageConverter method write.
@Override
public void write(final Record record, final MediaType mediaType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
if (!HttpServletUtils.getResponse().isCommitted()) {
if (record != null) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
requestAttributes.setAttribute(IoConstants.SINGLE_OBJECT_PROPERTY, true, RequestAttributes.SCOPE_REQUEST);
final ListRecordReader reader = new ListRecordReader(recordDefinition, record);
this.readerConverter.write(reader, mediaType, outputMessage);
}
}
}
use of org.springframework.web.context.request.RequestAttributes in project com.revolsys.open by revolsys.
the class RecordReaderHttpMessageConverter method write.
@Override
public void write(final RecordReader reader, final MediaType mediaType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
if (!HttpServletUtils.getResponse().isCommitted()) {
MediaType actualMediaType;
if (mediaType == null) {
actualMediaType = getDefaultMediaType();
} else {
actualMediaType = mediaType;
}
if (actualMediaType != null) {
final Charset charset = HttpServletUtils.setContentTypeWithCharset(outputMessage, actualMediaType);
final String mediaTypeString = actualMediaType.getType() + "/" + actualMediaType.getSubtype();
final RecordWriterFactory writerFactory = IoFactory.factoryByMediaType(RecordWriterFactory.class, mediaTypeString);
if (writerFactory == null) {
throw new IllegalArgumentException("Media type " + actualMediaType + " not supported");
} else {
final RecordDefinition recordDefinition = reader.getRecordDefinition();
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
String baseName = (String) requestAttributes.getAttribute("contentDispositionFileName", RequestAttributes.SCOPE_REQUEST);
if (baseName == null) {
baseName = HttpServletUtils.getRequestBaseFileName();
}
String contentDisposition = (String) requestAttributes.getAttribute("contentDisposition", RequestAttributes.SCOPE_REQUEST);
if (contentDisposition == null) {
contentDisposition = "attachment";
}
final String fileName = baseName + "." + writerFactory.getFileExtension(mediaTypeString);
final HttpHeaders headers = outputMessage.getHeaders();
headers.set("Content-Disposition", contentDisposition + "; filename=" + fileName);
final OutputStream body = outputMessage.getBody();
final Writer<Record> writer = writerFactory.newRecordWriter(baseName, recordDefinition, body, charset);
if (Boolean.FALSE.equals(requestAttributes.getAttribute("wrapHtml", RequestAttributes.SCOPE_REQUEST))) {
writer.setProperty(IoConstants.WRAP_PROPERTY, false);
}
final HttpServletRequest request = HttpServletUtils.getRequest();
String callback = request.getParameter("jsonp");
if (callback == null) {
callback = request.getParameter("callback");
}
if (callback != null) {
writer.setProperty(IoConstants.JSONP_PROPERTY, callback);
}
for (final String attributeName : requestAttributes.getAttributeNames(RequestAttributes.SCOPE_REQUEST)) {
final Object value = requestAttributes.getAttribute(attributeName, RequestAttributes.SCOPE_REQUEST);
if (value != null && attributeName.startsWith("java:") || this.requestAttributeNames.contains(attributeName)) {
writer.setProperty(attributeName, value);
}
}
final Iterator<Record> iterator = reader.iterator();
if (iterator.hasNext()) {
Record record = iterator.next();
final Geometry geometry = record.getGeometry();
if (geometry != null) {
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
writer.setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
}
writer.write(record);
while (iterator.hasNext()) {
record = iterator.next();
writer.write(record);
}
}
writer.close();
}
}
}
}
Aggregations