WAR文件中的eclipselink PersistenceUnitLoadingEception?

时间:2014-08-13 15:12:12

标签: java-ee websphere eclipselink websphere-8 websphere-liberty

我在这个问题上遇到了一个非常相似的错误:eclipselink PersistenceUnitLoadingEception in executable JAR

我正在部署WAS Liberty Profile V8.5。

将项目导出到WAR文件时;我无法改变包装。我不确定什么是错的,包装样式之间有什么区别。即便如此......我所有的依赖项(jar文件)都在server.xml中指定的目录中,所以我可以说我很困惑。

错误:

[ERROR   ] SRVE0321E: The [websphere.jaxrs.filters.ProjectAccessFilter] filter did not load during start up.
SRVE0320E: The [websphere.jaxrs.filters.ProjectAccessFilter] filter was found, but a resource injection failure has occurred.
[ERROR   ] SRVE0321E: The [websphere.jaxrs.filters.AuthorizationFilter] filter did not load during start up.
SRVE0320E: The [websphere.jaxrs.filters.AuthorizationFilter] filter was found, but a resource injection failure has occurred.
[ERROR   ] SRVE0315E: An exception occurred: com.ibm.ws.webcontainer.webapp.WebAppErrorReport: javax.servlet.ServletException: SRVE0320E: The [websphere.jaxrs.filters.AuthorizationFilter] filter was found, but a resource injection failure has occurred.
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager._loadFilter(WebAppFilterManager.java:615)
    at [internal classes]
Caused by: javax.servlet.ServletException: SRVE0320E: The [websphere.jaxrs.filters.AuthorizationFilter] filter was found, but a resource injection failure has occurred.
    ... 3 more
Caused by: com.ibm.wsspi.injectionengine.InjectionException: java.lang.reflect.InvocationTargetException
    at com.ibm.ws.webcontainer.webapp.WebApp.validateAndRun(WebApp.java:860)
    ... 1 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.ibm.ws.webcontainer.webapp.WebApp.validateAndRun(WebApp.java:847)
    ... 1 more
Caused by (repeated) ... : Exception [EclipseLink-30009] (Eclipse Persistence Services - 2.5.2.v20140222-22988a5): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while trying to load persistence unit at url: jar:file:/C:/wlp/usr/servers/dropServer/apps/WebApiConsole.war!/
Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.5.2.v20140222-22988a5): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while processing persistence.xml from URL: jar:file:/C:/wlp/usr/servers/dropServer/apps/WebApiConsole.war!/
Internal Exception: java.net.MalformedURLException
    ... 12 more
Caused by: java.net.MalformedURLException
    at java.net.URL.<init>(URL.java:619)
    at java.net.URL.<init>(URL.java:482)
    at java.net.URL.<init>(URL.java:431)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:610)
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)
    at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:636)
    ... 10 more
Caused by: java.lang.NullPointerException
    at java.net.URL.<init>(URL.java:524)

当我解压缩war文件时,我的persistence.xml文件的位置是:
WEB-INF /班/ META-INF / persistence.xml中
还有:/ META-INF / MANIFEST.MF

我不确定这是否有所不同,或者告诉eclipse停止制作这个额外的META-INF文件夹。

有趣的是,当我只是构建我的项目并使用.xml扩展名来引用我的类时,它完美无缺! (注意,当您简单地按“在服务器上运行”时,这是默认方式。)

WebApiConsole.war.xml:

<?xml version="1.0" encoding="UTF-8"?>
<archive>
    <dir sourceOnDisk="C:\eclipse\workspace\WebApiConsole\WebContent" targetInArchive="/"/>
    <dir sourceOnDisk="C:\eclipse\workspace\WebApiConsole\WebContent\WEB-INF\classes" targetInArchive="/WEB-INF/classes"/>
</archive>

这是过滤文件:

@WebFilter(description = "This filter intercepts all requests to the restful"
        + "webservice and checks whether the user is in the database", urlPatterns = { "/rest/*" })
public class AuthorizationFilter implements Filter {

    private static final String identifierCookieDomain = "null";
    private static final String identifierCookieName = "UID";
    private EntityManager em;

    public AuthorizationFilter() {}

    @PostConstruct
    public void init() {
        em = Persistence.createEntityManagerFactory("ConsoleManagement").createEntityManager();
    }

    public void doFilter(ServletRequest request,
                         ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        Cookie[] cookies;
        String uid = null;

        cookies = ((HttpServletRequest) request).getCookies();
        if ( cookies == null ) {
            ((HttpServletResponse) response).sendError(401, "Unauthorized Access: Please login");
        } else {

            uid = getCookie(request, identifierCookieDomain, identifierCookieName);

            if ( uid == null || !userExists(uid)) {
                ((HttpServletResponse) response).sendError(401, "Unauthorized Access: Please login");
            } else {
                chain.doFilter(request, response);
            }   
        }
    }

    public boolean userExists(String uid) {
        List<User> users = em.createNamedQuery("User.queryUserByUid", User.class)
                .setParameter("uid", uid)
                .getResultList();
        if (users.size() == 0) return false;
        return true;
    }

    public String getCookie(ServletRequest request, String domain, String name) {
        String value = null;
        Cookie[] cookies = ((HttpServletRequest) request).getCookies();
        for(Cookie cookie : cookies) {
            String cookieDomain = cookie.getDomain() == null ? "null" : cookie.getDomain();
            String cookieName = cookie.getName() == null ? "null" : cookie.getName();
            if ( cookieDomain.equals(domain) &&
                    cookieName.equals(name) ) {
                value = cookie.getValue();
                break;
            }
        }
        return value;
    }

    public void init(FilterConfig fConfig) throws ServletException {}

    @Override
    public void destroy() { }

}

1 个答案:

答案 0 :(得分:0)

这看起来像是一个EclipseLink错误。你能发帖到EclipseLink users邮件列表吗?我会在那边跟进你。

<强> [更新]

调试问题后,WebSphere Liberty中的问题已在Beta that was announced on 8/15/2014.中修复

<强> [/更新]

相关问题