0 Replies Latest reply on May 26, 2015 7:22 AM by user5108636

    Initial Connection definition in Stateless EJB

    user5108636

      Hi All,

         Instead of database, I connect to Microsoft CRM for fetch records. The connectivity is complex and has a security layer which exchanges token with the calling client. I used Apache CXF to get past the CRM's security implementation.

        Next I use the CRM's exposed API to retrieve the entities. I want to create a stateless session EJB which contains method to retrieve different entities.

       

      I could have a method like

       

      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

      public List<OrderEntity> getAllOrders() {

      QueryBuilder qb = new DispatchGridQueryBuilder();

              qb.buildQuery();

              QueryExpression query = qb.getQuery();

              EntityCollection result = port.retrieveMultiple(query);

              List<Entity> entities = result.getEntities().getEntities();

      return entities;

      }

       

      The security tokens are exchanged when a call is made to the OrganizationService in the below code

       

      URL wsdlLocation = new URL(

                      "https://abc/XRMServices/2011/Organization.svc?wsdl");

              SpringBusFactory factory = new SpringBusFactory();

              Bus bus = factory.createBus("/META-INF/spring/app-context.xml");

              BusFactory.setDefaultBus(bus);

         

             

       

              OrganizationService service = new OrganizationService(wsdlLocation);

              IOrganizationService port = service

                      .getCustomBindingIOrganizationService();

       

      I am not sure where to put this initialization code which is required each time a session EJB methods is invoked as it contains reference to port.  Please suggest if there is a pattern to address this or how to go about this.

       

      Thanks in advance.