Reputation: 167
I want to use EclipseLink in WebLogic 10.3.6.0 to host web-services using JAX-WS. This works perfectly in Tomcat.
Environment:
WEB-INF/lib contains:
My code is as follows:
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
}
The Service: 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;
}
}
Perfect XML in Tomcat:
<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>
wrong XML in weblogic:
<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>
If you think I need to put out more code, please let me know.
I want to see the XML output from tomcat in the output from weblogic
Upvotes: 3
Views: 2228
Reputation: 149017
The JAX-WS implementation in WebLogic 10.3.6 is hard coded to use the JAXB reference implementation. EclipseLink JAXB (MOXy) is the default JAXB provider as of WebLogic 12.1.1 and you can leverage all of our extensions in your JAX-WS Web Services:
For JAX-WS implementations that do not provide an integration with MOXy as the JAXB provider you could leverage the javax.xml.ws.Provider
interface instead of the traditional service endpoint interface. Provider gives you access to the actual XML message. With access to the XML message you can interact with it directly using 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);
}
}
}
For More Information
Upvotes: 3