Skip to content

Instantly share code, notes, and snippets.

@vunb
Created January 8, 2015 07:58
Show Gist options
  • Save vunb/9c68fc48e3c7302b40ae to your computer and use it in GitHub Desktop.
Save vunb/9c68fc48e3c7302b40ae to your computer and use it in GitHub Desktop.
Những lỗi gặp phải với Ejb
Properties props = new Properties();
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); // default!
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); // default!
InitialContext context = new InitialContext(props);
VendorFacadeRemote remote = (VendorFacadeRemote) context.lookup("java:global/ConfigDb-Ejb/VendorFacade");
1. Lỗi không đặt tên JNDI không theo chuẩn
SEVERE: Exception while preparing the app : Invalid resource : wnms_config_test__pm
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : wnms_config_test__pm
at org.glassfish.jdbcruntime.service.JdbcDataSource.validateResource(JdbcDataSource.java:81)
at org.glassfish.jdbcruntime.service.JdbcDataSource.setResourceInfo(JdbcDataSource.java:62)
Nguyên nhân: không đặt tên JNDI không theo chuẩn
Giải pháp: Sửa tên JNDI bắt đầu với jdbc/<database_name> trong cả hai file persistence.xml và WEB-INF/glassfish-resources.xml
2. Lỗi 2 đơn vị liên kết PU sử dụng cùng một Entity giống nhau.
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: javax.annotation.processing.FilerException: Attempt to recreate a file for type net.vnpttech.nms2.model.NewsEntity_
at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:407)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:625)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:554)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:699)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:981)
Giải pháp: Cập nhật lại đơn vị PU bằng cách thêm vào thuộc tính <exclude-unlisted-classes>true</exclude-unlisted-classes> hoặc củ chuối là xóa bớt 1 PU đi !
3. Không tồn tại ejb. Ejb jar yêu cầu ít nhất có 1 session/entity/message driven bean.
java.lang.IllegalArgumentException: Invalid ejb jar wtr-web-0.0.1-SNAPSHOT: it contains zero ejb. A valid ejb jar requires at least one session/entity/message driven bean.
at org.glassfish.ejb.deployment.util.EjbBundleValidator.accept(EjbBundleValidator.java:147)
at org.glassfish.ejb.deployment.util.EjbBundleValidator.accept(EjbBundleValidator.java:112)
at com.sun.enterprise.deployment.BundleDescriptor.visit(BundleDescriptor.java:621)
Giải pháp: Thêm vào annotation là @Remote vào cho một session bean hoặc singleton ejb @Singleton.
4. Không thể load được resouces khi thực hiện testing: Invalid resource : wnms_config_test__pm --->>>> Đã fix được :(
Ref1: https://blogs.oracle.com/brunoborges/entry/configure_datasources_for_maven_embedded
Ref2: http://stackoverflow.com/a/26897758/1896897
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : wnms_config_test__pm
at org.glassfish.jdbcruntime.service.JdbcDataSource.validateResource(JdbcDataSource.java:81)
at org.glassfish.jdbcruntime.service.JdbcDataSource.setResourceInfo(JdbcDataSource.java:62)
Nguyên nhân:
- Netbeans không tự động copy file ./src/main/setup/glassfish-resources.xml vào ./src/main/java/resources/META-INF/glassfish-resources.xml
- Đặt tên jndi-name trong persistence.xml không theo chuẩn: java:app/<jta-data-source-name>
Giải pháp: Bellow are a serie of steps for you to check
1 - Your pom.xml must have the path , plugin and dependencies configured for glassfish-embedded-static-shell, as follow:
Add in the properties at the top of your pom the path to your glassfish instalation folder(here is mine):
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<glassfish.embedded-static-shell.jar>C:/Program Files/glassfish-4.0/glassfish/lib/embedded/glassfish-embedded-static-shell.jar</glassfish.embedded-static-shell.jar>
</properties>
Add/check the plugin definition bellow(substitute mysql per maven in your case): `
<build>
...
<plugins>
...
<plugin>
<groupId>org.glassfish.embedded</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>4.0</version>
<dependencies>
<dependency>
<groupId>org.glassfish.main.common</groupId>
<artifactId>simple-glassfish-api</artifactId>
<version>4.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-static-shell</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${glassfish.embedded-static-shell.jar}</systemPath>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.28</version>
</dependency>
</dependencies>
<configuration>
<app>target/${project.artifactId}-${project.version}</app>
<port>8282</port>
<contextRoot>${project.artifactId}</contextRoot>
<foo>bar</foo>
</configuration>
</plugin>
...
</plugins>
...
</build>
`
2 - Your glassfish-resources... it's silly, but the jndi-name of your jdbc resource must have the prefix java:app/ so, add it as sample bellow(just the resource, the connection pool can have any name): *Just remembering the name of your jdbc-resource in glassfish will not have the prefix java:app, e.g.: my jdbc-resource in glassfish is just ShrewdPCPool
3 - Third and the silliest, when deploying the embedded glassfish, the auto generated script of Netbeans doen't include /src/main/resources/setup in the class path, so, the simple solution is to make a copy of your glassfish-resources.xml para /src/main/resources/META-INF/ or if you are patient enough change the script.
Dont forget to clean, and after build with dependencies before you run your tests!
5. Chứng chỉ hết hạn của Glassfish Server 4.0 trong file: cacerts.jks
Ref: http://www.adam-bien.com/roller/abien/entry/how_to_fix_expired_certificate
http://stuetzpunkt.wordpress.com/2013/08/28/glassfish-4-error-severe-sec5054-certificate-has-expired/
Error Message: SEVERE: SEC5054: Certificate has expired: [
[
Version: V3
Subject: CN=GTE CyberTrust Root 5, OU="GTE CyberTrust Solutions, Inc.", O=GTE Corporation, C=US
Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5
Key: Sun RSA public key, 2048 bits
Giải pháp: Remove the key from the CA-file
Thường file cacerts.jks đặt trong thư mục: [GLASSFISH_HOME]/glassfish4/glassfish/domains/[DOMAIN_NAME]/config
Để loại bỏ thông báo lỗi khi khởi động Glassfish Server 4.0 hoặc khi thực hiện test dự án, hãy xóa chứng chỉ bằng lệnh sau:
Command: keytool -delete -keystore ./cacerts.jks -alias gtecybertrust5ca
Password: changeit
Sau đó hãy copy file cacerts.jks vừa thay đổi vào thư mục dự án: scr/test/resources/config
Nếu mong muốn sử dụng file cacerts.jks này khi deploy thì hãy copy vào thư mục: src/main/resources/config
6. JUnit Tests on an Embedded Glassfish 4 using CDI end up with an endless loop of the following output: WARNING: AS-CDI-005 Okt 22, 2013 4:49:23 PM org.glassfish.weld.BeanDeploymentArchiveImpl handleEntry
Giải pháp: What worked for me is putting your app name in the properties when creating the EJB container
Map<Object, Object> properties = new HashMap<Object, Object>();
properties.put(EJBContainer.APP_NAME, "your_app_name");
EJBContainer ejbContainer = EJBContainer.createEJBContainer(properties);
7. org.glassfish.deployment.common.DeploymentException: Failue while processing glassfish-resources.xml(s) in the archive -- Resource [ java:app/nms_config ] is not allowed to specify the scope [ java:app/ ]. Acceptable scope for this resource is [ java:module/ ]
Nguyên nhân: Do định nghĩa phạm vi sử dụng resource trong phiên bản Glassfish 3, 4
Giải pháp: ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment