Websphere 上具有 Source 返回类型的 JAX-WS Web 服务

发布于 2024-12-22 11:34:11 字数 2211 浏览 6 评论 0原文

我正在将旧的 JAX-WS 2.1 Web 服务从 JBoss 4 迁移到 Websphere 7。大多数 @WebMethod 组件都如下所示:

@WebMethod
public Source someMethod(){
    Source source = null;

    try{
            source = ServiceActions.someMethodWorker();
    }
    catch( Throwable throwable ){
            source = ServiceActions.handleThrowable("Error occured in method someMethod", throwable );
    }
    return source;
}

ServiceActions.someMethodWorker() 通常会这样关闭并获取该数据,填充 JAXB 结构,编组为 XML 并返回 XML 的 StreamSource,如下所示:

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

JAXBContext jc = JAXBContext.newInstance();
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(someJaxBObjectHierarchy, byteArrayOutputStream);

return new StreamSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));

此 Web 服务在 JBoss 4 上运行良好(使用Jax-WS 和 JaxB 库)和 GlassFish 3.1,但每当我针对 Web 服务使用客户端时,Websphere 7 都会不断给出以下错误:

javax.xml.ws.soap.SOAPFaultException: javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class javax.xml.transform.stream.StreamSource nor any of its super class is known to this context.]
        at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
        at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
        at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)

乍一看,这似乎是 JAXB 类型绑定问题;实际上,这似乎是 JAXB 类型绑定问题。但是,我在各处添加了 @XmlSeeAlso(StreamSource.class) ,但仍然收到错误。

有人知道为什么这在 WebSphere 7 上失败吗?

谢谢!

编辑/解决方案:解决方案是使用byte[]返回类型而不是Source

GlassFish和JBoss与JAX相比做了一些额外的事情- WS 规范让我相信 Source 返回类型是可以的。

我的方法不再返回 new StreamSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())) ,它们现在只返回 byteArrayOutputStream.toByteArray()

I am migrating an old JAX-WS 2.1 web service from JBoss 4 to Websphere 7. Most of the @WebMethod components all look like this:

@WebMethod
public Source someMethod(){
    Source source = null;

    try{
            source = ServiceActions.someMethodWorker();
    }
    catch( Throwable throwable ){
            source = ServiceActions.handleThrowable("Error occured in method someMethod", throwable );
    }
    return source;
}

ServiceActions.someMethodWorker() usually goes off and fetches that data populates a JAXB structure, marshalls into XML and returns a StreamSource of the XML like this:

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

JAXBContext jc = JAXBContext.newInstance();
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(someJaxBObjectHierarchy, byteArrayOutputStream);

return new StreamSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));

This web service runs just fine on JBoss 4 (with the Jax-WS and JaxB libraries) and GlassFish 3.1, but Websphere 7 keeps giving me the following error any time I use a client against the web service:

javax.xml.ws.soap.SOAPFaultException: javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class javax.xml.transform.stream.StreamSource nor any of its super class is known to this context.]
        at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
        at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
        at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)

At first look this seems to be the JAXB type binding problem; however, I've added @XmlSeeAlso(StreamSource.class) everywhere, and I still get the error.

Would someone know why this is failing on WebSphere 7?

Thanks!

Edit/Solution: The solution is to use byte[] return type instead of Source

GlassFish and JBoss were doing something extra compared to the JAX-WS specification which led me to believe that Source return type was OK.

Instead of my methods returning new StreamSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())) they now just return byteArrayOutputStream.toByteArray()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-黛色若梦 2024-12-29 11:34:11

javax.xml.transform.Source 不是普通 JAX-WS 服务端点接口 (SEI) 的有效返回类型。如果您想这样做(并符合 JAX-WS),您需要使用作为 javax.xml.ws.Provider 实现的服务(请参阅相应的文档)。如果 JBoss 或 GlassFish 支持 Source 作为普通 SEI 中的参数或返回类型,那么这就是专有扩展。

javax.xml.transform.Source is not a valid return type for a normal JAX-WS service endpoint interface (SEI). If you want to do that (and be compliant with JAX-WS) you need to use a service that is implemented as a javax.xml.ws.Provider (see the corresponding docs). If JBoss or GlassFish support Source as a parameter or return type in a normal SEI, then that's a proprietary extension.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文