1

ここで次のことを試します: リモート EJB を呼び出す Web アプリケーションがあります。

@WebServlet("/token")
@SuppressWarnings("serial")
public class TokenServlet extends HttpServlet {

@EJB
private TokenService tokenService;

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    Token token = tokenService.getToken();

    tokenService.setToken(token);

}

}

サービス ejb:

@Stateless
@Remote
public class TokenServiceImpl implements TokenService {

private Token token = new Token();

@Override
public Token getToken() {
    System.out.println("class: " + TokenServiceImpl.class
            + ", method: getToken() - " + "token value: '"
            + token.getToken() + "' reference: " + this.token);

    return this.token;
}

@Override
public void setToken(Token token) {
    boolean referenceEquality = this.token == token;
    boolean valueEquality = this.token.equals(token);
    System.out.println("class " + TokenServiceImpl.class
            + ", methos: setToken(Token token)");
    System.out.println("test for reference equality: " + " " + this.token
            + " == " + token + " --> " + referenceEquality);
    System.out.println("test for value equality: " + " " + this.token
            + " equals " + token + " --> " + valueEquality);

    this.token = token;
}

webproject(.war) と ejbproject(.ear) は、glassfish-application.xml エントリで個別にデプロイされます。

<!DOCTYPE glassfish-application PUBLIC "-//GlassFish.org//DTD
GlassFish Application Server 3.1 Java EE Application 6.0//EN"
"http://glassfish.org/dtds/glassfish-application_6_0-1.dtd">
<glassfish-application>
   <pass-by-reference>true</pass-by-reference>
</glassfish-application>

class: class TokenServiceImpl, method: getToken() - token value: '     
'default token value' reference: com.ebcont.domain.impl.Token@7fef01a8|#]

class TokenServiceImpl, method: setToken(Token token)|#]
test for reference equality:  Token@7fef01a8 == Token@2f4d4e75 --> false|#]
test for value equality:  Token@7fef01a8 equals Token@2f4d4e75 --> false|#]

リモート EJB で call-by-reference を使用することはできませんか?

4

1 に答える 1