Datei-Upload mit Spring WebFlow 2.4.0, Parameter nicht gebunden

Ich verwende Spring Framework 4.1.5, Spring Security 4.0.0.RC2, Spring Webflow 2.4.0.RELEASE und Tomcat 8.0.15.

Ich bin dem Beispiel im Webflow gefolgtDokumentatio, aber ich kann die Datei nicht in meinem Formular-Bean abrufen.

Die For

    <form:form action="${flowExecutionUrl}" method="post" commandName="fileForm" enctype="multipart/form-data">
        <form:input type="file" value="" path="multipartFileUpload"/>
        <button type="submit" name="_eventId_forward"><spring:message code="signup.forward"/></button>
        <sec:csrfInput/>
    </form:form>

The form bean

public class FileForm implements Serializable {
    private static final long serialVersionUID = 1L;

    private transient MultipartFile multipartFileUpload;

    public MultipartFile getMultipartFileUpload() {
        return multipartFileUpload;
    }

    public void setMultipartFileUpload(final MultipartFile multipartFileUpload) {
        this.multipartFileUpload = multipartFileUpload;
    }
}

Der Fluss

<view-state id="companyLogo" view="signup/company-logo" model="fileForm">
    <var name="fileForm" class="it.openex.pmcommonw.form.FileForm"/>
    <transition on="back" to="chooseProfile" bind="false" validate="false"/>
    <transition on="forward" to="companyInfo">
        <evaluate expression="userCommonBean.uploadImage(fileForm)"/>
    </transition>
</view-state>

Das Hintergrundobjekt

@Component
public class UserCommonBean {    
    public static void uploadImage(final FileForm fileForm) throws IOException, ServletException {
        fileForm.getMultipartFileUpload(); // always null!!!
    }
}

The multipartResolver

@Bean
public CommonsMultipartResolver filterMultipartResolver() {
    final CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
    multipartResolver.setMaxUploadSize(10 * 1024 * 1024);
    multipartResolver.setMaxInMemorySize(1048576);
    multipartResolver.setDefaultEncoding("UTF-8");
    return multipartResolver;
}

webflow configuration

@Configuration
public class WebFlowConfig extends AbstractFlowConfiguration {

    @Autowired
    TilesViewResolver viewResolver;

    @Bean
    public FlowDefinitionRegistry flowRegistry() {
        return getFlowDefinitionRegistryBuilder()
            .setFlowBuilderServices(flowBuilderServices())
            .setBasePath("/WEB-INF/flows/")
            .addFlowLocation("signup.xml", UrlMap.SIGNUP_WEBFLOW)
            .addFlowLocation("user-edit.xml", UrlMap.PROFILE_EDIT_WEBFLOW)
            .build();
    }

    @Bean
    public FlowExecutor flowExecutor() {
        return getFlowExecutorBuilder(flowRegistry()).build();
    }

    @Bean
    public FlowHandlerAdapter flowHandlerAdapter() {
        final FlowHandlerAdapter flowHandlerAdapter = new FlowHandlerAdapter();
        flowHandlerAdapter.setFlowExecutor(flowExecutor());
        return flowHandlerAdapter;
    }

    @Bean
    public FlowHandlerMapping flowHandlerMapping() {
        final FlowHandlerMapping flowHandlerMapping = new FlowHandlerMapping();
        flowHandlerMapping.setFlowRegistry(flowRegistry());
        // this has to be less than -1
        flowHandlerMapping.setOrder(-2);
        return flowHandlerMapping;
    }

    @Bean
    public MvcViewFactoryCreator mvcViewFactoryCreator() {
        final MvcViewFactoryCreator mvcViewFactoryCreator = new MvcViewFactoryCreator();
        final List<ViewResolver> viewResolvers = Collections.singletonList(viewResolver);
        mvcViewFactoryCreator.setViewResolvers(viewResolvers);
        return mvcViewFactoryCreator;
    }

    @Bean
    public FlowBuilderServices flowBuilderServices() {
        return getFlowBuilderServicesBuilder().setViewFactoryCreator(mvcViewFactoryCreator())
            .setValidator(localValidatorFactoryBean()).build();
    }

    @Bean
    public LocalValidatorFactoryBean localValidatorFactoryBean() {
        return new LocalValidatorFactoryBean();
    }
}

Inside Tomcat'scontext.xml Ich habe bereits hinzugefügtallowCasualMultipartParsing="true"

Debuggen der Anwendung Ich kann die Dateidaten in der Anforderung sehen und sie abrufen, wenn ich versuche, das Formular auf einem normalen Controller zu veröffentlichen.

Ich habe auch versucht, Spring Security zu entfernen, aber es funktionierte immer noch nicht in Spring WebFlow.

Im requestParameters-Objekt gibt es nur 3 Objekte:

Ausführun _eventid_forward _csrf

Es gibt einige relevante Zeilen in den Protokollen

DEBUG 2015-03-13 18:03:15,053: org.springframework.web.multipart.support.MultipartFilter - Using MultipartResolver 'filterMultipartResolver' for MultipartFilter
DEBUG 2015-03-13 18:03:15,053: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'filterMultipartResolver'
DEBUG 2015-03-13 18:03:15,053: org.springframework.web.multipart.support.MultipartFilter - Resolving multipart request [/registrazione] with MultipartFilter
DEBUG 2015-03-13 18:03:15,060: org.springframework.web.multipart.commons.CommonsMultipartResolver - Found multipart file [multipartFileUpload] of size 469217 bytes with original filename [PoliziaMunicipale.png], stored in memory
....
DEBUG 2015-03-13 18:03:15,072: org.springframework.binding.mapping.impl.DefaultMapper - Beginning mapping between source [org.springframework.webflow.core.collection.LocalParameterMap] and target [it.openex.pmcommonw.form.FileForm]
DEBUG 2015-03-13 18:03:15,072: org.springframework.binding.mapping.impl.DefaultMapping - Adding mapping result [TargetAccessError@34bc31ea mapping = parameter:'execution' -> execution, code = 'propertyNotFound', error = true, errorCause = org.springframework.binding.expression.PropertyNotFoundException: Property not found, originalValue = 'e1s2', mappedValue = [null]]
DEBUG 2015-03-13 18:03:15,072: org.springframework.binding.mapping.impl.DefaultMapper - Completing mapping between source [org.springframework.webflow.core.collection.LocalParameterMap] and target [it.openex.pmcommonw.form.FileForm]; total mappings = 1; total errors = 1

DasmultipartFileUpload -Eigenschaft ist im @ nicht gebundFileForm Bohne

Ich bin nicht sicher, ob es nützlich ist, aber inorg.springframework.webflow.context.servlet.HttpServletRequestParameterMap in Zeile 52

if (request instanceof MultipartHttpServletRequest) {
        // ... process multipart data
    }

it hat die Prüfung nicht bestanden, da die Anforderung eine Instanz von @ isorg.springframework.security.web.context.HttpSessionSecurityContextRepository$Servlet3SaveToSessionRequestWrapper

Update 1

Ich kann bestätigen, dass multipartRequest.getFile ("file") ebenfalls funktioniert.

Ich kann das @ nicht aktivierorg.springframework.web.multipart.support.MultipartFilter Filter obwohl.

Wenn es aktiviert ist, ist multipartRequest eine Instanz vonStandardMultipartHttpServletRequest mit einemServlet3SecurityContextHolderAwareRequestWrapper, ein @ einwickeServlet3SaveToSessionRequestWrapper, enthält endlich ein nicht erreichbaresDefaultMultipartHttpServletRequest mit der multipartFile, die ich brauche, aber ich kann es nicht bekommen.

Deaktiviere es Ich kann es bekommen, weil multipartRequest eine Instanz von @ wurDefaultMultipartHttpServletRequest, aber es gibt keine Dateiüberprüfung und die maximale Upload-Größe vonCommonsMultipartResolver wird nicht respektiert.

Plus Wenn Tomcat eine Ausnahme auslöst, weil die Datei für Tomcats maxPostSize-Limit zu groß ist, wird die Ausnahme von meinem @ abgefangeCustomAccessDeniedHandler weil sein Typ @ iorg.springframework.security.access.AccessDeniedException und die Fehlermeldung istInvalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'..

eim Betrachten des Anforderungsobjekts kann ich die ursprüngliche Tomcat-Ausnahme seheorg.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException. Es scheint, als gäbe es nichts, was man richtig handhaben könnte, aber wie gesagt, wenn ich den MultipartFilter aktiviere, bekomme ich die Datei nicht.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage