0

Web サービスを使用してデータベースを公開しようとしています。postgresql データベース、ejb 3.1、および CXF を Web サービス フレームワークとして使用しています。

これが実体

package persistance.model;

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

import javax.persistence.*;
    /**
 * Entity implementation class for Entity: ENVOI
 *
 */
@Entity
@Table(name = "Envoi")
@NamedQueries({@NamedQuery(name="Envoi.getAll", query="Select e from Envoi e")})

public class Envoi implements Serializable {

    @Id
    @Column
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int Id;
    @Column
    private int Numet;
    @Column
    private int Numseq;
    @Column
    private int Valadler;
    @Column
    private String Typemess;
    @Column
    @Temporal(TemporalType.DATE)
    private Date Horodatage;
    @Column
    private String Appli;
    @Column
    private String Versproto;
    @Column
    private String Data;
    @Column
    private String ACK;

    private static final long serialVersionUID = 1L;

    public Envoi() {
        super();
    }   
    public int getNumet() {
        return this.Numet;
    }

    public void setNumet(int Numet) {
        this.Numet = Numet;
    }   
    public int getNumseq() {
        return this.Numseq;
    }

    public void setNumseq(int Numseq) {
        this.Numseq = Numseq;
    }   
    public int getValadler() {
        return this.Valadler;
    }

    public void setValadler(int Valadler) {
        this.Valadler = Valadler;
    }   
    public String getTypemess() {
        return this.Typemess;
    }

    public void setTypemess(String Typemess) {
        this.Typemess = Typemess;
    }   
    public Date getHorodatage() {
        return this.Horodatage;
    }

    public void setHorodatage(Date Horodatage) {
        this.Horodatage = Horodatage;
    }   
    public String getAppli() {
        return this.Appli;
    }

    public void setAppli(String Appli) {
        this.Appli = Appli;
    }   
    public String getVersproto() {
        return this.Versproto;
    }

    public void setVersproto(String Versproto) {
        this.Versproto = Versproto;
    }   
    public int getId() {
        return this.Id;
    }

    public void setId(int Id) {
        this.Id = Id;
    }   
    public String getData() {
        return this.Data;
    }

    public void setData(String Data) {
        this.Data = Data;
    }   
    public String getACK() {
        return this.ACK;
    }

    public void setACK(String ACK) {
        this.ACK = ACK;
    }

}

ここでDAO

これはジェネリックです

package persistance.dao;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
//import javax.persistence.criteria.CriteriaQuery;

public abstract class GenericDAO<T> {
    private final static String UNIT_NAME = "MestaPU";

    @PersistenceContext(unitName = UNIT_NAME)
    private EntityManager em;

    private Class<T> entityClass;

    public GenericDAO(Class<T> entityClass) {
    this.entityClass = entityClass;
    }

    public void save(T entity) {
    em.persist(entity);
    }

    protected void delete(Object id, Class<T> classe) {
    T entityToBeRemoved = em.getReference(classe, id);

    em.remove(entityToBeRemoved);
    }

    public T update(T entity) {
    return em.merge(entity);
    }

    public T find(int entityID) {
    return em.find(entityClass, entityID);
    }

    // Using the unchecked because JPA does not have a
    // em.getCriteriaBuilder().createQuery()<T> method
   /* @SuppressWarnings({ "unchecked", "rawtypes" })
    public List<T> findAll() {
    CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
    cq.select(cq.from(entityClass));
    return em.createQuery(cq).getResultList();
    }*/

    // Using the unchecked because JPA does not have a
    // ery.getSingleResult()<T> method
   /* @SuppressWarnings("unchecked")
    protected T findOneResult(String namedQuery, Map<String, Object> parameters) {
    T result = null;

    try {
        Query query = em.createNamedQuery(namedQuery);

        // Method that will populate parameters if they are passed not null and empty
        if (parameters != null && !parameters.isEmpty()) {
        populateQueryParameters(query, parameters);
        }

        result = (T) query.getSingleResult();

    } catch (Exception e) {
        System.out.println("Error while running query: " + e.getMessage());
        e.printStackTrace();
    }

    return result;
    }*/

  /*  private void populateQueryParameters(Query query, Map<String, Object> parameters) {

    for (Entry<String, Object> entry : parameters.entrySet()) {
        query.setParameter(entry.getKey(), entry.getValue());
    }
    }*/
}

これは Envoi エンティティに固有のものです

package persistance.dao;

import javax.ejb.Stateless;

import persistance.model.*;

@Stateless
public class EnvoiDAO extends GenericDAO<Envoi> {

    public EnvoiDAO() {
    super(Envoi.class);
    }

    public void delete(Envoi envoi) {
        super.delete(envoi.getId(), Envoi.class);
    }
}

これは、ejb を公開するファサードです。

package persistance.facade;

import java.util.List;

import javax.ejb.Local;
import javax.jws.WebService;

import persistance.model.Envoi;

@WebService
@Local
public interface EnvoiFacade {

    public abstract void save(Envoi envoi);

    public abstract Envoi update(Envoi envoi);

    public abstract void delete(Envoi envoi);

    public abstract Envoi find(int entityID);

    public abstract List<Envoi> findAll();
}



package persistance.facade;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebService;

import persistance.dao.EnvoiDAO;
import persistance.model.Envoi;

@WebService
@Stateless
public class EnvoiFacadeImp implements EnvoiFacade {

    @EJB
    private EnvoiDAO envoiDAO;

    public void save(Envoi envoi) {
        envoiDAO.save(envoi);
    }

    public Envoi update(Envoi envoi) {
        return envoiDAO.update(envoi);
    }

    public void delete(Envoi envoi) {
        envoiDAO.delete(envoi);
    }

    public Envoi find(int entityID) {
        // TODO Auto-generated method stub
        return null;
    }

    public List<Envoi> findAll() {
        // TODO Auto-generated method stub
        return null;
    }

    /*public Envoi find(int entityID) {
        return envoiDAO.find(entityID);
    }*/

    /*public List<Envoi> findAll() {
        return envoiDAO.findAll();
    }*/


}

これで、サービスを公開するSpring Beanが見つかります

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" /> 
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 

    <jaxws:endpoint 
      id="orderProcess" 
      implementor="demo.order.OrderProcessImpl" 
      address="/OrderProcess" />

     <jaxws:endpoint 
      id="EnvoiFacade" 
      implementor="persistance.facade.EnvoiFacadeImp" 
      address="/EnvoiFacade" />
</beans>

これで、クライアントとそれに関連付けられた Bean が見つかります

package demo.ejb.client;


import org.springframework.context.support.ClassPathXmlApplicationContext;

import persistance.facade.EnvoiFacade;
import persistance.model.Envoi;

public final class Client {

    public Client() {
    }

    public static void main(String args[]) throws Exception {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] { "demo/ejb/client/client-beans.xml" });

        EnvoiFacade client = (EnvoiFacade) context.getBean("envoiClient");
        Envoi p1 = new Envoi();
        p1.setNumet(3690);
        p1.setNumseq(9990);

        client.save(p1);



    }
}



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <jaxws:client id="envoiClient" serviceClass="persistance.facade.EnvoiFacade" address="http://localhost:8080/orderapp/EnvoiFacade" >
    </jaxws:client>

</beans>

これで、私の Web サービスは JBOSS 7.1.0 AS にデプロイされました。データソースを作成し、postgres my sql のドライバーを含めました。問題は、クライアントを実行するとこのエラーが発生することです

Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing.
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:143)
    at $Proxy57.save(Unknown Source)
    at demo.ejb.client.Client.main(Client.java:23)
Caused by: org.apache.cxf.binding.soap.SoapFault: Fault occurred while processing.
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalFault(Soap11FaultInInterceptor.java:75)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:46)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:96)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:658)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2139)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2022)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1947)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:632)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:472)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:302)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:254)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:123)
... 2 more
4

1 に答える 1

1

最近、同様のスタック トレースがあり、自分のフィールドの 1 つでクラシック セッターが欠落していることに気付きました。

于 2014-01-23T13:01:19.247 に答える