WebLogic 12.1.3中的JSON-B作为JDK 8的新功能

时间:2018-06-26 18:22:02

标签: java weblogic

我试图在运行于WebLogic 12c(12.1.3)中的简单RESTful中实现JSON-B,该项目的部署没有错误,但是在调用JsonbBuilder.create()

Resource.java

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String getText(String arg) {
    Jsonb jsonb = JsonbBuilder.create();
    RespSmsNexmo respFromJson = jsonb.fromJson(arg, RespSmsNexmo.class);

    return respFromJson.text;
}

它产生了这个:

INFO: Initiating Jersey application, version 'Jersey: 1.18.1 02/19/2014 03:28 AM'
    Jun 26, 2018 11:26:46 AM com.sun.jersey.server.impl.application.DeferredResourceConfig$ApplicationHolder <init>
INFO: Instantiated the Application class gt.com.atel.wgtm_0040.AplicationConfig
    Jun 26, 2018 11:49:44 AM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
    javax.json.bind.JsonbException: JSON Binding provider org.eclipse.yasson.JsonBindingProvider not found
        at javax.json.bind.spi.JsonbProvider.provider(JsonbProvider.java:120)
        at javax.json.bind.JsonbBuilder.create(JsonbBuilder.java:108)
        at gt.com.atel.wgtm_0040.GenericResource.getText(GenericResource.java:49)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
        at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
        at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
        at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
        at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
        at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
        at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)
        at weblogic.jaxrs.server.portable.servlet.ServletContainer.service(ServletContainer.java:219)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
        at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:243)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3432)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
        at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
        at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285)
        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201)
        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572)
        at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:263)
    Caused by: java.lang.ClassNotFoundException: org.eclipse.yasson.JsonBindingProvider
        at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:357)
        at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:318)
        at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:80)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:186)
        at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:50)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at javax.json.bind.spi.JsonbProvider.provider(JsonbProvider.java:117)
        ... 39 more

在pom.xml文件中,我没有声明任何依赖项,因为JDK 8足以使用JSON-B

pom.xml

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>8.0</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>8.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

我会很乐意解决这个问题。

WebLogic正在Java 8上运行,如下所示:

user    21599 21539  4 10:41 pts/17   00:06:00 /usr/lib/jvm/java-8-oracle/bin/java -server -Xms256m -Xmx512m -XX:CompileThreshold=8000 -XX:PermSize=128m -XX:MaxPermSize=256m -Dweblogic.Name=AdminServer -Djava.security.policy=/usr/local/weblogic/12.1.3/Oracle/Middleware/Oracle_Home/wlserver/server/lib/weblogic.policy -Dweblogic.security.SSL.ignoreHostnameVerification=true -Dssl.debug=true -DUseSunHttpHandler=true -Djsse.enableSNIExtension=false -Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true -Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true -Dcom.sun.xml.ws.transport.http.HttpAdapter.dump=true -Dcom.sun.xml.internal.ws.transport.http.HttpAdapter.dump=true -Dlog4j.configurationFile=/home/user/Devs/Git/ConfiguracionLogger/log4j2-config.xml -Dwebsisatel.logs=/home/user/logs/ -Xdebug -Xnoagent -Djava.compiler=none -Xrunjdwp:server=y,suspend=n,transport=dt_socket,address=8787 -da -Dwls.home=/usr/local/weblogic/12.1.3/Oracle/Middleware/Oracle_Home/wlserver/server -Dweblogic.home=/usr/local/weblogic/12.1.3/Oracle/Middleware/Oracle_Home/wlserver/server -Dweblogic.utils.cmm.lowertier.ServiceDisabled=true weblogic.Server

1 个答案:

答案 0 :(得分:2)

我做了一个简单的测试隔离,我的意思是,没有在WebLogic中部署应用程序,而是在终端中运行,并且我得到了非常相似的错误:

Exception in thread "main" javax.json.bind.JsonbException: JSON Binding provider org.eclipse.yasson.JsonBindingProvider not found
    at javax.json.bind.spi.JsonbProvider.provider(JsonbProvider.java:120)

经过研究,我发现here对于添加一些依赖关系是必需的:

<dependency>
    <groupId>javax.json.bind</groupId>
    <artifactId>javax.json.bind-api</artifactId>
    <version>1.0</version>
</dependency>

<dependency>
    <groupId>org.eclipse</groupId>
    <artifactId>yasson</artifactId>
    <version>1.0</version>
</dependency>

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.1</version>
</dependency>

测试可以按预期进行。 现在的主题是,我无法在添加此依赖项的WebLogic中部署项目。因此,我将在另一个线程中对此进行询问。