我可以从Javax-WS到war文件中将本地bean调用到ear文件中吗-apache-tomee-plus-1.7.4

时间:2018-06-27 23:54:31

标签: spring eclipse maven java-ee tomee-7

我正在使用Eclipse Mars 2,maven 3.3.9和apache-tomee-plus-1.7.4。

我有2个项目(A和B)

项目A是使用Maven 3.3.9像WAR一样编译并部署到TOMEE_HOME / webapps中的Web服务

项目B是一个像EAR一样使用maven 3.3.9编译并部署到TOMEE_HOME / apps中的EJB模块(此项目包括其他具有ejb clases的项目,并且像jar文件一样编译)

这些项目在pom.xml中彼此不依赖,但是我需要从项目B中查找项目A中的EJB。

  

----------项目B的实施-----------

项目B中的本地Bean接口:

package co.edu.uniquindio.model.ejb.interfaces;

import javax.ejb.Local;

import org.springframework.context.support.ClassPathXmlApplicationContext;

@Local
public interface IReporte {

    public Object generate1();

    public Object generate2();

    public void setContext(ClassPathXmlApplicationContext context);
}

在项目B中实现本地bean接口:

package co.edu.uniquindio.model.ejb;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import co.edu.uniquindio.model.ejb.interfaces.IReporte;

@Stateless
@EJB(beanInterface = IReporte.class, beanName="ReporteEJB", name="IReporte")
public class ReporteEJB implements IReporte{

    private ClassPathXmlApplicationContext context;

    @Override
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public Object generate1(){
        // do somthing amazing  
    }

    @Override
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
    public Object generate2(){
        // do somthing amazing  
    }

    @Override
    public void setContext(ClassPathXmlApplicationContext context) {
        this.context = context;
    }

}
  

----------项目A实施-----------

我开发查找的方式是:

package co.swatit.rest.services;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import co.edu.uniquindio.model.ejb.interfaces.IReporte;

@Path("/ReporteWS")
public class ReporteWS {

    @POST
    @Path("generate1and2")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes({ MediaType.APPLICATION_JSON} )
    public Response generate1and2() {
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
        try {
            Context ctx = new InitialContext(props);
            // I do not know if use IReporte or ReporteEJB to cast. and I do not know how to import it.
            IReporte ejbLocal = (IReporte) ctx.lookup("java:global/Sac-report-ear-1.0.0/co.swatit-Sac-report-ejb-1.0.0/ReporteEJB");
            ejbLocal.generate1();
            ejbLocal.generate2();
        } catch (Exception exception) {
            exception.printStackTrace()
        }
        return Response.status(Status.OK)
                .entity(ejbLocal).build();
    }

}

我不知道是否可以在项目A中导入本地bean来查找该bean:

import co.edu.uniquindio.model.ejb.interfaces.IReporte

我不知道是使用IReporte还是ReporteEJB进行转换,也不知道如何导入它。

谢谢您的帮助。

0 个答案:

没有答案