我想在WebLogic 10.3.6.0中使用EclipseLink来使用JAX-WS托管Web服务.这在Tomcat中完美地工作.
环境:
> Java 1.6
> WebLogic 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
> mail.jar
> management-api.jar
> mimepull.jar
> policy.jar
> saaj-api.jar
> saaj-impl.jar
> stax-ex.jar
> stax2-api.jar
> streambuffer.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参考实现.从WebLogic 12.1.1开始,EclipseLink JAXB (MOXy)是默认的JAXB提供程序,您可以在您的JAX-WS Web服务中利用我们所有的扩展:
> http://blog.bdoughan.com/2011/12/eclipselink-moxy-is-jaxb-provider-in.html
对于不提供与MOXy集成的JAX-WS实现作为JAXB提供程序,您可以利用javax.xml.ws.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);
}
}
}
欲获得更多信息
> http://blog.bdoughan.com/2013/02/leveraging-moxy-in-your-web-service-via.html
> How to use Moxy XPath annotated beans in web services?