2015-02-19 20 views
5

vấn đề hiện tại của tôi nói chung là, tôi có hai phiên bản Wildfly 8.2.0Final đang chạy trên máy của tôi. Tôi biết, có những câu hỏi tương tự, nhưng không ai trong số họ thực sự giúp đỡ với vấn đề của tôi. Một trong số họ giữ một ứng dụng yên tĩnh kích hoạt một phiên đậu không trạng thái SenderBean khi nhận được GET. Sau đó, bean phiên không trạng thái này sẽ gọi một phương thức từ bean phiên không trạng thái vô tuyến từ xa PrintBean, nằm trên cá thể wildfly khác.EJB trên Wildfly gọi EJB từ xa từ Wildfly

Tôi sẽ bắt đầu bằng cách giải thích những gì tôi đã làm cho đến nay (có thể tôi đã bỏ lỡ điều gì đó, tôi khá mới đối với Java EE và Wildfly).

Tôi sẽ gọi trường hợp Wildfly với SenderBean số Sender và số có PrintBean số Receiver.

Tôi đã tạo người dùng Ứng dụng có tên Stefan bằng Mật khẩu stefan, thuộc nhóm guest trên Receiver. Trên Sender, trong standalone-full.xml, tôi đã thêm một An-Realm bằng cách đặt

<security-realm name="ejb-security-realm"> 
    <server-identities> 
    <secret value="c3R1ZmFu"/> 
    </server-identities> 
</security-realm> 

vào phần <security-realms>. Tôi cũng đã thêm một outbound-socket ràng buộc bằng cách đặt

<outbound-socket-binding name="remote-ejb"> 
    <remote-destination host="localhost" port="8080"/> 
</outbound-socket-binding> 

vào phần <socket-binding-group ...>. ngoái, tôi đã tạo ra một outbound-kết nối, bằng cách đặt

<outbound-connections> 
    <remote-outbound-connection name="remote-ejb-connection" outbound-socket-binding-ref="remote-ejb" username="Stefan" security-realm="ejb-security-realm"> 
    <properties> 
     <property name="SASL_POLICY_NOANONYMOUS" value="false"/> 
     <property name="SSL_ENABLED" value="false"/> 
    </properties> 
    </remote-outbound-connection> 
</outbound-connections> 

vào phần <subsystem xmlns="urn:jboss:domain:remoting:2.0">.

Tôi bắt đầu Sender bằng lệnh CLI standalone.bat -c standalone-full.xml -Djboss.socket.binding.port-offset=100 -Djboss.node.name=SenderReceiver với standalone.bat -c standalone-full.xml -Djboss.node.name=Receiver.

The Local Stateless Session Bean trên Sender được gọi SenderBean:

@Stateless 
public class SenderBean implements SenderService { 

    private static final Logger logger = Logger.getLogger(SenderBean.class.getSimpleName()); 

    public void send(){ 
    logger.info("Trying to invoke"); 
    this.invoke(); 
    } 

    private void invoke() { 
    Properties clientProperties = new Properties(); 
    clientProperties.put("remote.connections", "default"); 
    clientProperties.put("remote.connection.default.port", "8080"); 
    clientProperties.put("remote.connection.default.host", "localhost"); 

    Properties properties = new Properties(); 
    properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");   

    try { 
     Context context = new InitialContext(properties); 
     context = new InitialContext(properties); 
     Object x = context.lookup("ejb:baseproject-ear-01.00.00-SNAPSHOT/testdomain-service-01.00.00-SNAPSHOT/Receiver/PrintBean!com.schubert.baseproject.testdomain.service.PrintService"); 
     logger.info("Obtained some object "+x.toString()); 
     logger.info("Trying to cast."); 
     PrintService s = (PrintService) x; 
     logger.info("Cast successful"); 
     logger.info("Printing using remote ejb: "+s.print("Markus")); 
    } catch (NamingException e) { 
     e.printStackTrace(); 
    } 
    } 
} 

Receiver chứa PrintBean:

@Stateless 
@Remote(PrintService.class) 
public class PrintBean implements PrintService { 

    @Override 
    public String print(String name) { 
    return "Hello " + name; 
    } 
} 

vấn đề bây giờ là, tôi luôn luôn có được một IllegalStateException nói rằng EJBCLIENT000025 : Không có bộ thu EJB nào có sẵn để xử lý ...

Tôi có có thể làm điều gì đó rất sai? Tôi khá mới với EJB và Wildfly. Bạn có thể tìm thấy thiết lập dự án trên GitHub.

Trả lời

1

Bạn nên thêm tệp jboss-ejb-client.xml vào người gửi EAR của bạn (không phải WAR). Đặt nó bên cạnh application.xml.

nội dung JBoss-ejb-client.xml:

<jboss-ejb-client> 
    <client-context> 
     <ejb-receivers> 
      <remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection"/> 
     </ejb-receivers> 
    </client-context> 
</jboss-ejb-client> 

Trong đậu gửi hai dòng là đủ:

Context context = new InitialContext(); 
Object x = context.lookup("ejb:baseproject-ear-01.00.00-SNAPSHOT/testdomain-service-01.00.00-SNAPSHOT/PrintBean!com.schubert.baseproject.testdomain.service.PrintService"); 

Lưu ý rằng tôi gỡ bỏ "Receiver /" từ con đường. Bạn có thể tìm thấy các ràng buộc JNDI trong nhật ký máy chủ.

0

Trên vấn đề về tâm trí của tôi được đặt trong các tham số cho InitialContext, cấu hình máy chủ là tốt. Cố gắng làm theo ví dụ của tôi kết nối vào hàng đợi từ xa, trong trường hợp enterprise bean thông thường bạn có thể khám phá kịch bản như vậy quá (chèn đăng nhập đúng người dùng và mật khẩu):

env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); 
    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
    env.put(Context.SECURITY_PRINCIPAL, "client"); 
    env.put(Context.SECURITY_CREDENTIALS, "q"); 

    Context ctx = new InitialContext(env); 
    connectionFactory = (ConnectionFactory)ctx.lookup("/jms/RemoteConnectionFactory"); 
    connection = connectionFactory.createConnection("client", "q"); 

Hãy nhớ rằng, các nguồn lực jndi với mở khả năng truy cập bên ngoài phải bắt đầu tại cấu hình máy chủ với java:/jboss/exports /, nhưng ở phía máy khách, bạn có thể thả xuống từ này. Hướng dẫn này là tốt cho WildFly, nhưng không cho JBoss EAP/AS và những người khác.Thông tin thêm bạn có thể nhận được bằng cách theo dõi link.

Các vấn đề liên quan