Implementing and Publishing a JAX-WS SOAP Web Service

Classified in Computers

Written on in English with a size of 2.4 KB

CEP Request Wrapper (Cep.java)

package control.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "cep", namespace = "http://control/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "cep", namespace = "http://control/")
public class Cep {

    @XmlElement(name = "leituraCep", namespace = "")
    private int leituraCep;

    public int getLeituraCep() {
        return this.leituraCep;
    }

    public void setLeituraCep(int leituraCep) {
        this.leituraCep = leituraCep;
    }
}

CEP Response Wrapper (CepResponse.java)

package control.jaxws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "cepResponse", namespace = "http://control/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "cepResponse", namespace = "http://control/")
public class CepResponse {

    @XmlElement(name = "return", namespace = "")
    private String _return;

    public String getReturn() {
        return this._return;
    }

    public void setReturn(String _return) {
        this._return = _return;
    }
}

Web Service Implementation (Cep.java)

package control;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import DAO.UsuarioDAO;

@WebService
public class Cep {

    @WebMethod
    public String cep(@WebParam(name = "leituraCep") int leituraCep) {
        // TODO Auto-generated method stub
        UsuarioDAO dao = new UsuarioDAO();
        // dao.buscarPorCep(Integer.parseInt(leituraCep));
        return "Endereço: " + dao.buscarPorCep(leituraCep);
    }
}

Web Service Publisher (Publicador.java)

package control;

import javax.xml.ws.Endpoint;

public class Publicador {
    public static void main(String[] args) {
        Endpoint.publish("http://localhost:10001/cep", new Cep());
    }
}

Related entries: