SOAP Web Service with Custom Class Argument in Java 8 and Glassfish 5

huangapple go评论60阅读模式
英文:

SOAP Web Service with Custom Class Argument in Java 8 and Glassfish 5

问题

我试图开发一个带有自定义类的SOAP服务...
但是,我无法检查生成的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() {
    }

    // Getter 和 Setter 方法...

}

我正在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 定义... -->
<portType name="IWebService">
<!-- 其他 operation 定义... -->
</portType>
<binding name="WebServiceImplPortBinding" type="tns:IWebService">
<!-- 其他 binding 定义... -->
</binding>
<service name="WebServiceImplService">
<!-- 其他 service 定义... -->
</service>
</definitions>

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

英文:

I was trying to develop a Soap Service with Custom Class...
But, I can't to check de WSDL generated.

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);

}

Now the implementation source code

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 = &quot;org.bz.soap.ws.IWebService&quot;)
public class WebServiceImpl implements IWebService {

  @Inject
  IEmpleadoService empleadoService;

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

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

}

The POJO class with the packages

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;
	}

}

I was deploying in glassfish

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

The WSDL file:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
&lt;!--  Published by JAX-WS RI (http://jax-ws.java.net). RI&#39;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.  --&gt;
&lt;!--  Generated by JAX-WS RI (http://javaee.github.io/metro-jax-ws). RI&#39;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.  --&gt;
&lt;definitions xmlns:wsu=&quot;http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd&quot; xmlns:wsp=&quot;http://www.w3.org/ns/ws-policy&quot; xmlns:wsp1_2=&quot;http://schemas.xmlsoap.org/ws/2004/09/policy&quot; xmlns:wsam=&quot;http://www.w3.org/2007/05/addressing/metadata&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:tns=&quot;http://ws.soap.bz.org/&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://schemas.xmlsoap.org/wsdl/&quot; targetNamespace=&quot;http://ws.soap.bz.org/&quot; name=&quot;WebServiceImplService&quot;&gt;
&lt;types&gt;
&lt;xsd:schema&gt;
&lt;xsd:import namespace=&quot;http://ws.soap.bz.org/&quot; schemaLocation=&quot;http://localhost:8080/WebServiceImplService/WebServiceImpl?xsd=1&quot;/&gt;
&lt;/xsd:schema&gt;
&lt;/types&gt;
&lt;message name=&quot;create&quot;&gt;
&lt;part name=&quot;parameters&quot; element=&quot;tns:create&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;createResponse&quot;&gt;
&lt;part name=&quot;parameters&quot; element=&quot;tns:createResponse&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;sumar&quot;&gt;
&lt;part name=&quot;parameters&quot; element=&quot;tns:sumar&quot;/&gt;
&lt;/message&gt;
&lt;message name=&quot;sumarResponse&quot;&gt;
&lt;part name=&quot;parameters&quot; element=&quot;tns:sumarResponse&quot;/&gt;
&lt;/message&gt;
&lt;portType name=&quot;IWebService&quot;&gt;
&lt;operation name=&quot;create&quot;&gt;
&lt;input wsam:Action=&quot;http://ws.soap.bz.org/IWebService/createRequest&quot; message=&quot;tns:create&quot;/&gt;
&lt;output wsam:Action=&quot;http://ws.soap.bz.org/IWebService/createResponse&quot; message=&quot;tns:createResponse&quot;/&gt;
&lt;/operation&gt;
&lt;operation name=&quot;sumar&quot;&gt;
&lt;input wsam:Action=&quot;http://ws.soap.bz.org/IWebService/sumarRequest&quot; message=&quot;tns:sumar&quot;/&gt;
&lt;output wsam:Action=&quot;http://ws.soap.bz.org/IWebService/sumarResponse&quot; message=&quot;tns:sumarResponse&quot;/&gt;
&lt;/operation&gt;
&lt;/portType&gt;
&lt;binding name=&quot;WebServiceImplPortBinding&quot; type=&quot;tns:IWebService&quot;&gt;
&lt;soap:binding transport=&quot;http://schemas.xmlsoap.org/soap/http&quot; style=&quot;document&quot;/&gt;
&lt;operation name=&quot;create&quot;&gt;
&lt;soap:operation soapAction=&quot;&quot;/&gt;
&lt;input&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/input&gt;
&lt;output&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/output&gt;
&lt;/operation&gt;
&lt;operation name=&quot;sumar&quot;&gt;
&lt;soap:operation soapAction=&quot;&quot;/&gt;
&lt;input&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/input&gt;
&lt;output&gt;
&lt;soap:body use=&quot;literal&quot;/&gt;
&lt;/output&gt;
&lt;/operation&gt;
&lt;/binding&gt;
&lt;service name=&quot;WebServiceImplService&quot;&gt;
&lt;port name=&quot;WebServiceImplPort&quot; binding=&quot;tns:WebServiceImplPortBinding&quot;&gt;
&lt;soap:address location=&quot;http://localhost:8080/WebServiceImplService/WebServiceImpl&quot;/&gt;
&lt;/port&gt;
&lt;/service&gt;
&lt;/definitions&gt;

Why, Is not described the complete POJO class?

答案1

得分: 0

这个 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

英文:

This wsdl uses the following import:

&lt;xsd:import namespace=&quot;http://ws.soap.bz.org/&quot; schemaLocation=&quot;http://localhost:8080/WebServiceImplService/WebServiceImpl?xsd=1&quot;/&gt;

And part of your schema is in another xsd file that can be accessed here - http://localhost:8080/WebServiceImplService/WebServiceImpl?xsd=1

huangapple
  • 本文由 发表于 2020年9月19日 17:30:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63967254.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定