access a #SessionScoped bean from #WebService annotated EJB - soap

One of my partners needs a SOAP interface and so I thought: lets move to an Application server. I chose Glassfish and it works great out of the box. There is just one thing I can not make it do: inject a #SessionScoped ManagedBean into the #Webservice annotated EJB.
The only way I can acces the EJB is over JNDI. I read about it here
My question is: is there a bug in Glassfish and it will work in a future version or should it work and I did something wrong.
I would like to be able to inject the property DataAccess session with the #EJB annotation but it does not work.
Below are all the files in the test project
Here is my WebService class:
#LocalBean
#Stateless
#WebService()
public class MySOAP implements Serializable {
private DataAccess session;
#WebMethod
public String getUsername() {
javax.naming.Context ctx = null;
try {
ctx = new javax.naming.InitialContext();
session = ( DataAccess ) ctx.lookup( "java:comp/env/DataAccess" );
return "user is " + session.getData();
} catch ( NamingException e ) {
e.printStackTrace();
}
return "exception occured";
}
}
The EJB I would like to inject:
public abstract class AbstractDataBean {
#Inject /* this just returns some text*/
private MySessionBean session;
public MySessionBean getSession() {
return session;
}
}
#LocalBean
#Stateless
public class DataAccess extends AbstractDataBean implements Serializable {
public String getData() {
return " data " + getSession();
}
#Override
public String toString() {
return getData();
}
}
#Named
#SessionScoped
public class MySessionBean implements Serializable {
static private int classCounter = 0;
private String user;
#PostConstruct
public void initMySessionBean( ) {
user = "Micha " + (++classCounter) ; //to check how many times it was called
}
public String getUser() {
return user;
}
public void setUser( String user ) {
this.user = user;
}
#Override
public String toString() {
return user;
}
}
I have a web.xml to define the JNDI:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="3.0">
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<ejb-local-ref>
<ejb-ref-name>DataAccess</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>ch.sertal.server.services.ejb.DataAccess</local>
</ejb-local-ref>
</web-app>
a sun-jaxws.xml to define the SOAP WebService:
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
<endpoint
name='Mysoap'
implementation='ch.sertal.server.services.MySOAP'
url-pattern='/soap/Mysoap '/>
</endpoints>
and an empty beans.xml in order to have CDI functioning:
<?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>
and finally the pom.xml It is very long because I copied it from the existing project. But there should be nothing missing.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.sertal</groupId>
<artifactId>VisionWeb</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>VisionWeb Jersey Webapp</name>
<build>
<finalName>VisionWeb</finalName>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>*.xml</include>
</includes>
</resource>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<targetPath>.</targetPath>
<includes>
<include>*.properties</include>
</includes>
</resource>
<resource>
<filtering>true</filtering>
<directory>src/main/resources/i18n</directory>
<targetPath>.</targetPath>
<includes>
<include>*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.1</version>
<configuration>
<glassfishDirectory>/Development/glassfish3</glassfishDirectory>
<user>admin</user>
<adminPassword>U36c9AqVf5Ppk4DX</adminPassword>
<autoCreate>true</autoCreate>
<debug>true</debug>
<echo>false</echo>
<terse>true</terse>
<skip>false</skip>
<domain>
<host>${glassfish.host}</host>>
<name>domain1</name>
<adminPort>4848</adminPort>
<httpPort>9080</httpPort>
<httpsPort>8181</httpsPort>
<iiopPort>3700</iiopPort>
<jmsPort>7676</jmsPort>
</domain>
<components>
<component>
<name>VisionWeb</name>
<artifact>${project.build.directory}/${project.build.finalName}.war</artifact>
</component>
</components>
</configuration>
</plugin>
<!--surefire-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<parallel>test</parallel>
<threadCount>1</threadCount>
<groups>${test.groups}</groups>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-api</artifactId>
<version>1.1.Final</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
<!--jersey for RESTful services-->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey-version}</version>
</dependency>
<!--GlassFish libraries-->
<dependency>
<groupId>org.glassfish.distributions</groupId>
<artifactId>web-all</artifactId>
<version>10.0-build-20080430</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.embedded</groupId>
<artifactId>gf-embedded-api</artifactId>
<version>1.0-alpha-4</version>
<scope>test</scope>
</dependency>
<!--peristence & database-->
<!-- hsqldb -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.6</version>
</dependency>
<!-- persistence -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>${eclipselink.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>${eclipselink.jpa.version}</version>
<scope>compile</scope>
</dependency>
<!--SHIRO Authentication-->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>1.1.0</version>
</dependency>
<!--POI components-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.7</version>
</dependency>
<!--PDF Box-->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.6.0</version>
</dependency>
<!--XML processing-->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<!--testing-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<!--properties-->
<properties>
<jersey-version>1.8</jersey-version>
<jpa.unit>hsqldb.server</jpa.unit>
<test.jpa.unit>hsqldb.testr</test.jpa.unit>
<eclipselink.version>2.3.0</eclipselink.version>
<eclipselink.jpa.version>2.0.3</eclipselink.jpa.version>
</properties>
<!--profiles-->
<profiles>
<profile>
<id>mode.alpha.dev</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>environment</name>
<value>server</value>
</property>
</activation>
<properties>
<delete.files>true</delete.files>
<log.level>FINER</log.level>
<jersey.log.level>WARNING</jersey.log.level>
<jpa.log.level>INFO</jpa.log.level>
<test.groups>server-tests</test.groups>
<db.server.name>localhost</db.server.name>
<img-basedir>/opt/sertal/data</img-basedir>
<!--the url for tomcat 7 has changed. this is why /html has been appended to the below URL-->
<tomcat.manager>http://dev.sertal.net:7070/manager/html</tomcat.manager>
<tomcat.username>sertaladmin</tomcat.username>
<tomcat.password>29VeK0Ul</tomcat.password>
<tomcat.context>/VisionWeb</tomcat.context>
<test.groups>none</test.groups>
<!-- the date at the end marks the version of the data model -->
<hsqldb.data.path>/opt/sertal/data/hsqldb-dev-20110813</hsqldb.data.path>
</properties>
</profile>
</profiles>
<!--repositories and plugin repos-->
<repositories>
<!--glass fish-->
<repository>
<id>glassfish.java.net</id>
<name>GlassFish Maven Repository</name>
<url>http://download.java.net/maven/glassfish</url>
<layout>default</layout>
</repository>
<repository>
<id>m2.java.net</id>
<name>Java.net Maven 2 Repository</name>
<url>http://download.java.net/maven/2</url>
<layout>default</layout>
</repository>
<!--eclipse link-->
<repository>
<id>eclipselink.repo</id>
<name>eclipselink maven repository</name>
<url>http://download.eclipse.org/rt/eclipselink/maven.repo</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>m2.java.net</id>
<name>Java.net Maven 2 Repository</name>
<url>http://download.java.net/maven/2</url>
<layout>default</layout>
</pluginRepository>
<pluginRepository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Spare yourself the advice, I will not switch to JBoss :-)

The Session Scope isn't active for web derives per section 6.7.2 of JSR 299, it's not a bug. If you think about it, there isn't much point as the session doesn't really follow from one web service request to the next.
Also, you said you won't switch to JBoss, out of curiosity, what are your reasons?

Related

setting arquillian on Wildfly Preview 25: NoClassDefFoundError: org/jboss/threads/AsyncFuture

I am trying to run this test on Arquillian:
#ExtendWith(ArquillianExtension.class)
class ArquillianTest {
#Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class, "arquillian-test.war");
}
#Test
void execTest() {
fail("Always fails");
}
}
but it gets ignored and the whole execution just fails with:
INFO: JBoss Threads version 3.1.0.Final
Test ignored.
java.lang.NoClassDefFoundError: org/jboss/threads/AsyncFuture
at org.jboss.as.controller.client.ModelControllerClient$Factory.create(ModelControllerClient.java:609)
at org.jboss.as.arquillian.container.CommonDeployableContainer.start(CommonDeployableContainer.java:121)
at org.jboss.arquillian.container.impl.ContainerImpl.start(ContainerImpl.java:179)
I do not think I am missing anything in my deployment method, since there are no classes involved in this simple test, but I am new to Arquillian.
I found a bug report of the same error, but it was in 2014 and apparently resolved: https://lists.jboss.org/pipermail/jboss-jira/2014-April/256446.html
This is my pom.xml (relevant parts):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.7.0.Alpha10</version>
<type>pom</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<version>1.7.0.Alpha10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet-jakarta</artifactId>
<version>1.7.0.Alpha10</version>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>5.0.0.Alpha2</version>
<scope>test</scope>
</dependency>
and this is my arquillian.xml:
<arquillian
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<defaultProtocol type="Servlet 5.0"/>
<container qualifier="wildfly" default="true">
<configuration>
<property name="jbossHome">C:\Users\sotan\Software\wildfly-preview-25.0.1.Final</property>
<property name="javaVmArguments">-Djboss.socket.binding.port-offset=100</property>
<property name="managementPort">10090</property>
</configuration>
</container>
</arquillian>

Compile time weaving in Spring Application not working properly

I am working on compile team weaving using AspectJ as Load time Weaving for the same is causing extra overhead on server startup.so the issue is at compile all the classes is being weaved. However when running application on server it is never coming to any of the Aspect class.
So as I have some classes that are using lombok so I have done like this and added compile time maven plugin
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>com.x.rgx</groupId>
<artifactId>web</artifactId>
<version>10.0</version>
<packaging>war</packaging>
<properties>
<runSuite>**/AllTests.class</runSuite>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring-framework.version>5.0.4.RELEASE</spring-framework.version>
<lombok.version>1.18.2</lombok.version>
<aspectj.version>1.8.13</aspectj.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring-framework.version}</version>
</dependency>
<dependencies>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<compilerArguments>
<d>${project.build.directory}/classes</d>
</compilerArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.11</version>
<dependencies>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${aspectj.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<configuration>
<complianceLevel>${maven.compiler.target}</complianceLevel>
<source>${maven.compiler.target}</source>
<target>${maven.compiler.target}</target>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<Xlint>ignore</Xlint>
<encoding>${project.build.sourceEncoding}</encoding>
<forceAjcCompile>true</forceAjcCompile>
<sources />
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<include>${runSuite}</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.x.aspect.config;
#Configuration
#ComponentScan(basePackages = { "com.x" })
public class AspectConfig {
}
package com.x.login;
#Component
#Scope("session")
public class LoginMBean extends AbstractMbean {
#Autowired
LoginService loginService ;
public void loginUserData(){
LoginInfo info= new LoginInfo();
//setter for info object
//some nested method calls
loginService.insertLoginData(info);
}
}
package com.x.aspects;
#Component
#Aspect
public class Aspects {
private static Logger Logger= LoggerFactory.getLogger(Aspects.class);
#Pointcut("execution(* *(..)) && cflow(execution(* com.x.login..*(..)))")
public void methodsToBeProfiled() {}
#Around("methodsToBeProfiled()")
public Object methodsToBeProfiled(ProceedingJoinPoint point) throws Throwable {
StopWatch sw = new StopWatch(getClass().getSimpleName());
try {
sw.start(point.getSignature().getName());
return point.proceed();
} finally {
sw.stop();
Logger.info("Elapsed Time, Package Name, Method Name");
Logger.info(sw.prettyPrint());
Logger.info("Package Name: " + point.getStaticPart());
}
}
}
[INFO] Join point 'method-execution(java.lang.String com.x.login.LoginMBean.getArisgPersistenceUnitName(java.lang.String))' in Type 'com.x.login.LoginMBean' (LoginMBean.java:258) advised by around advice from 'com.x.aspects.Aspects' (Aspects.class(from Aspects.java)) [with runtime test]
[INFO] Join point 'method-execution(java.lang.String com.x.login.LoginMBean.getMultiDb())' in Type 'com.x.login.LoginMBean' (LoginMBean.java:269) advised by around advice from 'com.x.aspects.Aspects' (Aspects.class(from Aspects.java)) [with runtime test]
[INFO] Join point 'method-execution(void com.x.login.LoginMBean.setMultiDb(java.lang.String))' in Type 'com.x.login.LoginMBean' (LoginMBean.java:273) advised by around advice from 'com.x.aspects.Aspects' (Aspects.class(from Aspects.java)) [with runtime test]
[INFO] Join point 'method-execution(boolean com.x.login.LoginMBean.isDbListStatus())' in Type 'com.x.login.LoginMBean' (LoginMBean.java:277) advised by around advice from 'com.x.aspects.Aspects' (Aspects.class(from Aspects.java)) [with runtime test]
So now as in the compile time it has weaved all the classes. But at the runtime it not coming to Aspects.java. Anything else i need to add up for configuration.? Do i need configuration added in spring-config.xml?
List item
It has worked by changing Pointcut to:
#Pointcut("execution(* *(..)) && cflow(execution(* com.x.login.LoginMBean.*(..)))")

itext java.lang.NoClassDefFoundError: DefaultAccessibilityProperties

I don't understand why I get an exception in this very basic test of iText :
package com.itextpdf.testpdf4;
import com.itextpdf.io.font.FontConstants;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.List;
import com.itextpdf.layout.element.ListItem;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.text.DocumentException;
import com.itextpdf.licensekey.LicenseKey;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.File;
import java.io.IOException;
#WrapToTest
public class HelloWorld {
public static final String DEST = "result/hello.pdf";
public static void main(String[] args)
throws DocumentException, IOException {
LicenseKey.loadLicenseFile("C:\\dev\\testPDF4\\src\\main\\java\\com\\itextpdf\\testpdf4\\itextkey1544447451310_0.xml");
File file = new File(DEST);
file.getParentFile().mkdirs();
new HelloWorld().createPdf(DEST);
}
public void createPdf(String dest) throws DocumentException, IOException {
PdfWriter writer = new PdfWriter(dest);
//Initialize PDF document
PdfDocument pdf = new PdfDocument(writer);
// Initialize document
Document document = new Document(pdf);
// Create a PdfFont
PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
// Add a Paragraph
document.add(new Paragraph("iText is:").setFont(font));
// Create a List
List list = new List()
.setSymbolIndent(12)
.setListSymbol("\u2022")
.setFont(font);
// Add ListItem objects
list.add(new ListItem("Never gonna give you up"))
.add(new ListItem("Never gonna let you down"))
.add(new ListItem("Never gonna run around and desert you"))
.add(new ListItem("Never gonna make you cry"))
.add(new ListItem("Never gonna say goodbye"))
.add(new ListItem("Never gonna tell a lie and hurt you"));
// Add the list
document.add(list);
//Close document
document.close();
}
}
Exception in thread "main" java.lang.NoClassDefFoundError:
com/itextpdf/kernel/pdf/tagutils/DefaultAccessibilityProperties at
com.itextpdf.testpdf4.HelloWorld.createPdf(HelloWorld.java:56)
(line 56 is : document.add(new Paragraph("iText is:").setFont(font)); )
This code comes from here: https://developers.itextpdf.com/fr/content/itext-7-jump-start-tutorial/examples/chapter-1 -> C01E02_RickAstley.java
In the POM.XML :
<modelVersion>4.0.0</modelVersion>
<groupId>com.itextpdf</groupId>
<artifactId>testPDF4</artifactId>
<version>1.0</version>
(package is : package com.itextpdf.testpdf4;)
Here is the complete POM.XML :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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>com.itextpdf</groupId>
<artifactId>testPDF4</artifactId>
<version>1.0</version>
<properties>
<itext.version>7.1.4</itext.version>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<junit.version>4.12</junit.version>
</properties>
<repositories>
<repository>
<id>itext</id>
<name>iText Repository - releases</name>
<url>https://repo.itextsupport.com/releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>7.1.4</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>forms</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdfa</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdftest</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.18</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-licensekey</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-sandbox-parent</artifactId>
<version>2</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.p12</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<excludePackageNames>com.itextpdf.xml</excludePackageNames>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>external.atlassian.jgitflow</groupId>
<artifactId>jgitflow-maven-plugin</artifactId>
<version>1.0-m5.1</version>
<configuration>
<!-- see goals wiki page for configuration options -->
<flowInitContext>
<masterBranchName>master</masterBranchName>
<developBranchName>develop</developBranchName>
<featureBranchPrefix>feature/</featureBranchPrefix>
<releaseBranchPrefix>release/</releaseBranchPrefix>
<hotfixBranchPrefix>hotfix/</hotfixBranchPrefix>
<versionTagPrefix />
</flowInitContext>
<allowUntracked>true</allowUntracked>
<autoVersionSubmodules>true</autoVersionSubmodules>
<updateDependencies>true</updateDependencies>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>public</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<excludes>
<exclude>com/itextpdf/xml/**</exclude>
<exclude>**/*.p12</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>internal</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<excludes>
<exclude>**/*.p12</exclude>
</excludes>
<classifier>INTERNAL</classifier>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Does anyone see something wrong ? I don't
Thanks
You're mixing different core itext artifact versions, 7.0.4 and 7.1.4.
...
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>7.1.4</version>
<type>jar</type>
</dependency>
...
Don't mix these. Use the same version of all your core itext artifacts.
By the way, you put your test project into the itext group:
<groupId>com.itextpdf</groupId>
<artifactId>testPDF4</artifactId>
You shouldn't do that, in particular not with production use projects.
Thanks a lot mkl ;
Bad group IP, Bad versions, and a wrong nbaction.xml

Fuse Error deploying bundle IndexOutOfBoundsException

I am new to FUSE. I am trying to start a simple REST service.
I am using Jboss Fuse 6.3.
The bundle installs but i cannot start it without the error.
After installing the bundle, it appears as "Active", but with the tag "Failure".
The log prints the following error:
12:29:17,046 | ERROR | Thread-53 | BlueprintContainerImpl | 23 - org.apache.aries.blueprint.core - 1.4.5 | Unable to start blueprint container for bundle null/0.0.0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)[:1.8.0_151]
at java.util.ArrayList.get(Unknown Source)[:1.8.0_151]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.readDirectives(BlueprintContainerImpl.java:214)
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:296)
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:270)
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:294)
at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:263)
This is my code:
Picture of project structure
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>org.fusesource.example</groupId>
<artifactId>rest-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>rest-service</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix.specs</groupId>
<artifactId>org.apache.servicemix.specs.jsr311-api-1.1.1</artifactId>
<version>1.9.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-http</artifactId>
<version>2013.01</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.6</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>* </Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Blueprint.xml:
<?xml version = "1.0" encoding = "UTF-8"?>
<blueprint xmlns = "http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs = "http://cxf.apache.org/blueprint/jaxrs"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xsi:schemaLocation = "http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd">
<jaxrs:server id="servicios" address="/serviciosPrueba">
<jaxrs:serviceBeans>
<ref component-id="miServicio" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="miServicio" class="com.rest.Servicio" />
</blueprint>
Java:
package com.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/servicioPrueba")
public class Servicio {
#GET
#Path("/getData")
#Produces(MediaType.APPLICATION_JSON)
public String getUser() {
String reponse = "This is standard response from REST";
return reponse;
}
}
Thank you very much.
In pom.xml
Please change
<packaging>jar</packaging>
to
<packaging>bundle</packaging>
otherwise it will miss the necessary OSGi headers
I resolved the second error adding specific versions of dependencies in pom.xml:
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>
javax.ws.rs;version="[2.0,3)",
javax.ws.rs.core;version="[2.0,3)",
*
</Import-Package>
</instructions>
</configuration>

spring-rest-docs application is not generating snippets when run or integration tested

My test class is
package com.htc.spring.rest.docs;
-------
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes=CrudRestDemoApplication.class)
#WebAppConfiguration
#IntegrationTest
public class ForRestDocumentationTest {
#Rule
public JUnitRestDocumentation restDoc = new
JUnitRestDocumentation("target/generated-snippets");
private final ObjectMapper objectMapper = new ObjectMapper();
#Autowired
public EmbeddedWebApplicationContext context;//or WebApplicationContext
private MockMvc mockMvc;
public ForRestDocumentationTest(){
System.out.println("Test class created");
}
#Before
public void setup(){
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDoc)).alwaysDo(document("
{method-name}/{step}/")).build();
}
#Test
public void addOrder() throws Exception {
GregorianCalendar calendar = new
GregorianCalendar(2015,Calendar.MARCH,21);
OrderTO newOrder =
new OrderTO(8000, calendar.getTime(), "M/s Joseph Sales", 2120.5);
this.mockMvc.perform(post("/orders")
.accept(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(newOrder))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("index"));
}
#Test
public void getOrder() throws Exception {
System.out.println("get order fired");
int orderId = 2000;
this.mockMvc.perform(get("/orders/{orderId}", orderId)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("orderId").isNotEmpty())
.andExpect(jsonPath("orderDate").isNotEmpty())
.andExpect(jsonPath("customer").isNotEmpty())
.andExpect(jsonPath("cost").isNotEmpty())
.andDo(document("index"));
}
#Test
public void getAllOrders() throws Exception {
this.mockMvc.perform(get("/orders")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$").isArray())
.andExpect(jsonPath("[*].orderId").isNotEmpty())
.andExpect(jsonPath("[*].orderDate").isNotEmpty())
.andExpect(jsonPath("[*].custoer").isNotEmpty())
.andExpect(jsonPath("[*].cost").isNotEmpty())
.andDo(document("index"));
}
private static final String ORDERS_ORDERID_DESCRIPTION =
"OrderTO's OrderId";
private static final String ORDERS_ORDER_DATE_DESCRIPTION =
"OrderTO's Order Date";
private static final String ORDERS_CUSTOMER_DESCRIPTION =
"OrderTO's Customer";
private static final String ORDERS_COST_DESCRIPTION =
"OrderTO's Cost";
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
---------
<groupId>sprRestDocs</groupId>
<artifactId>sprRestDocs</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>sprRestDocs</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath/>
</parent>
<properties>
<java.version>1.8</java.version>
<springframework.version>4.3.0.RELEASE
</springframework.version>
<jackson.library>2.8.0</jackson.library>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<snippetsDirectory>target/generated-snippets
</snippetsDirectory>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.library}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.library}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.library}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.library}</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<version>1.1.0.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-core</artifactId>
<version>1.1.0.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>sprRestDocs</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>sprRestDocs</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
<attributes>
<snippets>${snippetsDirectory}</snippets>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring snapshots</name>
<url>https://repo.spring.io/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
If I use mvn spring-boot:run no documentation is generating.
If I use mvn integration-test I get api-guide.adoc [html file] but no snippets
If I try to run
mvn -Dtest=com.htc.spring.rest.docs.ForRestDocumentationTest test
I get this error:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.htc.spring.rest.docs.ForRestDocumentationTest
17:33:12.463 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.htc.spring.rest.docs.ForRestDocumentationTest]
17:33:12.463 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
17:33:12.479 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.383 sec <<< FAILURE! - in com.htc.spring.rest.docs.ForRestDocumentationTest
initializationError(com.htc.spring.rest.docs.ForRestDocumentationTest) Time elapsed: 0 sec <<< ERROR!
java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify #BootstrapWith's 'value' attribute or make the default bootstrapper class available.
Caused by: java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.findAllMergedAnnotations(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/util/Set;
Hi I was facing the same issue myself, I found a solution so the snippet are being created, by changing from
<phase>prepare-package</phase>
to
<phase>generate-resources</phase>
but still facing an issue that snippet are getting created after html is getting generated, which is why it's not included as part of html.
Though I am still looking into that part, for now there is a temporary solution to this, first I execute mvn clean test
then once snippet get generated
again execute mvn test and proper html doc get's generated.
This not a clean solution, and I am still looking for a better solution to this issue, but it's getting the job done for now.