gpt4 book ai didi

java - 如何让 EclipseLink MOXy 在基于 JAX-WS 的 Web 服务中的 WebLogic 中工作?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:53:43 24 4
gpt4 key购买 nike

我想在 WebLogic 10.3.6.0 中使用 EclipseLink 来托管使用 JAX-WS 的 Web 服务。这在 Tomcat 中完美运行。

环境:

  • Java 1.6
  • 网络逻辑 10.3.6.0
  • EclipseLink 2.4.0.v20120608-r11652
  • JAXWS 2.2.7-20120813

WEB-INF/lib 包含:

  • eclipselink.jar
  • FastInfoset.jar
  • gmbal-api-only.jar
  • ha-api.jar
  • javax.annotation.jar
  • jaxb-api.jar
  • jaxb-impl.jar
  • jaxb-xjc.jar
  • jaxws-api.jar
  • jaxws-eclipselink-plugin.jar
  • jaxws-rt.jar
  • jaxws-tools.jar
  • jsr181-api.jar
  • 邮件.jar
  • management-api.jar
  • mimepull.jar
  • policy.jar
  • saaj-api.jar
  • saaj-impl.jar
  • stax-ex.jar
  • stax2-api.jar
  • 流缓冲.jar
  • woodstox-core-asl.jar

我的代码如下:

TestRequestDTO.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "test_request")
public class TestRequestDTO implements Serializable {
@XmlPath("request/name/text()")
private String requestName;
@XmlPath("request/value/text()")
private String requestValue;
//getter setters
}

TestResponseDTO.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "test_response")
public class TestResponseDTO implements Serializable {
@XmlPath("response/name/text()")
private String responseName;
@XmlPath("response/value/text()")
private String responseValue;
//getter setters
}

服务:SampleTest.java

@WebService
public class SampleTest {
@WebMethod
public TestResponseDTO fetchResponse(TestRequestDTO request) {
System.out.println("request.getRequestName()" + request.getRequestName());
System.out.println("request.getRequestValue()" + request.getRequestValue());
TestResponseDTO response = new TestResponseDTO();
response.setResponseName("Service Response");
response.setResponseValue(new Date().toString());
return response;
}
}

Tomcat 中的完美 XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://service.test.services.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:fetchResponse>
<arg0>
<request>
<name>this-that</name>
<value>home-run</value>
</request>
</arg0>
</q0:fetchResponse>
</soapenv:Body>
</soapenv:Envelope>

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns0:fetchResponseResponse xmlns:ns0="http://service.test.services.com/">
<return>
<response>
<name>Service Response</name>
<value>Wed Feb 06 20:21:13 XXX 2013</value>
</response>
</return>
</ns0:fetchResponseResponse>
</S:Body>
</S:Envelope>

weblogic 中错误的 XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://service.test.services.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:fetchResponse>
<arg0>
<requestName>hello</requestName>
<requestValue>wassup</requestValue>
</arg0>
</q0:fetchResponse>
</soapenv:Body>
</soapenv:Envelope>

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:fetchResponseResponse xmlns:ns2="http://service.test.services.com/">
<return>
<responseName>Service Response</responseName>
<responseValue>Wed Feb 06 20:30:06 IST 2013</responseValue>
</return>
</ns2:fetchResponseResponse>
</S:Body>
</S:Envelope>

如果您认为我需要提供更多代码,请告诉我。

我想在weblogic的输出中看到tomcat的XML输出

最佳答案

WebLogic 10.3.6 中的 JAX-WS 实现被硬编码为使用 JAXB 引用实现。 EclipseLink JAXB (MOXy)是 WebLogic 12.1.1 的默认 JAXB 提供程序,您可以在 JAX-WS Web 服务中利用我们的所有扩展:

对于不提供与作为 JAXB 提供程序的 MOXy 集成的 JAX-WS 实现,您可以利用 javax.xml.ws.Provider 接口(interface)而不是传统的服务端点接口(interface)。 Provider 使您可以访问实际的 XML 消息。通过访问 XML 消息,您可以使用 MOXy 直接与其交互。

import javax.xml.bind.*;
import javax.xml.bind.util.JAXBSource;
import javax.xml.transform.Source;
import javax.xml.ws.*;

@ServiceMode(Service.Mode.PAYLOAD)
@WebServiceProvider(
portName = "FindCustomerPort",
serviceName = "FindCustomerService",
targetNamespace = "http://service.jaxws.blog/",
wsdlLocation = "WEB-INF/wsdl/FindCustomerService.wsdl")
public class FindCustomerService implements Provider<Source> {

private JAXBContext jaxbContext;

public FindCustomerService() {
try {
jaxbContext = JAXBContext.newInstance(FindCustomerResponse.class,
FindCustomerRequest.class);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}

@Override
public Source invoke(Source request) throws WebServiceException {
try {
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
FindCustomerRequest fcRequest = (FindCustomerRequest) unmarshaller
.unmarshal(request);

Customer customer = new Customer();
customer.setId(fcRequest.getArg0());
customer.setFirstName("Jane");
customer.setLastName("Doe");

FindCustomerResponse response = new FindCustomerResponse();
response.setValue(customer);

return new JAXBSource(jaxbContext, response);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}

}

了解更多信息

关于java - 如何让 EclipseLink MOXy 在基于 JAX-WS 的 Web 服务中的 WebLogic 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14732355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com