Java 8和Glassfish 5中具有自定义类参数的SOAP Web服务

问题描述

我正在尝试开发具有自定义类的肥皂服务... 但是,我无法检查生成的WSDL。

package org.bz.soap.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;

import org.bz.soap.api.models.Empleado1;

@WebService
public interface IWebService {
    
    @WebMethod
    void create(Empleado1 empleado1);
  
    @WebMethod
    int sumar(int a,int b);

}

现在实现的源代码

package org.bz.soap.ws;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.jws.WebService;
import org.bz.soap.api.models.Empleado1;

import org.bz.soap.api.models.service.IEmpleadoService;

@Stateless
@WebService(endpointInterface = "org.bz.soap.ws.IWebService")
public class WebServiceImpl implements IWebService {

  @Inject
  IEmpleadoService empleadoService;

  @Override
  public void create(Empleado1 empleado1) {
    System.out.println(this.getClass().getSimpleName().concat("  create"));
  }

  @Override
  public int sumar(int a,int b) {
    return a + b;
  }

}

带有软件包的POJO类

package org.bz.soap.api.models;

import java.io.Serializable;
import java.util.Date;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Empleado1 implements Serializable {

    private static final long serialVersionUID = 1L;
    
    private Long id;
    private String nombres;
    private String tipodocumento;
    private String numerodocumento;
    private Date fechaNacimiento;
    
    public Empleado1() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNombres() {
        return nombres;
    }

    public void setNombres(String nombres) {
        this.nombres = nombres;
    }

    public String getTipodocumento() {
        return tipodocumento;
    }

    public void setTipodocumento(String tipodocumento) {
        this.tipodocumento = tipodocumento;
    }

    public String getNumerodocumento() {
        return numerodocumento;
    }

    public void setNumerodocumento(String numerodocumento) {
        this.numerodocumento = numerodocumento;
    }

    public Date getFechaNacimiento() {
        return fechaNacimiento;
    }

    public void setFechaNacimiento(Date fechaNacimiento) {
        this.fechaNacimiento = fechaNacimiento;
    }

}

我正在部署在玻璃鱼中

http:// localhost:8080 / WebServiceImplService / WebServiceImpl?wsdl

WSDL文件

This XML file does not appear to have any style @R_908_4045@ion associated with it. The document tree is shown below.
<!--  Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.4.0 (wsit240-7e98ff4; 2017-08-03T21:19:54+0200) JAXWS-RI/2.3.0 JAXWS-API/2.3.0 JAXB-RI/2.3.0 JAXB-API/2.3.0 svn-revision#unkNown.  -->
<!--  Generated by JAX-WS RI (http://javaee.github.io/metro-jax-ws). RI's version is Metro/2.4.0 (wsit240-7e98ff4; 2017-08-03T21:19:54+0200) JAXWS-RI/2.3.0 JAXWS-API/2.3.0 JAXB-RI/2.3.0 JAXB-API/2.3.0 svn-revision#unkNown.  -->
<deFinitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/Metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.soap.bz.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.soap.bz.org/" name="WebServiceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.soap.bz.org/" schemaLocation="http://localhost:8080/WebServiceImplService/WebServiceImpl?xsd=1"/>
</xsd:schema>
</types>
<message name="create">
<part name="parameters" element="tns:create"/>
</message>
<message name="createResponse">
<part name="parameters" element="tns:createResponse"/>
</message>
<message name="sumar">
<part name="parameters" element="tns:sumar"/>
</message>
<message name="sumarResponse">
<part name="parameters" element="tns:sumarResponse"/>
</message>
<portType name="IWebService">
<operation name="create">
<input wsam:Action="http://ws.soap.bz.org/IWebService/createRequest" message="tns:create"/>
<output wsam:Action="http://ws.soap.bz.org/IWebService/createResponse" message="tns:createResponse"/>
</operation>
<operation name="sumar">
<input wsam:Action="http://ws.soap.bz.org/IWebService/sumarRequest" message="tns:sumar"/>
<output wsam:Action="http://ws.soap.bz.org/IWebService/sumarResponse" message="tns:sumarResponse"/>
</operation>
</portType>
<binding name="WebServiceImplPortBinding" type="tns:IWebService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="create">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="sumar">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="WebServiceImplService">
<port name="WebServiceImplPort" binding="tns:WebServiceImplPortBinding">
<soap:address location="http://localhost:8080/WebServiceImplService/WebServiceImpl"/>
</port>
</service>
</deFinitions>

为什么没有描述完整的POJO类?

解决方法

此wsdl使用以下导入:

<xsd:import namespace="http://ws.soap.bz.org/" schemaLocation="http://localhost:8080/WebServiceImplService/WebServiceImpl?xsd=1"/>

部分架构位于另一个xsd文件中,可以在此处访问-http://localhost:8080/WebServiceImplService/WebServiceImpl?xsd=1