Showing posts with label CDI. Show all posts
Showing posts with label CDI. Show all posts

Saturday, May 11, 2013

Weblogic 12.1.1 and WELD-001408 Unsatisfied dependencies for type error test

Issues with Weld are fixed in Weblogic 12.1.2 which uses newer version of Weld library
http://docs.oracle.com/middleware/1212/wls/NOTES/index.html#NOTES254

Weblogic 12.1.1  is strictly checking all injections at deployment time

Utility project  jar used by Weld must also have beans.xml file 

http://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html_single/#d0e4697


Following error is thrown for failed injection validation WELD-001408 Unsatisfied dependencies for type



<May 11, 2013 7:34:08 PM CEST> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "weld-ear-1.0-SNAPSHOT".> 
<May 11, 2013 7:34:08 PM CEST> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.management.DeploymentException: 
    at weblogic.application.internal.BaseDeployment.throwAppException(BaseDeployment.java:123)
    at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:239)
    at weblogic.application.internal.EarDeployment.prepare(EarDeployment.java:61)
    at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:158)
    at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
    Truncated. see log file for complete stacktrace
Caused By: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [String] with qualifiers [@Default] at injection point [[field] @Inject private dave.TestServlet.injectedValue]
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:258)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:105)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:125)
    at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:324)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:309)
    Truncated. see log file for complete stacktrace
> 

Creating Shared Java EE Libraries and Optional Packages http://docs.oracle.com/cd/E24329_01/web.1211/e24368/libraries.htm#autoId2


https://cn.forums.oracle.com/forums/thread.jspa?threadID=2485198&start=0&tstart=1

https://forums.oracle.com/forums/thread.jspa?threadID=2506170&tstart=0

http://stackoverflow.com/questions/5060314/inject-a-stateless-ejb-with-inject-into-cdi-weld-managedbean-jsf-1-2-ejb-appli

Three projects are created:
-  Web  project using Weld injection from utility jar
- utility jar project with class for injection
- ear projected packaging war and utility jar

Create Java EE project with Maven
http://www.adam-bien.com/roller/abien/entry/creating_java_ee_6_projects

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 278: 479
Choose org.codehaus.mojo.archetypes:webapp-javaee6 version: 
1: 1.0
2: 1.0.1
3: 1.0.2
4: 1.1
5: 1.2
6: 1.3
7: 1.4
8: 1.5
Choose a number: 8: 
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/mojo/archetypes/webapp-javaee6/1.5/webapp-javaee6-1.5.jar
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/mojo/archetypes/webapp-javaee6/1.5/webapp-javaee6-1.5.jar (2 KB at 13.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/mojo/archetypes/webapp-javaee6/1.5/webapp-javaee6-1.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/codehaus/mojo/archetypes/webapp-javaee6/1.5/webapp-javaee6-1.5.pom (918 B at 3.0 KB/sec)
Define value for property 'groupId': : weld-web
Define value for property 'artifactId': : weld-web
Define value for property 'version':  1.0-SNAPSHOT: : 
Define value for property 'package':  weld-web: : dave
Confirm properties configuration:
groupId: weld-web
artifactId: weld-web
version: 1.0-SNAPSHOT
package: dave
 Y: : 
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: webapp-javaee6:1.5
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: weld-web
[INFO] Parameter: artifactId, Value: weld-web
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: dave
[INFO] Parameter: packageInPathFormat, Value: dave
[INFO] Parameter: package, Value: dave
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: groupId, Value: weld-web
[INFO] Parameter: artifactId, Value: weld-web
[INFO] project created from Archetype in dir: /home/dave/workspace/weld-web
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:58.096s
[INFO] Finished at: Wed Jun 05 09:54:07 CEST 2013
[INFO] Final Memory: 12M/105M
[INFO] ------------------------------------



Maven Weblogic plugin
http://docs.oracle.com/cd/E21764_01/web.1111/e13702/maven_deployer.htm

Kepler Java EE already comes with m2e Maven Eclipse plugin
http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/keplerrc2

ear project


[dave@dave weld-ear]$ ls -lR
.:
total 12
-rw-rw-r--. 1 dave dave 1837 May 11 18:48 pom.xml
drwxrwxr-x. 3 dave dave 4096 May 11 13:41 src
drwxrwxr-x. 4 dave dave 4096 May 11 19:35 target

./src:
total 4
drwxrwxr-x. 3 dave dave 4096 May 11 13:41 main

./src/main:
total 4
drwxrwxr-x. 3 dave dave 4096 May 11 13:41 application

./src/main/application:
total 4
drwxrwxr-x. 2 dave dave 4096 May 11 13:41 META-INF

./src/main/application/META-INF:
total 4
-rw-rw-r--. 1 dave dave 23 May 11 13:41 MANIFEST.MF

./target:
total 20
-rw-rw-r--. 1 dave dave  494 May 11 19:35 application.xml
drwxrwxr-x. 2 dave dave 4096 May 11 19:35 maven-archiver
drwxrwxr-x. 4 dave dave 4096 May 11 19:35 weld-ear-1.0-SNAPSHOT
-rw-rw-r--. 1 dave dave 6359 May 11 19:35 weld-ear-1.0-SNAPSHOT.ear

./target/maven-archiver:
total 4
-rw-rw-r--. 1 dave dave 109 May 11 19:35 pom.properties

./target/weld-ear-1.0-SNAPSHOT:
total 12
drwxrwxr-x. 2 dave dave 4096 May 11 19:35 lib
drwxrwxr-x. 2 dave dave 4096 May 11 19:35 META-INF
-rw-rw-r--. 1 dave dave 3640 May 11 19:35 weld-web.war

./target/weld-ear-1.0-SNAPSHOT/lib:
total 4
-rw-rw-r--. 1 dave dave 2294 May 11 19:35 testUtility-1.0-SNAPSHOT.jar

./target/weld-ear-1.0-SNAPSHOT/META-INF:
total 8
-rw-rw-r--. 1 dave dave 494 May 11 19:35 application.xml
-rw-rw-r--. 1 dave dave  23 May 11 19:35 MANIFEST.MF
[dave@dave weld-ear]$ 



web project

[dave@dave weld-web]$ ls -lR
.:
total 12
-rw-rw-r--. 1 dave dave 2899 May 11 19:48 pom.xml
drwxrwxr-x. 3 dave dave 4096 May 11 13:42 src
drwxrwxr-x. 8 dave dave 4096 May 11 19:20 target

./src:
total 4
drwxrwxr-x. 4 dave dave 4096 May 11 13:42 main

./src/main:
total 8
drwxrwxr-x. 3 dave dave 4096 May 11 13:42 java
drwxrwxr-x. 3 dave dave 4096 May 11 19:16 webapp

./src/main/java:
total 4
drwxrwxr-x. 2 dave dave 4096 May 11 18:26 dave

./src/main/java/dave:
total 4
-rw-rw-r--. 1 dave dave 1285 May  9 22:56 TestServlet.java

./src/main/webapp:
total 8
-rw-rw-r--. 1 dave dave  361 May 11 13:42 index.jsp
drwxrwxr-x. 2 dave dave 4096 May 11 19:17 WEB-INF

./src/main/webapp/WEB-INF:
total 4
-rw-rw-r--. 1 dave dave 269 May  9 23:06 beans.xml

./target:
total 28
drwxrwxr-x. 3 dave dave 4096 May 11 19:20 classes
drwxrwxr-x. 2 dave dave 4096 May 11 19:20 endorsed
drwxrwxr-x. 3 dave dave 4096 May 11 19:20 generated-sources
drwxrwxr-x. 2 dave dave 4096 May 11 19:20 maven-archiver
drwxrwxr-x. 2 dave dave 4096 May 11 19:20 surefire
drwxrwxr-x. 4 dave dave 4096 May 11 19:20 weld-web-1.0-SNAPSHOT
-rw-rw-r--. 1 dave dave 3640 May 11 19:20 weld-web-1.0-SNAPSHOT.war

./target/classes:
total 4
drwxrwxr-x. 2 dave dave 4096 May 11 19:20 dave

./target/classes/dave:
total 4
-rw-rw-r--. 1 dave dave 1443 May 11 19:20 TestServlet.class

./target/endorsed:
total 108
-rw-rw-r--. 1 dave dave 108093 May 11 19:20 javaee-endorsed-api-6.0.jar

./target/generated-sources:
total 4
drwxrwxr-x. 2 dave dave 4096 May 11 19:20 annotations

./target/generated-sources/annotations:
total 0

./target/maven-archiver:
total 4
-rw-rw-r--. 1 dave dave 109 May 11 19:20 pom.properties

./target/surefire:
total 0

./target/weld-web-1.0-SNAPSHOT:
total 12
-rw-rw-r--. 1 dave dave  361 May 11 13:42 index.jsp
drwxrwxr-x. 2 dave dave 4096 May 11 19:20 META-INF
drwxrwxr-x. 3 dave dave 4096 May 11 19:20 WEB-INF

./target/weld-web-1.0-SNAPSHOT/META-INF:
total 0

./target/weld-web-1.0-SNAPSHOT/WEB-INF:
total 8
-rw-rw-r--. 1 dave dave  269 May  9 23:06 beans.xml
drwxrwxr-x. 3 dave dave 4096 May 11 19:20 classes

./target/weld-web-1.0-SNAPSHOT/WEB-INF/classes:
total 4
drwxrwxr-x. 2 dave dave 4096 May 11 19:20 dave

./target/weld-web-1.0-SNAPSHOT/WEB-INF/classes/dave:
total 4
-rw-rw-r--. 1 dave dave 1443 May 11 19:20 TestServlet.class
[dave@dave weld-web]$ 


utility project

[dave@dave testUtility]$ ls -lR
.:
total 12
-rw-rw-r--. 1 dave dave  849 May 11 18:46 pom.xml
drwxrwxr-x. 4 dave dave 4096 May 11 18:43 src
drwxrwxr-x. 7 dave dave 4096 May 11 19:34 target

./src:
total 8
drwxrwxr-x. 4 dave dave 4096 May 11 19:18 main
drwxrwxr-x. 3 dave dave 4096 May 11 18:43 test

./src/main:
total 8
drwxrwxr-x. 3 dave dave 4096 May 11 18:43 java
drwxrwxr-x. 3 dave dave 4096 May 11 19:18 resources

./src/main/java:
total 4
drwxrwxr-x. 2 dave dave 4096 May 11 18:46 dave

./src/main/java/dave:
total 4
-rw-rw-r--. 1 dave dave 167 May 11 18:45 ValueProducer.java

./src/main/resources:
total 4
drwxrwxr-x. 2 dave dave 4096 May 11 19:18 META-INF

./src/main/resources/META-INF:
total 4
-rw-rw-r--. 1 dave dave 269 May 11 19:18 beans.xml

./src/test:
total 4
drwxrwxr-x. 3 dave dave 4096 May 11 18:43 java

./src/test/java:
total 4
drwxrwxr-x. 2 dave dave 4096 May 11 18:43 dave

./src/test/java/dave:
total 4
-rw-rw-r--. 1 dave dave 632 May 11 18:43 AppTest.java

./target:
total 24
drwxrwxr-x. 4 dave dave 4096 May 11 19:34 classes
drwxrwxr-x. 2 dave dave 4096 May 11 19:34 maven-archiver
drwxrwxr-x. 2 dave dave 4096 May 11 19:34 surefire
drwxrwxr-x. 2 dave dave 4096 May 11 19:34 surefire-reports
drwxrwxr-x. 3 dave dave 4096 May 11 19:34 test-classes
-rw-rw-r--. 1 dave dave 2294 May 11 19:34 testUtility-1.0-SNAPSHOT.jar

./target/classes:
total 8
drwxrwxr-x. 2 dave dave 4096 May 11 19:34 dave
drwxrwxr-x. 2 dave dave 4096 May 11 19:34 META-INF

./target/classes/dave:
total 4
-rw-rw-r--. 1 dave dave 468 May 11 19:34 ValueProducer.class

./target/classes/META-INF:
total 4
-rw-rw-r--. 1 dave dave 269 May 11 19:34 beans.xml

./target/maven-archiver:
total 4
-rw-rw-r--. 1 dave dave 115 May 11 19:34 pom.properties

./target/surefire:
total 0

./target/surefire-reports:
total 12
-rw-rw-r--. 1 dave dave  257 May 11 19:34 dave.AppTest.txt
-rw-rw-r--. 1 dave dave 4145 May 11 19:34 TEST-dave.AppTest.xml

./target/test-classes:
total 4
drwxrwxr-x. 2 dave dave 4096 May 11 19:34 dave

./target/test-classes/dave:
total 4
-rw-rw-r--. 1 dave dave 588 May 11 19:34 AppTest.class
[dave@dave testUtility]$ 



[dave@dave testUtility]$ more ./src/main/java/dave/ValueProducer.java
package dave;


import javax.enterprise.inject.Produces;
 
public class ValueProducer {
 
    @Produces
    public String stringValue() {
        return "someStringValue";
    }
 
}



[dave@dave weld-web]$ more ./src/main/java/dave/TestServlet.java
package dave;

import java.io.IOException;
import java.io.PrintWriter;

import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TestServlet
 */
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TestServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    @Inject
    private String injectedValue;
 
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
 
        PrintWriter pw = response.getWriter();
        pw.write("injectedValue: " + injectedValue);
        pw.flush();
 
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws Servlet
Exception, IOException {
        // TODO Auto-generated method stub
    }

}



[dave@dave weld-web]$ more pom.xml 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc
e"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0
.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>weld-web</groupId>
    <artifactId>weld-web</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>weld-web</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
[dave@dave weld-web]$           



[dave@dave weld-ear]$ more pom.xml 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc
e"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>weld-ear</groupId>
  <artifactId>weld-ear</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>ear</packaging>

  <name>weld-ear</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

<dependencies>
<dependency>
       <groupId>weld-web</groupId>
    <artifactId>weld-web</artifactId>
    <version>1.0-SNAPSHOT</version>
    <type>war</type>
</dependency>
<dependency>
       <groupId>testUtility</groupId>
    <artifactId>testUtility</artifactId>
    <version>1.0-SNAPSHOT</version>
    <type>jar</type>
</dependency>
</dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <version>6</version>
            <defaultLibBundleDir>lib</defaultLibBundleDir>
             <modules>
            <webModule>
                <groupId>weld-web</groupId>
                <artifactId>weld-web</artifactId>
                <uri>weld-web.war</uri>
                <bundleFileName>weld-web.war</bundleFileName>
                <contextRoot>/weld-web</contextRoot>
            </webModule>
        </modules>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

building ear with Maven

[dave@dave weld-ear]$ mvn clean install
/usr/java//jdk1.7.0_21
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building weld-ear 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ weld-ear ---
[INFO] Deleting /home/dave/workspace/weld-ear/target
[INFO] 
[INFO] --- maven-ear-plugin:2.6:generate-application-xml (default-generate-application-xml) @ weld-ear ---
[INFO] Generating application.xml
[INFO] 
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ weld-ear ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/dave/workspace/weld-ear/src/main/resources
[INFO] 
[INFO] --- maven-ear-plugin:2.6:ear (default-ear) @ weld-ear ---
[INFO] Copying artifact[war:weld-web:weld-web:1.0-SNAPSHOT] to[weld-web.war]
[INFO] Copying artifact[jar:testUtility:testUtility:1.0-SNAPSHOT] to[lib/testUtility-1.0-SNAPSHOT.jar]
[INFO] Copy ear sources to /home/dave/workspace/weld-ear/target/weld-ear-1.0-SNAPSHOT
[INFO] Including custom manifest file[/home/dave/workspace/weld-ear/target/weld-ear-1.0-SNAPSHOT/META-INF/MANIFEST.MF]
[INFO] Building jar: /home/dave/workspace/weld-ear/target/weld-ear-1.0-SNAPSHOT.ear
[INFO] 
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ weld-ear ---
[INFO] Installing /home/dave/workspace/weld-ear/target/weld-ear-1.0-SNAPSHOT.ear to /home/dave/.m2/repository/weld-ear/weld-ear/1.0-SNAPSHOT/weld-ear-1.0-SNAPSHOT.ear
[INFO] Installing /home/dave/workspace/weld-ear/pom.xml to /home/dave/.m2/repository/weld-ear/weld-ear/1.0-SNAPSHOT/weld-ear-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.520s
[INFO] Finished at: Sat May 11 20:15:00 CEST 2013
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
[dave@dave weld-ear]$ 

generated application.xml file

[dave@dave weld-ear]$ more ./target/application.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-ins
tance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/applica
tion_6.xsd" version="6">
  <display-name>weld-ear</display-name>
  <module>
    <web>
      <web-uri>weld-web.war</web-uri>
      <context-root>/weld-web</context-root>
    </web>
  </module>
  <library-directory>lib</library-directory>
</application>


ear content
[dave@dave weld-ear]$ jar tvf target/weld-ear-1.0-SNAPSHOT.ear 
     0 Sat May 11 20:15:02 CEST 2013 META-INF/
   123 Sat May 11 20:15:00 CEST 2013 META-INF/MANIFEST.MF
     0 Sat May 11 20:15:00 CEST 2013 lib/
   494 Sat May 11 20:15:00 CEST 2013 META-INF/application.xml
  2294 Sat May 11 20:15:00 CEST 2013 lib/testUtility-1.0-SNAPSHOT.jar
  3640 Sat May 11 20:15:00 CEST 2013 weld-web.war
     0 Sat May 11 20:15:02 CEST 2013 META-INF/maven/
     0 Sat May 11 20:15:02 CEST 2013 META-INF/maven/weld-ear/
     0 Sat May 11 20:15:02 CEST 2013 META-INF/maven/weld-ear/weld-ear/
  1837 Sat May 11 18:48:28 CEST 2013 META-INF/maven/weld-ear/weld-ear/pom.xml
   109 Sat May 11 20:15:00 CEST 2013 META-INF/maven/weld-ear/weld-ear/pom.properties


war content
[dave@dave weld-web]$ jar tvf target/weld-web-1.0-SNAPSHOT.war 
     0 Sat May 11 19:20:28 CEST 2013 META-INF/
   123 Sat May 11 19:20:26 CEST 2013 META-INF/MANIFEST.MF
     0 Sat May 11 19:20:28 CEST 2013 WEB-INF/
     0 Sat May 11 19:20:28 CEST 2013 WEB-INF/classes/
     0 Sat May 11 19:20:28 CEST 2013 WEB-INF/classes/dave/
   361 Sat May 11 13:43:00 CEST 2013 index.jsp
   269 Thu May 09 23:06:38 CEST 2013 WEB-INF/beans.xml
  1443 Sat May 11 19:20:24 CEST 2013 WEB-INF/classes/dave/TestServlet.class
     0 Sat May 11 19:20:28 CEST 2013 META-INF/maven/
     0 Sat May 11 19:20:28 CEST 2013 META-INF/maven/weld-web/
     0 Sat May 11 19:20:28 CEST 2013 META-INF/maven/weld-web/weld-web/
  3073 Sat May 11 19:19:30 CEST 2013 META-INF/maven/weld-web/weld-web/pom.xml
   109 Sat May 11 19:20:28 CEST 2013 META-INF/maven/weld-web/weld-web/pom.properties

utility jar content
[dave@dave testUtility]$ jar tvf target/testUtility-1.0-SNAPSHOT.jar 
     0 Sat May 11 19:34:58 CEST 2013 META-INF/
   123 Sat May 11 19:34:56 CEST 2013 META-INF/MANIFEST.MF
     0 Sat May 11 19:34:52 CEST 2013 dave/
   269 Sat May 11 19:34:50 CEST 2013 META-INF/beans.xml
   468 Sat May 11 19:34:52 CEST 2013 dave/ValueProducer.class
     0 Sat May 11 19:34:58 CEST 2013 META-INF/maven/
     0 Sat May 11 19:34:58 CEST 2013 META-INF/maven/testUtility/
     0 Sat May 11 19:34:58 CEST 2013 META-INF/maven/testUtility/testUtility/
   849 Sat May 11 18:46:42 CEST 2013 META-INF/maven/testUtility/testUtility/pom.xml
   115 Sat May 11 19:34:56 CEST 2013 META-INF/maven/testUtility/testUtility/pom.properties


deploy  project

 mvn com.oracle.weblogic:weblogic-maven-plugin:^Cploy -Dadminurl=t3://localhost:7001 -Duser=weblogic -Dpassword=weblogic123 -Dtargets=AdminServer -Dsource=target/weld-ear-1.0-SNAPSHOT.ear -Dname=weld-ear


[dave@dave weld-ear]$ mvn com.oracle.weblogic:weblogic-maven-plugin:deploy -Dadminurl=t3://localhost:7001 -Duser=weblogic -Dpassword=weblogic123 -Dtargets=AdminServer -Dsource=target/weld-ear-1.0-SNAPSHOT.ear -Dname=weld-ear
/usr/java//jdk1.7.0_21
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building weld-ear 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- weblogic-maven-plugin:12.1.1.0:deploy (default-cli) @ weld-ear ---
weblogic.Deployer invoked with options:  -noexit -adminurl t3://localhost:7001 -user weblogic -deploy -name weld-ear -source target/weld-ear-1.0-SNAPSHOT.ear -targets AdminServer
<May 11, 2013 7:36:28 PM CEST> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, weld-ear [archive: /home/dave/workspace/weld-ear/target/weld-ear-1.0-SNAPSHOT.ear], to AdminServer .> 
Task 10 initiated: [Deployer:149026]deploy application weld-ear on AdminServer.
Task 10 completed: [Deployer:149026]deploy application weld-ear on AdminServer.
Target state: deploy completed on Server AdminServer

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.317s
[INFO] Finished at: Sat May 11 19:36:30 CEST 2013
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------


Test application at  http://localhost:7001/weld-web/TestServlet










Thursday, April 4, 2013

Weblogic 12.1.1 Java EE 6 CDI Weld requires patches

Weld issues are fixed in version 12.1.2
http://docs.oracle.com/middleware/1212/wls/NOTES/index.html#NOTES254



CDI  Weld patches are required on Java EE 6 Weblogic 12.1.1

 Caused By: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type
https://forums.oracle.com/forums/thread.jspa?messageID=10760194

http://biemond.blogspot.cz/2012/01/jsf-20-managed-bean-annotations-and-cdi.html

https://forums.oracle.com/forums/thread.jspa?threadID=2391298

Check installed patches with bsu utility
http://docs.oracle.com/cd/E14759_01/doc.32/e14143/commands.htm#i1071660

Patches delivered with installation from otn
-report
    

Generates a report showing the applied patches and associated file changes in a Middleware home directory.


[dave@dave weblogic]$ cd utils/bsu/
[dave@dave bsu]$ ./bsu.sh -report
Patch Report
============
  Report Info
    Report Options
      bea_home.................. ### OPTION NOT SET
      product_mask.............. ### OPTION NOT SET
      release_mask.............. ### OPTION NOT SET
      profile_mask.............. ### OPTION NOT SET
      patch_id_mask............. ### OPTION NOT SET
    Report Messages
  BEA Home.................. /opt/weblogic
  
  Product Description
  Product Name.............. WebLogic Server
  Product Version........... 12.1.1.0
  Installed Components...... Core Application Server, Administration Console, Configuration Wizard and Upgrade Framework, Web 2.0 HTTP Pub-Sub Server, WebLogic SCA, WebLogic JDBC Drivers, Third Party JDBC Drivers, WebLogic Server Clients, Xquery Support, Evaluation Database, Workshop Code Completion Support
  Product Install Directory. /opt/weblogic/wlserver_12.1
  Java Home................. /opt/weblogic/jdk160_29
  Jave Vendor............... Sun
  Java Version.............. 1.6.0_29
  Patch Directory........... /opt/weblogic/patch_wls1211
    
    Profile................... Default
      
      Patch ID.................. 97L5
      CR(s)..................... 
      Description............... SERVLET 3.0 FILE UPLOAD BREAKS OTHER FILE UPLOAD FRAMEWORKS
SERVLET 3.0 FILE UPLOAD BREAKS OTHER FILE UPLOAD FRAMEWORKS
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13657792_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... weblogic/servlet/internal/ServletRegistrationImpl.class
            File...................... weblogic/servlet/internal/ServletRequestImpl$1.class
            File...................... weblogic/servlet/internal/ServletRequestImpl$AuthenticateResponseWrapper.class
            File...................... weblogic/servlet/internal/ServletRequestImpl$CookieKey.class
            File...................... weblogic/servlet/internal/ServletRequestImpl$ExtraIncludeParams.class
            File...................... weblogic/servlet/internal/ServletRequestImpl$ExtraParams.class
            File...................... weblogic/servlet/internal/ServletRequestImpl$RequestInputHelper.class
            File...................... weblogic/servlet/internal/ServletRequestImpl$RequestParameters.class
            File...................... weblogic/servlet/internal/ServletRequestImpl$SessionHelper.class
            File...................... weblogic/servlet/internal/ServletRequestImpl.class
            File...................... weblogic/servlet/internal/ServletStubFactory.class
            File...................... weblogic/servlet/internal/ServletStubImpl$1.class
            File...................... weblogic/servlet/internal/ServletStubImpl.class
      
      Patch ID.................. NST7
      CR(s)..................... 
      Description............... UNCAUGHT EXCEPTION IN SERVER HANDLERJAVAX.NET.SSL.SSLEXCEPTION: ERROR GENERATING
UNCAUGHT EXCEPTION IN SERVER HANDLERJAVAX.NET.SSL.SSLEXCEPTION: ERROR GENERATING
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13421471_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... weblogic/security/utils/KeyStoreInstall.class
      
      Patch ID.................. 4331
      CR(s)..................... 
      Description............... WEB SERVICE THAT IMPLEMENTS PROVIDER INTERFACE CANNOT BE GENERATED A
WEB SERVICE THAT IMPLEMENTS PROVIDER INTERFACE CANNOT BE GENERATED A
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13361720_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... weblogic/wsee/tools/jws/build/JwsCompiler.class
      
      Patch ID.................. RCMZ
      CR(s)..................... 
      Description............... UNDEPLOYING A SUBMODULE JMS FAILS
UNDEPLOYING A SUBMODULE JMS FAILS
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13424251_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... weblogic/cluster/migration/MigrationManager$1.class
            File...................... weblogic/cluster/migration/MigrationManager.class
      
      Patch ID.................. 53JP
      CR(s)..................... 
      Description............... MERGE LABEL REQUEST ON TOP OF 12.1.1 FOR CDI BUGS
MERGE LABEL REQUEST ON TOP OF 12.1.1 FOR CDI BUGS
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13603813_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... com/oracle/injection/integration/CDIAppDeploymentExtension$1.class
            File...................... com/oracle/injection/integration/CDIAppDeploymentExtension.class
            File...................... com/oracle/injection/integration/CDIModuleExtension$RarModuleInjectionArchive.class
            File...................... com/oracle/injection/integration/CDIModuleExtension$WebInfLibInjectionArchive.class
            File...................... com/oracle/injection/integration/CDIModuleExtension.class
            File...................... com/oracle/injection/integration/CDIUtils.class
            File...................... com/oracle/injection/provider/weld/BasicDeployment$1.class
            File...................... com/oracle/injection/provider/weld/BasicDeployment$NullJpaInjectionServicesAdapter.class
            File...................... com/oracle/injection/provider/weld/BasicDeployment$RootBeanDeploymentArchive.class
            File...................... com/oracle/injection/provider/weld/BasicDeployment.class
            File...................... com/oracle/injection/provider/weld/WeldValidationServicesAdapter.class
            File...................... weblogic/application/internal/flow/TailVersionLifecycleFlow.class
            File...................... weblogic/application/ModuleManager.class
            File...................... weblogic/transaction/internal/ServerSCInfo$1.class
            File...................... weblogic/transaction/internal/ServerSCInfo$2.class
            File...................... weblogic/transaction/internal/ServerSCInfo$3.class
            File...................... weblogic/transaction/internal/ServerSCInfo$CallAfterCompletionsAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$CallBeforeCompletionsAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$ForceLocalCommitAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$ForceLocalRollbackAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$GetPropertiesAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$NonXAResourceCommitAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$RecoverAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$RegisteredSync.class
            File...................... weblogic/transaction/internal/ServerSCInfo$RollbackAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$StartCommitAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$StartPrepareAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo$StartPrePrepareAndChain.class
            File...................... weblogic/transaction/internal/ServerSCInfo$StartRollbackAction.class
            File...................... weblogic/transaction/internal/ServerSCInfo.class
      
      Patch ID.................. 1U7B
      CR(s)..................... 
      Description............... VERBOSE SUPPORT DOESN'T SUPPORT NOT WITH WILDCARD ALWAYS DUMPS THE SOAP MESSAGE
VERBOSE SUPPORT DOESN'T SUPPORT NOT WITH WILDCARD ALWAYS DUMPS THE SOAP MESSAGE
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13641115_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... weblogic/wsee/util/Verbose$1.class
            File...................... weblogic/wsee/util/Verbose.class
      
      Patch ID.................. B33B
      CR(s)..................... 
      Description............... CANNOT CREATE "OTHER" DATASOURCE IN CONSOLE.
CANNOT CREATE "OTHER" DATASOURCE IN CONSOLE.
      Other artifacts
        Destination............... $WLS_INSTALL_DIR$/server/lib/consoleapp/webapp/WEB-INF/lib/console.jar
      
      Patch ID.................. WC8G
      CR(s)..................... 
      Description............... WEBLOGIC 12C REFERENCING SHARED EE LIBRARIES DOES NOT WORK
WEBLOGIC 12C REFERENCING SHARED EE LIBRARIES DOES NOT WORK
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13516712_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... weblogic/application/internal/library/EarLibraryDefinition.class
      
      Patch ID.................. B84Y
      CR(s)..................... 
      Description............... WSEE TESTS FAILING WITH SSL ISSUES ON JDK 7 (7U2)
WSEE TESTS FAILING WITH SSL ISSUES ON JDK 7 (7U2)
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13391585_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... weblogic/net/http/MessageHeader.class
      
      Patch ID.................. 8PE3
      CR(s)..................... 
      Description............... CAN'T DEPLOY APP WITH WEB SERVICE WHEN WEBLOGIC DOMAIN IS LOCATED ON THE NETWORK
CAN'T DEPLOY APP WITH WEB SERVICE WHEN WEBLOGIC DOMAIN IS LOCATED ON THE NETWORK
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13019800_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... weblogic/utils/zip/Handler.class
            File...................... weblogic/utils/zip/NullZipEntry.class
            File...................... weblogic/utils/zip/ZipFactory.class
            File...................... weblogic/utils/zip/ZipURLConnection.class
      
      Patch ID.................. H675
      CR(s)..................... 
      Description............... PSR:DEVX:WLS DEPLOYMENT REGRESSIONS IN 12.1.1
PSR:DEVX:WLS DEPLOYMENT REGRESSIONS IN 12.1.1
      Classpath
        Classpath type............ SYSTEM
        Classpath control jar..... weblogic_patch.jar
          Jar....................... BUG13340309_1211.jar
            File...................... META-INF/MANIFEST.MF
            File...................... com/oracle/pitchfork/server/Bootstrap.class
            File...................... com/oracle/pitchfork/server/ContainerBootstrap.class
            File...................... com/oracle/pitchfork/server/DefaultContainerBootstrap.class
            File...................... weblogic/application/internal/flow/EnvContextFlow$1.class
            File...................... weblogic/application/internal/flow/EnvContextFlow$AppEnvironmentBeanProvider.class
            File...................... weblogic/application/internal/flow/EnvContextFlow.class
            File...................... weblogic/application/naming/Environment$EnvType.class
            File...................... weblogic/application/naming/Environment$ResourceDescriptionData.class
            File...................... weblogic/application/naming/Environment.class
            File...................... weblogic/application/naming/EnvironmentBeanProvider.class
            File...................... weblogic/application/naming/EnvironmentBuilder$1.class
            File...................... weblogic/application/naming/EnvironmentBuilder.class
            File...................... weblogic/application/naming/EnvironmentBuilderManager$1.class
            File...................... weblogic/application/naming/EnvironmentBuilderManager.class
            File...................... weblogic/application/naming/EnvironmentException.class
            File...................... weblogic/application/naming/EnvUtils$1.class
            File...................... weblogic/application/naming/EnvUtils$InterfacesList.class
            File...................... weblogic/application/naming/EnvUtils.class
            File...................... weblogic/corba/rmic/StubGenerator.class
            File...................... weblogic/ejb/container/compliance/EJBObjectClassChecker.class
            File...................... weblogic/ejb/container/deployer/EJBDeployer$1.class
            File...................... weblogic/ejb/container/deployer/EJBDeployer$DeployedManagers.class
            File...................... weblogic/ejb/container/deployer/EJBDeployer$InjectionBasedEjbComponentContributorFactory.class
            File...................... weblogic/ejb/container/deployer/EJBDeployer.class
            File...................... weblogic/ejb/container/deployer/EJBModule$1.class
            File...................... weblogic/ejb/container/deployer/EJBModule.class
            File...................... weblogic/ejb/container/metadata/EjbDescriptorReaderImpl$NoCloseInputStream.class
            File...................... weblogic/ejb/container/metadata/EjbDescriptorReaderImpl$NonClosingClassFinder.class
            File...................... weblogic/ejb/container/metadata/EjbDescriptorReaderImpl.class
            File...................... weblogic/ejb/container/metadata/EjbJarLoader.class
            File...................... weblogic/ejb/container/metadata/WeblogicEjbJarLoader.class
            File...................... weblogic/ejb/container/persistence/InstalledPersistence.class
            File...................... weblogic/j2ee/managedbean/ManagedBeanModuleExtensionFactory.class
            File...................... weblogic/jndi/internal/ApplicationNamingNode$1.class
            File...................... weblogic/jndi/internal/ApplicationNamingNode$CacheInvalidationListener.class
            File...................... weblogic/jndi/internal/ApplicationNamingNode.class
            File...................... weblogic/jndi/internal/BasicNamingNode$1.class
            File...................... weblogic/jndi/internal/BasicNamingNode$2.class
            File...................... weblogic/jndi/internal/BasicNamingNode.class
            File...................... weblogic/jndi/internal/RootNamingNode.class
            File...................... weblogic/jndi/internal/ServerNamingNode.class
            File...................... weblogic/jndi/internal/WLNameParser.class
            File...................... weblogic/rmi/extensions/server/RMIDDParser.class
            File...................... weblogic/rmi/internal/BasicRuntimeDescriptor.class
            File...................... weblogic/rmi/internal/BasicServerRef$1.class
            File...................... weblogic/rmi/internal/BasicServerRef$ErrorReporter.class
            File...................... weblogic/rmi/internal/BasicServerRef$OIDManagerMaker.class
            File...................... weblogic/rmi/internal/BasicServerRef$UnreferencedExecuteRequest.class
            File...................... weblogic/rmi/internal/BasicServerRef.class
            File...................... weblogic/rmi/internal/DescriptorManager.class
            File...................... weblogic/rmi/internal/MethodDescriptor.class
            File...................... weblogic/servlet/provider/WlsJNDIProvider.class
            File...................... weblogic/utils/CharUtils.class
            File...................... weblogic/utils/classfile/AttributeTable.class
            File...................... weblogic/utils/classfile/Bytecodes.class
            File...................... weblogic/utils/classfile/ClassFile.class
            File...................... weblogic/utils/classfile/CodeAttribute$exception_struct.class
            File...................... weblogic/utils/classfile/CodeAttribute.class
            File...................... weblogic/utils/classfile/CodeGenHelper.class
            File...................... weblogic/utils/classfile/cp/ConstantPool.class
            File...................... weblogic/utils/classfile/expr/InvokeExpression.class
            File...................... weblogic/utils/classfile/expr/MemberVarExpression.class
            File...................... weblogic/utils/classfile/MethodInfo.class
            File...................... weblogic/utils/classfile/Scope$LocalVar.class
            File...................... weblogic/utils/classfile/Scope.class
            File...................... weblogic/utils/classfile/utils/CodeGenerator.class
            File...................... weblogic/utils/classloaders/CodeGenClassFinder.class
            File...................... weblogic/utils/classloaders/GenericClassLoader$1.class
            File...................... weblogic/utils/classloaders/GenericClassLoader$GetClassLoaderParentAction.class
            File...................... weblogic/utils/classloaders/GenericClassLoader.class
            File...................... weblogic/utils/compiler/CodeGenerator.class
            File...................... weblogic/utils/io/FilenameEncoder$UnsafeFilenameException.class
            File...................... weblogic/utils/io/FilenameEncoder.class
            File...................... weblogic/utils/StringUtils$1.class
            File...................... weblogic/utils/StringUtils$ReflectedStringMaker.class
            File...................... weblogic/utils/StringUtils$StringMaker.class
            File...................... weblogic/utils/StringUtils.class
            File...................... weblogic/validation/injection/ValidationManager$1.class
            File...................... weblogic/validation/injection/ValidationManager$ValidationBean.class
            File...................... weblogic/validation/injection/ValidationManager.class
            File...................... weblogic/work/ServerWorkManagerFactory.class
            File...................... weblogic/work/WorkManagerFactory.class
            File...................... weblogic/wsee/wsdl/internal/WsdlExtensibleImpl.class
            File...................... weblogic/wsee/wsdl/internal/WsdlSchemaImpl.class
            File...................... weblogic/xml/babel/baseparser/BaseParser.class
            File...................... weblogic/xml/babel/baseparser/CharDataElement.class
            File...................... weblogic/xml/babel/reader/XmlChars.class
            File...................... weblogic/xml/babel/scanner/CharData.class
            File...................... weblogic/xml/babel/scanner/CloseTag.class
            File...................... weblogic/xml/babel/scanner/IntegerQueue.class
            File...................... weblogic/xml/babel/scanner/Name.class
            File...................... weblogic/xml/babel/scanner/Scanner.class
            File...................... weblogic/xml/babel/scanner/ScannerState.class
  
  Product Description
  Product Name.............. Oracle Coherence
  Product Version........... 3.7.1.1
  Installed Components...... Coherence Product Files
  Product Install Directory. /opt/weblogic/coherence_3.7
  Java Home................. null
  Jave Vendor............... null
  Java Version.............. null
  Patch Directory........... /opt/weblogic/patch_ocp371
  
  Product Description
  Product Name.............. Oracle Enterprise Pack for Eclipse
  Product Version........... 1.0.1.20120312.0
  Installed Components...... Common Files
  Product Install Directory. /opt/weblogic/oepe_12.1.1.0.1
  Java Home................. /opt/weblogic/jdk160_29
  Jave Vendor............... Sun
  Java Version.............. 1.6.0_29
  Patch Directory........... /opt/weblogic/patch_oepe101
Paste your text here.

Saturday, February 23, 2013

Load application configuration using CDI on Weblogic 12c

Testing this solution on Weblogic 12c
http://weblogs.java.net/blog/jjviana/archive/2010/05/18/applicaction-configuration-java-ee-6-using-cdi-simple-example

Deployed EJB module requires beans.xml file on META-INF
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>


Annotation Config
package dave;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.inject.Qualifier;

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
public @interface Config {
 
}

Configuration factory
package dave;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;

public class ConfigurationFactory {

    private volatile static Properties configProperties;
    public static final String propertiesFilePath = "/application.properties";

    public synchronized static Properties getProperties() {

        if (configProperties == null) {
            configProperties = new Properties();
            try {
                InputStream is = ConfigurationFactory.class.getResourceAsStream(propertiesFilePath);
                System.out.println("Found resource file" + (is != null));
                configProperties.load(is);
            } catch (IOException ex) {
                Logger.getLogger(ConfigurationFactory.class.getName()).log(
                        Level.SEVERE, null, ex);
                throw new RuntimeException(ex);
            }

        }

        return configProperties;
    }

    public @Produces
    @Config
    String getConfiguration(InjectionPoint p) {

        String configKey = p.getMember().getDeclaringClass().getName() + "."
                + p.getMember().getName();
        Properties config = getProperties();
        if (config.getProperty(configKey) == null) {
            configKey = p.getMember().getDeclaringClass().getSimpleName() + "."
                    + p.getMember().getName();
            if (config.getProperty(configKey) == null)
                configKey = p.getMember().getName();
        }
        System.err.println("Config key= " + configKey + " value = "
                + config.getProperty(configKey));

        return config.getProperty(configKey);
    }

    public @Produces
    @Config
    Double getConfigurationDouble(InjectionPoint p) {

        String val = getConfiguration(p);
        return Double.parseDouble(val);

    }

}


Test Facade
package dave;

import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 * Session Bean implementation class TestFacade
 */
@Stateless(mappedName = "TestFacade")
public class TestFacade implements TestFacadeRemote {

    @EJB
    TestStateless stateless;

    public String getServerAddress() {
        return stateless.getServerAddress();
    }

}

Facade Remote interface
package dave;

import javax.ejb.Remote;

@Remote
public interface TestFacadeRemote {
    
    public String getServerAddress();

}


EJB client calling facade
Client requires  /opt/weblogic/wlserver_12.1/server/lib/wlthint3client.jar on CLASSPATH
package dave;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class TestEJBClient {

    /**
     * @param args
     */
    public static void main(String[] args) {
        
        try {
            Properties props = new Properties();
            props.put(Context.PROVIDER_URL, "t3://localhost:7001");
            props.put(Context.INITIAL_CONTEXT_FACTORY,
                    "weblogic.jndi.WLInitialContextFactory");
            Context ctx = new InitialContext(props);
            TestFacadeRemote facade = (TestFacadeRemote) ctx.lookup("TestFacade#dave.TestFacadeRemote");
            
            System.out.println(facade.getServerAddress());
            
        } catch (NamingException e) {
            e.printStackTrace();
        }

    }

}



Loading configuration value in application class
package dave;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Inject;

/**
 * Session Bean implementation class TestStateless
 */
@Stateless(mappedName = "TestStateless")
@LocalBean
public class TestStateless {

    @Inject @Config
    private String serverAddress;
    
    public String getServerAddress() {
        return serverAddress;
    }
    

}


Output in Weblogic server log
Found resource filetrue
Config key= serverAddress value = dave

Test with plain Java class
package dave;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;


@ApplicationScoped
public class TestBean {
    
    @Inject @Config
    private String serverAddress;
    
    public String getServerAddress() {
        return serverAddress;
    }

}

Added call to plain class
package dave;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;

/**
 * Session Bean implementation class TestFacade
 */
@Stateless(mappedName = "TestFacade")
public class TestFacade implements TestFacadeRemote {

    @EJB
    TestStateless stateless;
    
    @Inject
    TestBean testBean;

    public String getServerAddress() {
        
        System.out.println("get value from testbean " + testBean.getServerAddress());
        
        System.out.println("get value from testbean " + testBean.getServerAddress());
        
        System.out.println("get value from stateless " + stateless.getServerAddress());
        
        System.out.println("get value from stateless " + stateless.getServerAddress());
        
        return stateless.getServerAddress();
    }

}


Output in Weblogic log
Found resource filetrue
Config key= serverAddress value = dave
get value from testbean dave
get value from testbean dave
Config key= serverAddress value = dave
get value from stateless dave
get value from stateless dave



Exception when config file is not found
Exception in thread "main" javax.ejb.EJBTransactionRolledbackException: EJB Exception: 
    at weblogic.ejb.container.internal.BaseLocalObject.handleSystemException(BaseLocalObject.java:453)
    at weblogic.ejb.container.internal.BaseLocalObject.getBeanInstance(BaseLocalObject.java:166)
    at weblogic.ejb.container.internal.BaseLocalObject.preInvoke(BaseLocalObject.java:103)
    at weblogic.ejb.container.internal.BaseLocalObject.__WL_preInvoke(BaseLocalObject.java:67)
    at weblogic.ejb.container.internal.SessionLocalMethodInvoker.invoke(SessionLocalMethodInvoker.java:20)
    at dave.TestStateless_954dmo_NoIntfViewImpl.getServerAddress(Unknown Source)
    at dave.TestFacade.getServerAddress(TestFacade.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at com.oracle.pitchfork.intercept.MethodInvocationInvocationContext.proceed(MethodInvocationInvocationContext.java:103)
    at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.oracle.pitchfork.intercept.JeeInterceptorInterceptor.invoke(JeeInterceptorInterceptor.java:108)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(Unknown Source)
    at $Proxy111.getServerAddress(Unknown Source)
    at dave.TestFacade_23kp48_TestFacadeRemoteImpl.__WL_invoke(Unknown Source)
    at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:32)
    at dave.TestFacade_23kp48_TestFacadeRemoteImpl.getServerAddress(Unknown Source)
    at dave.TestFacade_23kp48_TestFacadeRemoteImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:695)
    at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:520)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:516)
    at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Properties.java:418)
    at java.util.Properties.load0(Properties.java:337)
    at java.util.Properties.load(Properties.java:325)
    at dave.ConfigurationFactory.getProperties(ConfigurationFactory.java:22)
    at dave.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264)
    at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52)
    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137)
    at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260)
    at org.jboss.weld.introspector.jlr.WeldMethodImpl.invokeOnInstance(WeldMethodImpl.java:170)
    at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstance(MethodInjectionPoint.java:137)
    at org.jboss.weld.bean.ProducerMethod$1.produce(ProducerMethod.java:132)
    at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:299)
    at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:61)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:630)
    at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:691)
    at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:118)
    at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:691)
    at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:700)
    at org.jboss.weld.bean.SessionBean$1$1.proceed(SessionBean.java:175)
    at com.oracle.injection.provider.weld.WeldInjectionServicesAdapter.aroundInject(WeldInjectionServicesAdapter.java:88)
    at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:45)
    at org.jboss.weld.bean.SessionBean$1.inject(SessionBean.java:172)
    at com.oracle.injection.provider.weld.WeldEjbBeanManager$ExtendedInjectionTarget.inject(WeldEjbBeanManager.java:119)
    at com.oracle.injection.provider.weld.WeldEjbBeanManager.newBeanInstance(WeldEjbBeanManager.java:82)
    at weblogic.ejb.container.injection.InjectionBasedEjbComponentCreator.getBean(InjectionBasedEjbComponentCreator.java:75)
    at weblogic.ejb.container.manager.BaseEJBManager.createNewBeanInstance(BaseEJBManager.java:209)
    at weblogic.ejb.container.manager.BaseEJBManager.allocateBean(BaseEJBManager.java:235)
    at weblogic.ejb.container.manager.StatelessManager.createBean(StatelessManager.java:293)
    at weblogic.ejb.container.pool.StatelessSessionPool.createBean(StatelessSessionPool.java:185)
    at weblogic.ejb.container.pool.StatelessSessionPool.getBean(StatelessSessionPool.java:114)
    at weblogic.ejb.container.manager.StatelessManager.preInvoke(StatelessManager.java:174)
    at weblogic.ejb.container.internal.BaseLocalObject.getBeanInstance(BaseLocalObject.java:146)
    ... 38 more

Monday, July 27, 2009

Dependency Injection (DI) and JNDI

EJB3 in action http://www.manning.com/panda/
Chapter 2.1.2 - Introducing dependency injection In a sense, injection is lookup reversed. As you can see, in the manual JNDI lookup model, the bean explicitly retrieves the resources and components it needs. As a result, component and resource names are hard-coded in the bean. With DI, on the other hand, the container reads target bean configuration, figures out what beans and resources the target bean needs, and injects them into the bean at runtime.

Inversion of Control Containers and the Dependency Injection pattern
http://www.martinfowler.com/articles/injection.html