2016-06-12 91 views
2

我得到一個show-stopping錯誤,試圖從基本獲取JSON輸出JAX-RS設置。我想服務‘代碼NetBeans的已生成的這個默認的Web服務嚮導’:javax.servlet.ServletException:org.glassfish.jersey.server.ContainerException:java.lang.NoClassDefFoundError:org/xml/sax/helpers/DefaultHandler

package service; 

import entities.Manufacturer; 
import java.util.List; 
import javax.ejb.Stateless; 
import javax.persistence.EntityManager; 
import javax.persistence.PersistenceContext; 
import javax.ws.rs.Consumes; 
import javax.ws.rs.DELETE; 
import javax.ws.rs.GET; 
import javax.ws.rs.POST; 
import javax.ws.rs.PUT; 
import javax.ws.rs.Path; 
import javax.ws.rs.PathParam; 
import javax.ws.rs.Produces; 
import javax.ws.rs.core.MediaType; 


@Stateless 
@Path("entities.manufacturer") 
public class ManufacturerFacadeREST extends AbstractFacade<Manufacturer> { 

    @PersistenceContext(unitName = "RestDemoPU") 
    private EntityManager em; 

    public ManufacturerFacadeREST() { 
     super(Manufacturer.class); 
    } 

    @POST 
    @Override 
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 
    public void create(Manufacturer entity) { 
     super.create(entity); 
    } 

    @PUT 
    @Path("{id}") 
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 
    public void edit(@PathParam("id") Integer id, Manufacturer entity) { 
     super.edit(entity); 
    } 

    @DELETE 
    @Path("{id}") 
    public void remove(@PathParam("id") Integer id) { 
     super.remove(super.find(id)); 
    } 

    @GET 
    @Path("{id}") 
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 
    public Manufacturer find(@PathParam("id") Integer id) { 
     return super.find(id); 
    } 

    @GET 
    @Override 
    @Produces({MediaType.APPLICATION_JSON}) 
    public List<Manufacturer> findAll() { 
     return super.findAll(); 
    } 

    @GET 
    @Path("{from}/{to}") 
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) 
    public List<Manufacturer> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) { 
     return super.findRange(new int[]{from, to}); 
    } 

    @GET 
    @Path("count") 
    @Produces(MediaType.TEXT_PLAIN) 
    public String countREST() { 
     return String.valueOf(super.count()); 
    } 

    @Override 
    protected EntityManager getEntityManager() { 
     return em; 
    } 

} 

錯誤被顯示出來,當我刪除@Produces標註爲MediaType.APPLICATION_XMLfindAll()方法離開MediaType.APPLICATION_JSON(我只想JSON輸出)。

XML很好 - 僅JSON註釋引發了一個HTTP Status 500 - Internal Server Error Java異常:javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: org/xml/sax/helpers/DefaultHandler錯誤。

使用GlassFish 4.1.1。服務器日誌爲:

Info: EclipseLink, version: Eclipse Persistence Services - 2.6.1.v20150605-31e8258 
Info: /file:/home/lemon/code/java/Netbeans/RestDemo/build/web/WEB-INF/classes/_RestDemoPU login successful 
Warning: StandardWrapperValve[service.ApplicationConfig]: Servlet.service() for servlet service.ApplicationConfig threw exception 
java.lang.ClassNotFoundException: org.xml.sax.helpers.DefaultHandler not found by org.eclipse.persistence.moxy [6] 
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532) 
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75) 
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
    at org.eclipse.persistence.jaxb.BeanValidationHelper.<clinit>(BeanValidationHelper.java:53) 
    at org.eclipse.persistence.jaxb.JAXBBeanValidator.isConstrainedObject(JAXBBeanValidator.java:257) 
    at org.eclipse.persistence.jaxb.JAXBBeanValidator.shouldValidate(JAXBBeanValidator.java:208) 
    at org.eclipse.persistence.jaxb.JAXBMarshaller.validateAndTransformIfNeeded(JAXBMarshaller.java:587) 
    at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:481) 
    at org.eclipse.persistence.jaxb.rs.MOXyJsonProvider.writeTo(MOXyJsonProvider.java:949) 
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265) 
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250) 
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) 
    at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106) 
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) 
    at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86) 
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162) 
    at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130) 
    at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:683) 
    at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:424) 
    at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:414) 
    at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:312) 
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) 
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) 
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315) 
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297) 
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267) 
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) 
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:292) 
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1139) 
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:460) 
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386) 
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:334) 
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221) 
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) 
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) 
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) 
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) 
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) 
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206) 
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180) 
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) 
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) 
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283) 
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200) 
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132) 
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111) 
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) 
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536) 
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) 
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) 
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) 
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) 
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591) 
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571) 
    at java.lang.Thread.run(Thread.java:745) 

回答

1

從4.1.1降級到Glassfish 4.1解決了這個問題。

0

檢查您的JDK版本,使用JDK 1.7可以。

+0

使用JDK 1.7的結果相同。感謝您的建議。 – haircode

1

這是GlassFish https://java.net/jira/browse/GLASSFISH-21440中的一個已知錯誤,該錯誤實際上是在EclipseLink中,並且在上面的GlassFish錯誤報告中描述了一種解決方法。

您可以嘗試升級到Payara服務器,該問題已修復。

+0

切換到Payara是一個好主意 –

0

問題是在glashfish 4.1.1中缺少一個jar文件(jackson-module-jaxb-annotations)。你可以從這個鏈接下載http://www.java2s.com/Code/Jar/j/Downloadjacksonmodulejaxbannotations212jar.htm或谷歌下載傑克遜模塊jaxb註釋。然後將其包含在C:\ Program Files \ glassfish-4.1.1 \ glassfish \ modules主管中。您可以通過刪除版本號來重命名該jar文件。重新啓動glassfish並重新部署您的應用程序。它適用於我這種方式