3

我想在 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
  • 快速信息集.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
  • 管理-api.jar
  • mimepull.jar
  • 策略.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 输出

4

1 回答 1

3

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

对于不提供与 MOXy 作为 JAXB 提供者的集成的 JAX-WS 实现,您可以利用该javax.xml.ws.Provider接口而不是传统的服务端点接口。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);
        }
    }

}

了解更多信息

于 2013-02-06T15:40:36.627 回答