How do I get EclipseLink MOXy to work in WebLogic in a JAX-WS based web service?

I want to use EclipseLink in WebLogic 10.3.6.0 to host web services using JAX-WS. This works great in Tomcat.

Environment:

  • Java 1.6
  • WebLogic 10.3.6.0
  • EclipseLink 2.4.0.v20120608-r11652
  • JAXWS 2.2.7-20120813

WEB-INF / lib contains:

  • 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
  • Control-api.jar
  • mimepull.jar
  • policy.jar
  • SAAJ-api.jar
  • SAAJ-impl.jar
  • StAX-ex.jar
  • stax2-api.jar
  • streambuffer.jar
  • Woodstox-core-asl.jar

My code looks like this:

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
}

      

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 release more code, please let me know.

I want to see XML output from tomcat in output from weblogic

+3


source to share


1 answer


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 since WebLogic 12.1.1 and you can use all of our extensions in your JAX-WS web services:

For JAX-WS implementations that do not provide integration with MOXy as a JAXB provider, you can use an interface javax.xml.ws.Provider

instead of the traditional service endpoint interface. The 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);
        }
    }

}

      

Additional Information

+3


source







All Articles