Iniciante em Web Service Java (JAX-WS) - exemplo Criar e Consumir

2 respostas
A

Olá, começei agora estudo sobre o JAX-WS (web service Java)… Alguém poderia me dar um exemplinho para eu tentar criar e consumir web service Java?

abs,
André AS

2 Respostas

T

Olá André,

Segue um link que vai ajudar você a dar os primeiros passos

http://blog.caelum.com.br/2007/07/11/webservices-sem-servidor-de-aplicacao-no-java-6/

A

Olá thiagopires,

Cara estou tendo dores de cabeça ao criar um WS com JAXWS 2.0, GlassFish 3.0 e PostGre 8.4 na IDE Netbeans 6.8;
O WS baseia-se na criação de uma formulário de compra de produtos;

Estou fazendo testes com o WS em coneção com o PostGre, mas ele retorna os seguintes erros:

Service invocation threw an exception with message : null; Refer to the server log for more details

Exceptions details : java.lang.reflect.InvocationTargetException

O Código está abaixo:[/code]

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ws.ecommerce.view;

/**
 *
 * @author AndrePush
 */
public class Produto {
    private int codigo;
    private String descricao;
    private String quantidade;
    private String marca;

    /**
     * @return the codigo
     */
    public int getCodigo() {
        return codigo;
    }

    /**
     * @param codigo the codigo to set
     */
    public void setCodigo(int codigo) {
        this.codigo = codigo;
    }

    /**
     * @return the descricao
     */
    public String getDescricao() {
        return descricao;
    }

    /**
     * @param descricao the descricao to set
     */
    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    /**
     * @return the quantidade
     */
    public String getQuantidade() {
        return quantidade;
    }

    /**
     * @param quantidade the quantidade to set
     */
    public void setQuantidade(String quantidade) {
        this.quantidade = quantidade;
    }

    /**
     * @return the marca
     */
    public String getMarca() {
        return marca;
    }

    /**
     * @param marca the marca to set
     */
    public void setMarca(String marca) {
        this.marca = marca;
    }

   
}
[code]

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ws.ecommerce.view;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author AndrePush
 */
@WebService()
public class TesteCompraWs {

//private static final String URL_BASEDADOS="jdbc:postgresql://localhost:5432/COMERCIO";
//private static final String USUARIO="postgres";
//private static final String SENHA="senha";
//private Connection conexao;
//private Statement comando;

Produto produto ;
    /**
     * Operação de serviço web
     */
    @WebMethod(operationName = "adicionaProduto")
    public void adicionaProduto(@WebParam(name = "descricao")
    String descricao, @WebParam(name = "marca")
    String marca, @WebParam(name = "quantidade")
    String quantidade) {
        //TODO write your implementation code here:
                java.sql.Connection con;
        try {
            //carregando Driver
            Class.forName("org.postgresql.Driver");
            con = java.sql.DriverManager.getConnection("jdbc:postgresql://" +
                    "localhost:5432/COMERCIO", "postgres", "pushandre26");


        } catch (Exception e) {
            e.printStackTrace();
            throw new java.lang.RuntimeException("erro ao Conectar");
        }

        //Inserir Dados
       String comando =( "insert into Produto(descricao,marca,qnde)" + " " +
               "values" +"('" + produto.getDescricao()+ "','" + produto.getMarca() + "'," +
               "'" + produto.getQuantidade()+ "')");

        System.out.println(comando);
        try {
            java.sql.Statement stmt = con.createStatement();
            stmt.executeUpdate(comando);
            stmt.close();
            con.close();
        } catch (java.sql.SQLException e) {
            throw new java.lang.RuntimeException(e.getMessage());
        }

        //Fecha a Conexão
        try {
            con.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new java.lang.RuntimeException("ERRO!A conexão será fechada");

        }
    }

}

Por favor cara se puder ajudar!
vlws

Criado 26 de abril de 2010
Ultima resposta 15 de nov. de 2010
Respostas 2
Participantes 3