相关疑难解决方法(0)

在Java 1.6中为JAX-WS提供不同版本的JAXB

我有一个第三方jar,它附带一个jaxb-impl.jar并将其包含在其manifest类路径中.问题是,似乎提供自己的JAXB版本(无论它是哪个版本)似乎打破了JAX-WS中的SoapFaultBuilder.

根据非官方的JAXB指南,似乎Sun在将JAXB折叠到JDK中时故意更改了包名称,以避免与独立版本冲突.但是,随JDK一起提供的SoapFaultBuilder(我相信JAX-WS的一部分)明确依赖于新的内部包名.如果您添加了一个独立的JAXB jar(即使它与JAXB的版本相同),这会在构建错误消息时导致失败.

这是我的小测试案例:我制作一个简单的Web服务:

package wstest;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{

    @WebMethod String getHelloWorldAsString(String name);

}
Run Code Online (Sandbox Code Playgroud)

一个简单抛出异常的实现.(因为问题只出现在SOAPFaultBuilder中):

package wstest;

import javax.jws.WebService;

//Service Implementation
@WebService(endpointInterface = "wstest.HelloWorld")
public class HelloWorldImpl implements HelloWorld{

    @Override
    public String getHelloWorldAsString(String name) {
        //return "Hello World JAX-WS " + name;
        throw new RuntimeException("Exception for: " + name);
    }

}
Run Code Online (Sandbox Code Playgroud)

还有一个发布Web服务的类:

package wstest;

import javax.xml.ws.Endpoint;

//Endpoint publisher
public class HelloWorldPublisher{ …
Run Code Online (Sandbox Code Playgroud)

java web-services jax-ws jaxb

32
推荐指数
2
解决办法
4万
查看次数

ClassCastException:无法强制转换为com.sun.xml.internal.bind.v2.runtime.reflect.Accessor

我有一个SOAP Web服务,我试图在应用程序内部调用.我使用cxf-codegen-plugin(3.1.10)从WSDL生成源代码.

使用生成的客户端,如果我在应用程序中调用Web服务,它可以很好地工作.但是,我还在应用程序中使用另一个JAXB实例来导致问题.

例如,以下工作很好:

OutboundServicePortType service = new OutboundService().getOutboundServicePort();
service.sendMessage(message);
Run Code Online (Sandbox Code Playgroud)

但是,在之前初始化新的JAXB实例会导致getOutboundServicePort()调用失败:

JAXBContext.newInstance(SendMessageRequest.class);

OutboundServicePortType service = new OutboundService().getOutboundServicePort();
service.sendMessage(message);
Run Code Online (Sandbox Code Playgroud)

使用以下堆栈跟踪:

Caused by: java.lang.ClassCastException: outbound.model.standard.StandardOutboundMessage$JaxbAccessorF_messageUUId cannot be cast to com.sun.xml.internal.bind.v2.runtime.reflect.Accessor
    at com.sun.xml.internal.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.instanciate(OptimizedAccessorFactory.java:190)
    at com.sun.xml.internal.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:179)
    at com.sun.xml.internal.bind.v2.runtime.reflect.Accessor$FieldReflection.optimize(Accessor.java:271)
    at com.sun.xml.internal.bind.v2.runtime.property.SingleElementLeafProperty.<init>(SingleElementLeafProperty.java:77)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:113)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:166)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:488)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:153)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:488)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:305)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:124)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1123)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:147)
    at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:152)
    at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:96)
    at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:98)
    at com.sun.xml.internal.ws.db.glassfish.JAXBRIContextFactory.newContext(JAXBRIContextFactory.java:79)
    ... 25 more
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试过的事情:

来自Webservice的JAXB类编组错误

java cxf jaxb

13
推荐指数
2
解决办法
1万
查看次数

标签 统计

java ×2

jaxb ×2

cxf ×1

jax-ws ×1

web-services ×1