在Websphere Liberty 18.0.0.1中运行Moxy 2.7.1

时间:2018-07-20 14:24:23

标签: websphere-liberty moxy

我正在尝试在小型REST服务中使用moxy mashaller。以下是代码片段:

  @GET
  @Path("ping")
  @Produces(MediaType.APPLICATION_JSON)
  public String transform() {
    StringWriter result = new StringWriter();
    try {
     JAXBContext context = JAXBContext.newInstance(Partner.class);
     Marshaller marshaller = context.createMarshaller();
     marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

     marshaller.marshal(new Partner(), result);
    } catch (JAXBException e) {
     e.printStackTrace();
     throw new RuntimeException(e);
   }
  return result.toString();
 }

该服务通过以下server.xml部署在Websphere libty 18.0.0.1中:

<server description="Moxy">
<featureManager>
  <feature>javaee-7.0</feature>
  <feature>localConnector-1.0</feature>
</featureManager>
<applicationManager autoExpand="true" />
<applicationMonitor updateTrigger="mbean" />

我的pom依赖项:

<dependencies>
  <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>org.eclipse.persistence.moxy</artifactId>
    <version>2.7.1</version>
   </dependency>
   <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
   </dependency>
 </dependencies>

调用服务时,出现以下异常:

Caused by: javax.xml.bind.JAXBException: Unable to create context
 - with linked exception:
[java.lang.reflect.InvocationTargetException]
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:116)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:65)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:56)
    at de.signaliduna.moxy.PartnerResource.ping(PartnerResource.java:27)
    ... 51 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:114)
    ... 54 more
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    org/eclipse/persistence/jaxb/compiler/Generator.generateSchemaFiles(Ljavax/xml/bind/SchemaOutputResolver;Ljava/util/Map;)Ljava/util/Map; @90: invokevirtual
  Reason:
    Type 'org/eclipse/persistence/internal/oxm/schema/SchemaModelProject' (current frame, stack[0]) is not assignable to 'org/eclipse/persistence/core/sessions/CoreProject'
  Current Frame:
    bci: @90
    flags: { }
    locals: { 'org/eclipse/persistence/jaxb/compiler/Generator', 'javax/xml/bind/SchemaOutputResolver', 'java/util/Map', 'org/eclipse/persistence/internal/oxm/schema/SchemaModelProject', 'org/eclipse/persistence/oxm/XMLContext', 'org/eclipse/persistence/oxm/XMLMarshaller' }
    stack: { 'org/eclipse/persistence/internal/oxm/schema/SchemaModelProject', 'java/lang/Class' }
  Bytecode:
    0x0000000: 2a2c 2ab4 002c b700 c22a b400 312a b400
    0x0000010: 2cb6 0093 2ab4 002c b600 972a b400 2cb6
    0x0000020: 009a 2ab4 002c b600 9d2a b400 2cb6 00a0
    0x0000030: 2ab4 002c b600 8d2b b601 3abb 00c6 59b7
    0x0000040: 00c8 4ebb 00c9 592d c000 cbb7 00cd 3a04
    0x0000050: 1904 b600 d03a 052d 12d4 b600 d6c0 00dc
    0x0000060: 3a06 2ab4 0031 b600 ba3a 0719 07b9 00de
    0x0000070: 0100 3a09 a700 5f19 09b9 00e4 0100 c000
    0x0000080: d43a 0819 08b6 0102 3a0a 190a 1301 0613
    0x0000090: 0108 b601 0a19 0619 0ab9 0110 0200 1908
    0x00000a0: b601 3d99 000d 1908 b601 403a 0ba7 0013
    0x00000b0: 2b19 08b6 0144 1908 b600 fab6 0147 3a0b
    0x00000c0: 1905 1908 190b b601 4da7 000a 3a0a 190a
    0x00000d0: b601 5019 09b9 011f 0100 9aff 9d2a b400
    0x00000e0: 31b6 0122 b0                           
  Exception Handler Table:
    bci [131, 201] => handler: 204
  Stackmap Table:
    full_frame(@119,{Object[#1],Object[#328],Object[#81],Object[#215],Object[#201],Object[#282],Object[#220],Object[#223],Top,Object[#229]},{})
    full_frame(@176,{Object[#1],Object[#328],Object[#81],Object[#215],Object[#201],Object[#282],Object[#220],Object[#223],Object[#212],Object[#229],Object[#267]},{})
    append_frame(@192,Object[#347])
    full_frame(@204,{Object[#1],Object[#328],Object[#81],Object[#215],Object[#201],Object[#282],Object[#220],Object[#223],Object[#212],Object[#229]},{Object[#337]})
    full_frame(@211,{Object[#1],Object[#328],Object[#81],Object[#215],Object[#201],Object[#282],Object[#220],Object[#223],Top,Object[#229]},{})

我是否必须激活WLP中的功能,或者我缺少pom中的依赖项?

如果有人需要进一步的信息,我会支持。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在“开放自由”讨论组中,有人尝试更改WLP中的eclipse链接的缓存(请参见https://groups.io/g/openliberty/topic/20719688#165)。 一个提示是删除jpa功能并使用jpa容器功能。

我正在使用完整的jee7功能,其中包括jpa功能。

尽管(仍然)没有jpa功能的排除标签,但必须列出所有jee功能(不包括jpa功能且包括jpa容器功能)。

我的解决方案:

  <featureManager>
    <feature>servlet-3.1</feature>
    <feature>beanValidation-1.1</feature>
    <feature>ssl-1.0</feature>
    <feature>jndi-1.0</feature>
    <feature>jca-1.7</feature>
    <feature>jms-2.0</feature>
    <feature>ejbPersistentTimer-3.2</feature>
    <feature>appSecurity-2.0</feature>
    <feature>j2eeManagement-1.1</feature>
    <feature>jdbc-4.1</feature>
    <feature>wasJmsServer-1.0</feature>
    <feature>jaxrs-2.0</feature>
    <feature>javaMail-1.5</feature>
    <feature>cdi-1.2</feature>
    <feature>jcaInboundSecurity-1.0</feature>
    <feature>jsp-2.3</feature>
    <feature>ejbLite-3.2</feature>
    <feature>managedBeans-1.0</feature>
    <feature>jsf-2.2</feature>
    <feature>ejbHome-3.2</feature>
    <feature>jaxws-2.2</feature>
    <feature>jsonp-1.0</feature>
    <feature>el-3.0</feature>
    <feature>jaxrsClient-2.0</feature>
    <feature>concurrent-1.0</feature>
    <feature>appClientSupport-1.0</feature>
    <feature>ejbRemote-3.2</feature>
    <feature>jaxb-2.2</feature>
    <feature>mdb-3.2</feature>
    <feature>jacc-1.5</feature>
    <feature>batch-1.0</feature>
    <feature>ejb-3.2</feature>
    <feature>json-1.0</feature>
    <feature>jaspic-1.1</feature>
    <feature>distributedMap-1.0</feature>
    <feature>websocket-1.1</feature>
    <feature>wasJmsSecurity-1.0</feature>
    <feature>wasJmsClient-2.0</feature>

    <feature>jpaContainer-2.1</feature>
  </featureManager>

感谢帖子http://dplatz.de/blog/2018/wlp-eclipselink-cache-coordination.html

此解决方案对我有效,但是如果有人有任何提示,请发布。