1 Reply Latest reply on Jul 27, 2006 7:26 AM by Arno Werr

    How to get SOAP message inside a EJB layer

    Talles Brito Newbie

      I'm exposing my EJB session bean at a webservice using JBossWS, exists a way to get SOAP message data from EJB directly inside session bean implementation code?


      Thanks,
      Talles

        • 1. Re: How to get SOAP message inside a EJB layer
          Arno Werr Newbie

          Here is my sample of accessing SOAP message body content - Cabin by EJB exposed as a web service

          package com.bruno.net.ejb;
          
          import javax.annotation.PostConstruct;
          import javax.ejb.Stateless;
          import javax.jws.Oneway;
          import javax.jws.WebMethod;
          import javax.jws.WebParam;
          import javax.jws.WebResult;
          import javax.jws.WebService;
          import javax.persistence.EntityManager;
          import javax.persistence.PersistenceContext;
          import javax.xml.ws.WebServiceRef;
          
          import org.apache.log4j.Logger;
          
          import com.bruno.net.domain.Cabin;
          
          @WebService(name = "TravelAgent", serviceName = "TravelAgentService")
          @WebServiceRef(name = "service/TravelAgentService")
          @Stateless
          public class TravelAgentBean implements TravelAgentRemote {
           private Logger logger;
          
           @PersistenceContext(unitName = "titan")
           private EntityManager manager;
          
           @PostConstruct
           public void postConstruct() {
           logger = Logger.getLogger(getClass().getName());
           }
          
           @WebMethod
           @Oneway
           public void createCabin(@WebParam(name = "Cabin")
           Cabin cabin) {
           logger.debug("here is my cabin delivered by JAX-WS = " + cabin);
           logger.debug("cabin name " + cabin.getName());
           logger.debug("bed count " + cabin.getBedCount());
           manager.persist(cabin);
           }
          
           @WebMethod
           @WebResult(name = "Cabin")
           public Cabin findCabin(@WebParam(name = "ID")
           int pKey) {
           return manager.find(Cabin.class, pKey);
           }
          }
          

          If you need SOAP header you have to create and wire up a message handler to work with SAAJ.
          Cheers,
          Arno