Java 8 和 Glassfish 5 中带有自定义 Class 参数的 SOAP Web 服务
SOAP Web Service with Custom Class Argument in Java 8 and Glassfish 5
我正在尝试使用自定义开发 Soap 服务 Class...
但是,我无法检查生成的 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 class
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;
}
}
我在 glassfish 中部署
http://localhost:8080/WebServiceImplService/WebServiceImpl?wsdl
WSDL 文件:
This XML file does not appear to have any style information 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>
为什么,没有描述完整的POJOclass?
此 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
我正在尝试使用自定义开发 Soap 服务 Class... 但是,我无法检查生成的 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 class
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;
}
}
我在 glassfish 中部署
http://localhost:8080/WebServiceImplService/WebServiceImpl?wsdl
WSDL 文件:
This XML file does not appear to have any style information 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>
为什么,没有描述完整的POJOclass?
此 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