1

I have a problem with using a composite component. When the component needs to be rerendered (because i have panels which are shown / hidden based on a user action) I got following error. (He wants to restore a class by creating a new instance of it with the default constructor, but he can't find / execute that constructor because it doesn't exist ? But I don't understand why he wants to do this and why it fails...):

I tried to run exactly the same code with wlp (websphere liberty profile) and there it works as a charm so I'm suspecting a problem in undertow !

=> when I look at the implementation of that class I don't find a default constructor in the class ( PartImpl code ) So it's logic that he can't create it, but why does he want to restore / create an instance of that server specific class ??

**java.lang.InstantiationException: io.undertow.servlet.spec.PartImpl io.undertow.servlet.spec.PartImpl.() **

This class is a Wildfly class (undertow is used by Wildfly) I suppose

While debugging I found out this code:

  • this: StateHolderSaver@30209
  • classname: io.undertow.servlet.spec.PartImpl
  • result: null (throws exception below)

    try {
        toRestoreClass = loadClass(className, this);
    }
    catch (ClassNotFoundException e) {
        throw new IllegalStateException(e);
    } 
    

    if (null != toRestoreClass) { try { result = toRestoreClass.newInstance(); } catch (InstantiationException e) { throw new IllegalStateException(e); }

Here is the error:

ERROR javax.enterprise.resource.webcontainer.jsf.context  - java.lang.IllegalStateException: java.lang.InstantiationException: io.undertow.servlet.spec.PartImpl
at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:153)
at javax.faces.component.ComponentStateHelper.restoreState(ComponentStateHelper.java:303)
at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1629)
at javax.faces.component.UIOutput.restoreState(UIOutput.java:286)
at javax.faces.component.UIInput.restoreState(UIInput.java:1420)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy$2.visit(FaceletPartialStateManagementStrategy.java:379)
at com.sun.faces.component.visit.FullVisitContext.invokeVisitCallback(FullVisitContext.java:151)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1689)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at com.sun.faces.application.view.FaceletPartialStateManagementStrategy.restoreView(FaceletPartialStateManagementStrategy.java:366)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:138)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:591)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:151)
at org.ocpsoft.rewrite.faces.RewriteViewHandler.restoreView(RewriteViewHandler.java:102)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:353)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:353)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:353)
at org.omnifaces.viewhandler.OmniViewHandler.restoreView(OmniViewHandler.java:104)
at javax.faces.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:353)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:199)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)


at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:226)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at be.raes.web.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:22)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at be.raes.web.filter.SecurityFilter.doFilter(SecurityFilter.java:129)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at be.raes.web.filter.LanguageResolverFilter.doFilter(LanguageResolverFilter.java:49)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.jrHandle(ServletInitialHandler.java)
at sun.reflect.GeneratedMethodAccessor245.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Some important last part:

Caused by: java.lang.InstantiationException: io.undertow.servlet.spec.PartImpl
at java.lang.Class.newInstance(Class.java:427)
at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:150)
... 86 more

Caused by: java.lang.NoSuchMethodException: io.undertow.servlet.spec.PartImpl.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 87 more

Here is my component code:

<cc:interface componentType="fileComponent">
<cc:attribute name="label" type="java.lang.String"/>
<cc:attribute name="value" type="java.lang.Object"/>
<cc:attribute name="action" method-signature="void listener()"/></cc:interface>

<cc:implementation>
<uc:component id="#{cc.clientId}"
              composite="true">

    <uc:fileUpload id="fileUpload"
                   label="#{cc.attrs.label}"
                   value="#{cc.file}"
                   action="#{cc.uploadFile}"
                   render="#{cc.clientId}"
                   displayed="#{empty cc.fileContainer}"
                   accept="image/png,
                           image/jpeg"/>

    <uc:component id="fileContainer"
                  label="#{cc.attrs.label}"
                  displayed="#{not empty cc.fileContainer}">

            <h:commandLink ajax="true">
                <p:fileDownload value="#{cc.downloadFileContainer}"/>
            </h:commandLink>

        <o:commandScript name="action"
                         actionListener="#{cc.attrs.action}"
                         render=":#{cc.clientId}"
                         execute=":#{cc.clientId}"/>

    </uc:component>

</uc:component>

Component class:

@FacesComponent("fileComponent")
public class FileComponent extends UIInput implements NamingContainer {
@Override
public String getFamily() {
    return UINamingContainer.COMPONENT_FAMILY;
}

@Override
public Object getSubmittedValue() {
    return getFileContainer();
}

public FileContainer createFileContainer() {
    return new FileContainer();
}

public void uploadFile() throws IOException {
    FileContainer fileContainer = createFileContainer(); 



fileContainer.setFileName(FilenameUtils.getName(getFile().getSubmittedFileName()));
    fileContainer.setContent(Utils.toByteArray(getFile().getInputStream()));

    setFileContainer(fileContainer);
}

public void downloadFileContainer() throws IOException {
    Faces.sendFile(getFileContainer().getContent(), getFileContainer().getFileName(), true);
}

public Part getFile() {
    return (Part) getStateHelper().eval("file");
}

public void setFile(Part file) {
    getStateHelper().put("file", file);
}

public FileContainer getFileContainer() {
    return (FileContainer) getStateHelper().eval("filecontainer", getValue());
}

public void setFileContainer(FileContainer fileContainer) {
    getStateHelper().put("filecontainer", fileContainer);
}

}

JSF file (usage of component):

... <mc:fileComponent value="#{bean.fileContainer}" /> ...

Backing bean

@ViewScoped
@Named("bean")
public class Bean implements Serializable {
  private FileContainer fileContainer;
  //getters & setters etc
}

components.taglib.xml:

 ...<tag>
    <tag-name>fileComponent</tag-name>
    <component>
        <resource-id>components/fileComponent.xhtml</resource-id>
    </component>
    <attribute>
        <name>id</name>
    </attribute>
    <attribute>
        <name>label</name>
    </attribute>
    <attribute>
        <name>value</name>
        <required>true</required>
    </attribute>
    <attribute>
        <name>action</name>
    </attribute>
</tag>...

Tech Stack: (java 8 & EE7 & primefaces 6.1 & Wildfly 10.1)

Thank you for the help

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
scarvy
  • 11
  • 2
  • The Class **IS** found. you don't get a 'ClassNotFoundException' but an instantiation exception due to `Caused by: java.lang.NoSuchMethodException: io.undertow.servlet.spec.PartImpl.()` What more is in your `@FacesComponent`? Please make it into a simple [mcve] (e.g. does it work when you don't use a composite?) – Kukeltje Feb 19 '18 at 13:13
  • Sorry, indeed it's the method from that class (constructor i think) that doesn't exist or can't be executed. I updated my question with more code. And about the error, the StateHolderSaver wants to restore the view (with context PrimeFacesContext) , when he loads that class it gives something back and then he tries to create a new instance but fails I will put the code where it fails in my question to make it more clear I hope. Thank you already for your reply – scarvy Feb 19 '18 at 22:16

0 Answers0