Example usage for org.springframework.web.multipart.support StandardMultipartHttpServletRequest getFileMap

List of usage examples for org.springframework.web.multipart.support StandardMultipartHttpServletRequest getFileMap

Introduction

In this page you can find the example usage for org.springframework.web.multipart.support StandardMultipartHttpServletRequest getFileMap.

Prototype

@Override
    public Map<String, MultipartFile> getFileMap() 

Source Link

Usage

From source file:io.pivotal.poc.gateway.filters.pre.XPathHeaderEnrichingFilter.java

@Override
protected void filter(RequestContext requestContext) {
    StandardMultipartHttpServletRequest multipartRequest = this
            .extractMultipartRequest(requestContext.getRequest());
    try {// ww  w.j  av a  2  s.  c om
        for (Map.Entry<String, MultipartFile> entry : multipartRequest.getFileMap().entrySet()) {
            String value = this.evaluateExpression(entry.getValue().getInputStream());
            if (value != null) {
                String headerName = String.format("%s.%s", entry.getKey(), key);
                log.info("adding header from xpath evaluation: {}={}", headerName, value);
                requestContext.getZuulRequestHeaders().put(headerName, value);
            }
        }
    } catch (Exception e) {
        log.error("xpath header enrichment failed", e);
    }
}

From source file:io.pivotal.poc.gateway.filters.pre.FileClaimCheckFilter.java

@Override
public void filter(RequestContext ctx) {
    StandardMultipartHttpServletRequest multipartRequest = this.extractMultipartRequest(ctx.getRequest());
    Map<String, String> uploadedFileMap = new HashMap<>();
    for (Map.Entry<String, MultipartFile> entry : multipartRequest.getFileMap().entrySet()) {
        String fileKey = entry.getKey();
        String claimCheck = store.save(new MultipartFileResource(entry.getValue()));
        uploadedFileMap.put(fileKey, claimCheck);
    }//  w ww.  j  a  v  a  2  s . co m
    try {
        String json = this.mapper.writeValueAsString(uploadedFileMap);
        FileClaimCheckRequestWrapper wrapper = null;
        HttpServletRequest request = ctx.getRequest();
        if (request instanceof HttpServletRequestWrapper) {
            HttpServletRequest wrapped = (HttpServletRequest) ReflectionUtils.getField(this.requestField,
                    request);
            if (wrapped instanceof HttpServletRequestWrapper) {
                wrapped = ((HttpServletRequestWrapper) wrapped).getRequest();
            }
            wrapper = new FileClaimCheckRequestWrapper(json, wrapped);
            ReflectionUtils.setField(this.requestField, request, wrapper);
            ReflectionUtils.setField(this.contentDataField, request, json.getBytes());
            if (request instanceof ServletRequestWrapper) {
                ReflectionUtils.setField(this.servletRequestField, request, wrapper);
            }
        } else {
            wrapper = new FileClaimCheckRequestWrapper(json, request);
            ctx.setRequest(wrapper);
        }
        if (wrapper != null) {
            ctx.getZuulRequestHeaders().put("content-type", wrapper.getContentType());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    log.info(String.format("%s request to %s", multipartRequest.getMethod(),
            multipartRequest.getRequestURL().toString()));
}