小编Tob*_*sse的帖子

CDI不在从工厂模式实现创建的对象中工作

我试图在这里解决一些问题:注入仅适用于我的应用程序的第一层,但随后它停止,并且从我的工厂模式实现返回的对象中所有@Inject注释属性都为null.我读了很多关于让CDI与JAX-RS一起工作有问题的人,但这似乎不是我的问题.我觉得我错过了一些注释,或者我没有看到所有树木前面的木头(正如我们在这里所说);-)

编辑:是否有一个示例项目与我在这里发布的代码进行仔细检查.现在我意识到我过度简化了:事实上我正在使用工厂模式来获取我的服务,这可能会中断托管上下文.请参阅增强示例:

我们走吧.

第一层:JAX-RS应用程序,一切都很好

@RequestScoped
@Path("/somePath/someResource")
public class SomeResource {
   @Inject
   ISomeServiceFactory someServiceFactory;

   @POST
   @Produces(MediaType.APPLICATION_JSON)
   @Consumes(MediaType.APPLICATION_JSON)
   public SomeResponse someMethod(@PathParam("foo") final String foo) {
      ISomeService myService = someServiceFactory.getService(ServiceCatalog.valueOf(foo));   // works, we jump in there!
      myService.someMethod();
   }

}

public enum ServiceCatalog {
  STANDARD("standard"), ADVANCED("advanced"), FOO("foo");
  // ...
} 
Run Code Online (Sandbox Code Playgroud)

正在从REST API调用中选择基于已知参数(Enum)值的实现的已损坏服务工厂:

public interface ISomeServiceFactory {
  public ISomeService getService(ServiceCatalog serviceType);
} 

@Stateless
public class SomeServiceFactory implements ISomeServiceFactory {
  public ISomeService getService(ServiceCatalog serviceType) { …
Run Code Online (Sandbox Code Playgroud)

ejb java-ee cdi websphere-liberty

5
推荐指数
1
解决办法
620
查看次数

带有Liberty的Bluemix SSO:被AuthFailed困住(CWWKS9104A)

我正在尝试使用Bluemix,并尝试在我的WebSphere Liberty WebApp上添加单点登录.因此我按照指南.添加了SSO服务,其中包含Cloud Directory身份提供程序,将我的WebApp绑定到该服务,并修改了XML配置.

我从演示应用程序开始,并从那里量身定制.

的src /主/ web应用/ WEB-INF/web.xml中

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>MyApp</display-name>

<security-constraint>
    <display-name>MyApp</display-name>
    <web-resource-collection>
        <web-resource-name>chat-web</web-resource-name>
        <url-pattern>/</url-pattern>
        <url-pattern>/*</url-pattern>
        <url-pattern>/chat-web/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>PUT</http-method>
        <http-method>HEAD</http-method>
        <http-method>TRACE</http-method>
        <http-method>POST</http-method>
        <http-method>DELETE</http-method>
        <http-method>OPTIONS</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>any-authenticated</role-name>
    </auth-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

的src /主/ WLP/server.xml中

<featureManager>
    <feature>servlet-3.1</feature>
</featureManager>

<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080">
    <tcpOptions soReuseAddr="true" />
</httpEndpoint>

<application name="chat-web" context-root="chat-web"
    location="${appLocation}" type="war">
    <application-bnd>
        <security-role name="any-authenticated">
            <special-subject type="ALL_AUTHENTICATED_USERS" />
        </security-role>
    </application-bnd>
</application>
Run Code Online (Sandbox Code Playgroud)

我在Cloud Directory中创建了一个测试用户"tobi",该用户链接到我的SSO服务.当我部署应用程序时,我可以看到SSO依赖项/代码被组合/组装到应用程序包中.然而,如果我尝试登录应用程序,它会失败,我总是看到以下错误:

1/2/2016 5:31:10 PM OUT App [INFO    ] JSPG8502I: The value of …
Run Code Online (Sandbox Code Playgroud)

single-sign-on websphere-liberty ibm-cloud

4
推荐指数
1
解决办法
811
查看次数