开发者

How to set properties in a Seam component before @create?

I'm trying to set the following members of Component org.jboss.seam.mail.mailSession which are defined as:

boolean ssl;
boolean tls = true;

(both have getter and setter methods) before the method create which is annotated with @Create is called . I want to prevent the framework to use SSL,TLS. The mailSession component checks whether these mebers are set. If yes it creates properties which force javamail to use ssl.

I tried so far:

Object comp = Component.getInstance("org.jboss.seam.mail.mailSession");

Problem: unwraps to javax.mail.Session where I can't access the component.

Object comp = Component.getInstance("org.jboss.seam.mail.mailSession", ScopeType.APPLICATION,false,false);

Problem: returns null since no instance is created.

Component comp = Component.forName("org.jboss.seam.mail.mailSession");

Problem: A component and not the instance is returned.

What should I do to toggle 2 b开发者_开发知识库its, would you recommend to patch the framework, or is there an easier way I've overlooked?


According to Seam reference manual and Seam forum you should be able to disable TLS and SSL directly in your components.xml configuration:

<mail:mail-session debug="true" tls="false" ssl="false" ... />

Have you already tried that?


Did you try to override the mailSession? I am not sure if it works though...

Something along the lines of

@Name("org.jboss.seam.mail.mailSession")
@Install(precedence=Application)
class MyMailSession extends MailSession {

  //override the stuff you want here
}


I solved it using this sequence:

@In(create = true)
private Renderer renderer;
...
Component comp = Component.forName("org.jboss.seam.mail.mailSession");
MailSession ms = (MailSession)  comp.newInstance();
ms.setDebug(true);
ms.setTls(false);
ms.setSsl(false);
ms = ms.create();

renderer.render("/Mail.xhtml");

I wonder how the MailSession instance is attached to the component, but for now it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜