I want to create a full WebArchive for running Arquillian Tests using the new ShrinkWrap Feature MavenImporter (https://github.com/shrinkwrap/resolver).
The Scenario:
Arquillian should be integrated/extended with SoapUi to test a Spring application. There are n Endpoints exposed by the Spring application and implemented with cxf.
The test method looks like this:
/*
* Source folder for SoapUi project files
*/
#Value("${soapui.workspace}")
private String soapUiWorkspace;
/*
* Output directory for test reports
*/
#Value("${soapUi.reports.dir}")
private String reportsOutpuDirectory;
/*
* Comma separated list of SoapUi projects to be tested
*/
#Value("${soapUi.projects}")
private String[] projects;
/*
* URL resource provided by Arquillian runtime
*/
#ArquillianResource
private URL serverUrl;
#Test
public void testServiceEndpoints() throws Exception {
final SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
for (String project : projects) {
runner.setProjectFile(String.format("%s%s%s", soapUiWorkspace, "/", project));
runner.setHost(String.format("%s:%s", serverUrl.getHost(), serverUrl.getPort()));
runner.setOutputFolder(reportsOutpuDirectory);
LOG.info("SoapUi-Call for " + runner.getHost());
runner.setJUnitReport(true);
runner.setPrintReport(true);
runner.run();
}
}
My #Deployment-Method looks like this:
#Deployment
public static Archive<?> createDeployment() {
return ShrinkWrap.create(MavenImporter.class).loadPomFromFile("pom.xml").importBuildOutput().as(WebArchive.class);
}
I'm getting right now this Exception:
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.Archive com.bosch.mome.ws.facade.common.soapui.MarketTransparencyServiceEndpointsSoapUiTest.createDeployment()
at org.jboss.shrinkwrap.api.UnknownExtensionTypeException.newInstance(UnknownExtensionTypeException.java:68)
at org.jboss.shrinkwrap.api.UnknownExtensionTypeExceptionDelegator.newExceptionInstance(UnknownExtensionTypeExceptionDelegator.java:37)
at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.findExtensionImpl(ServiceExtensionLoader.java:279)
at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.loadExtensionMapping(ServiceExtensionLoader.java:246)
at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.createFromLoadExtension(ServiceExtensionLoader.java:212)
at org.jboss.shrinkwrap.impl.base.ServiceExtensionLoader.load(ServiceExtensionLoader.java:108)
at org.jboss.shrinkwrap.impl.base.ArchiveBase.as(ArchiveBase.java:662)
at org.jboss.shrinkwrap.api.ArchiveFactory.create(ArchiveFactory.java:150)
at org.jboss.shrinkwrap.api.ShrinkWrap.create(ShrinkWrap.java:163)
at com.bosch.mome.ws.facade.common.soapui.MarketTransparencyServiceEndpointsSoapUiTest.createDeployment(MarketTransparencyServiceEndpointsSoapUiTest.java:82)
Jan 19, 2015 6:29:46 PM org.apache.coyote.http11.Http11Protocol destroy
INFO: Stopping Coyote HTTP/1.1 on http-127.0.0.1-8888
I'm not adding the Assets separately because I'm integrating currently the junit SoapUi library and Arquillian for testing Endpoints and need to load the full Application/WebArchive.
I was looking to the ShrinkWrap javadoc but could not find a working solution/fix.
In the javadoc I read the following:
UnknownExtensionTypeException: Indicates that a default name cannot be generated for a given type because no extension mapping has been configured via ExtensionLoader.getExtensionFromExtensionMapping(Class)
But I don't know where I can exactly configure the Extension mapping. There is no tutorial or samples. Or may be I could not find them.
Does anybody have Experience with this new ShrinkWrap Feature?
I know it has been some time but maybe somebody finds it helpfull anyways.
I had the same problem and the cause was that i was to greedy in my pom.xml. I had the following dependencies:
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api-maven</artifactId>
<version>${version.shrinkwrap.resolvers}</version>
<scope>test</scope>
</dependency>
Turns out the error just disappears if you use the BOM and the depchain somewhat like this:
<dependencyManagement>
<dependencies>
...
<!-- Override dependency resolver with latest version.
This must go *BEFORE* the Arquillian BOM. -->
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>${version.shrinkwrap.resolvers}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.11.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
...
</dependencies>
</dependencyManagement>
<dependencies>
...
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<version>${version.shrinkwrap.resolvers}</version>
<scope>test</scope>
<type>pom</type>
</dependency>
...
<!-- your container goes here, too (for me it was arquillian-tomee-embedded) -->
</dependencies>
Also check out the documentation: https://github.com/shrinkwrap/resolver/blob/master/README.asciidoc
Related
I'll start off by saying I've looked at and tried the solutions in every question regarding this that I can find. The biggest problem is that most of these solutions are very old, and Spring Boot has changed a lot in the last several years. To be clear, I've tried this, this, this, this, and more. I've also read numerous tutorials. Nothing works.
I have a brand new Spring Boot application and I'm trying to get JSP rendering working with it. These are my dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>[2.3.4.RELEASE,3)</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>[2.3.4.RELEASE,3)</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>[2.3.4.RELEASE,3)</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>[2.8.0,3)</version>
</dependency>
<dependency>
<groupId>de.mkammerer</groupId>
<artifactId>argon2-jvm</artifactId>
<version>[2.7,3)</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>[8.0.21,9)</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>[2.3.2,)</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>[2.3.4.RELEASE,3)</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>[9.0.38,)</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>[2.3.4.RELEASE,3)</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
My project is laid out as follows:
- source
- production
- java
- [my source code packages]
- resources
- WEB-APP
- jsp
- initialization
- begin.jsp
- [my resource packages]
- test
- java
- resources
"WEB-APP/jsp" is just the latest iteration I've tried. I've tried "WEB-INF/jsp", "META-INF/jsp", "webapp/jsp", no parent (just "jsp"), etc., all with the same results.
I know the parent directories are a bit non-standard, but it's configured correctly in Maven and I've confirmed it's not the source of my problems:
<build>
<sourceDirectory>source/production/java</sourceDirectory>
<resources>
<resource>
<directory>source/production/resources</directory>
</resource>
</resources>
...
</build>
My Application class is as follows:
#SpringBootApplication(scanBasePackages="com.my.project")
#EnableWebMvc
#EnableJpaRepositories("com.my.project.repository")
#EntityScan("com.my.project.model")
public class Application
{
private static final Logger LOGGER = LogManager.getLogger(Application.class);
public Application()
{
}
#Bean
public ViewResolver viewResolver()
{
LOGGER.info("Constructing InternalResourceViewResolver[JstlView]");
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-APP/jsp/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
resolver.setRedirectContextRelative(true);
resolver.setRedirectHttp10Compatible(false);
return resolver;
}
public static void main(final String[] args)
{
SpringApplication.run(Application.class, args);
}
}
And my Controller:
#Controller
public class InitializationController
{
private static final Logger LOGGER = LogManager.getLogger(InitializationController.class);
#GetMapping("/initialize_application")
public String beginInitialization(ModelMap model)
{
LOGGER.info("Beginning initialization");
...
LOGGER.info("Returning view");
return "initialization/begin";
}
...
}
On startup I see the "Constructing InternalResourceViewResolver" log entry (my view resolver bean is created). When I go to /initialize_application, I get the following error:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Oct 18 21:45:26 CDT 2020
There was an unexpected error (type=Not Found, status=404).
Looking in the log again, I see "Beginning initialization" and "Returning view," so I know that the 404 is for my JSP and not my controller. My controller is working.
Other things I've tried:
Initially I did not have #EnableWebMvc on my application. Without it, the log was empty except my log statements. When I added #EnableWebMvc, this is now logged with the 404: No mapping for GET /WEB-APP/jsp/initialization/begin.jsp (or whatever other directory I've tried other than "WEB-APP").
I've tried running this directly on the pure command line with mvn spring-boot:run
I've tried running this in IntelliJ IDEA with a Maven run configuration and command spring-boot:run (same result)
I've tried both <packaging>jar</packaging> and <packaging>war</packaging>, but neither make a difference, because neither a JAR nor a WAR are ever made. Maven runs the application directly out of the target/classes directory instead of creating an artifact.
When I've tried WEB-INF or META-INF instead of WEB-APP or webapp or something else, I've seen a logged warning: Path with "WEB-INF" or "META-INF": [WEB-INF/jsp/initialization/begin.jsp]
I have also confirmed that my JSPs are present in target/classes/WEB-APP/jsp (or whatever other directory I've tried other than "WEB-APP"), so they do exist.
I'm at a loss how to proceed. I'm beginning to think I need to ditch Spring Boot and stick with a traditional boilerplate Spring Web MVC application with a Servlet config and a Tomcat installation, but I was really excited about the "just runs" aspect of Spring Boot. Any help would be appreciated.
UPDATE 1
After reading this Spring documentation about JSP limitations, I now know that I have to use <packaging>war</packaging>, and I'm using that now, but it hasn't made a difference. I'm starting to suspect that the underlying problem here is that maven spring-boot:run doesn't create a WAR and run it, it just builds everything to target/classes and runs it from there.
Also, after finding this old, official Spring boot samples application, I've changed my project structure a little:
- source
- production
- java
- [my source code packages]
- resources
- [my resource packages]
- webapp
- META-INF
- WEB-INF
- jsp
- initialization
- begin.jsp
- test
- java
- resources
Updated my view resolver configuration:
resolver.setPrefix("/jsp/");
resolver.setSuffix(".jsp");
And added this to my POM:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<warSourceDirectory>source/production/webapp</warSourceDirectory>
</configuration>
</plugin>
If I run mvn package, my WAR gets created correctly (classes and JSPs all where they should be), but neither mvn spring-boot:run nor mvn package spring-boot:run work—I still get 404 errors resolving my JSPs.
The old Spring Boot sample application linked to above puts the JSPs in WEB-INF/jsp, but I can't do that, because that results in the warning Path with "WEB-INF" or "META-INF": [WEB-INF/jsp/initialization/begin.jsp] (and still 404). What's frustrating is that this sample application doesn't exist anymore, nor does any new variation of it. I can't find any updated version that works with the newest version of Spring Boot. The sample application was deleted in 2.2.x.
Can you try by changing the scope of tomcat-embed-jasper to provided as this dependency is needed to compile JSPs.
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>[9.0.38,)</version>
<scope>provided</scope>
</dependency>
Edit:
I looked for various spring-boot + jsp projects over internet. I noticed that they have they also have spring-boot-starter-tomcat with provided scope. Can you try this.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>[2.3.4.RELEASE,3)</version>
<scope>provided</scope>
</dependency>
References :
https://mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/
https://dzone.com/articles/spring-boot-2-with-jsp-view
Edit-2 :
So this time i created a new springboot project. Did bare minimum setup to get jsp rendered. So basically i followed this tutorial and my project was running fine.
Then I replaced the pom.xml with yours and the i got the same error you mentioned in the question.
Then while doing trial and error i removed the <version>[9.0.38,)</version> from <artifactId>tomcat-embed-jasper</artifactId> and it started working for me.
<!--I have removed version here and it started working for me-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<!-- <version>[9.0.38,)</version>-->
<scope>provided</scope>
</dependency>
Although i have different directory structure. But as you mentioned that is not the cause of issue.
I have uploaded the project to github. Feel free to pull it run it locally.
Github
Assuming the following location for your web content (which should be outside the classpath AFAIK) source/production/webapp. Spring Boot will ignore this due to a hardcoded path in DocumentRoot for detection of directories when running from the command-line or IDE (it will work when building a war and running that).
As a workaround you can add a TomcatContextCustomizer as a bean to detect the path and set it as the correct base.
package com.my.project;
#SpringBootApplication
public class Application extends SpringBootServletInitializer
{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
{
return application.sources(DemoApplication.class);
}
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
#Bean
public TomcatContextCustomizer docBaseCustomizer()
{
return new TomcatContextCustomizer()
{
public void customize(Context context)
{
File root = new File("source/production/webapp");
if (root.exists() && root.isDirectory())
{
context.setDocBase(root.getAbsolutePath());
}
}
}
}
}
Now add the following to your application.properties
spring.mvc.view.prefix=/jsp/
spring.mvc.view.suffix=.jsp
NOTE: The removal of the other annotations can only be done if your #SpringBootApplication annotated class is in the com.my.project package. It will then automatically detect the other classes (like entities and repositories).
I'm currently building a microservice-based on Helidon Microprofile following guides and tutorials from Oracle themselves, but I've run into a problem related to the 'Automatic OpenAPI specification generator' when using Annotations.
My POM consists of an MP bundle and integrations to make it work with Hibernate-provided JPA.
Even after setting up all the annotations on my Resource, it doesn't generate an updated specification.
POM
<dependencies>
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>2.1.1.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.helidon.integrations.cdi</groupId>
<artifactId>helidon-integrations-cdi-datasource-hikaricp</artifactId>
<version>1.4.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.helidon.integrations.cdi</groupId>
<artifactId>helidon-integrations-cdi-jta-weld</artifactId>
<version>1.4.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.helidon.integrations.cdi</groupId>
<artifactId>helidon-integrations-cdi-hibernate</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.29.1</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.8.3</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>jwks-rsa</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
I'm only using Annotations specified in the guides and #OpenAPIDefinition for defining things like Title and Licence.
RESOURCE
#OpenAPIDefinition(
info = #Info(
title = "Newsletter Microservice",
version = "1.0", description = "Microservice in charge of handling newsletter",
license = #License(name = "Apache 2.0", url = "https://www.apache.org/licenses/LICENSE-2.0"),
contact = #Contact(name = "Email", url = "mailto:email")
),
tags = {
#Tag(name = "public"), #Tag(name = "private")
}
)
#Path("/newsletter")
#RequestScoped
public class NewsletterClientResource {
LOG
Connected to the target VM, address: '127.0.0.1:0', transport: 'socket'
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2019.12.02 20:01:19 INFO org.jboss.weld.Version Thread[main,5,main]: WELD-000900: 3.1.1 (Final)
2019.12.02 20:01:20 INFO org.jboss.weld.Bootstrap Thread[main,5,main]: WELD-ENV-000020: Using jandex for bean discovery
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jboss.weld.util.bytecode.ClassFileUtils$1 (file:/C:/Users/Brenno%20Fagundes/.m2/repository/org/jboss/weld/weld-core-impl/3.1.1.Final/weld-core-impl-3.1.1.Final.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of org.jboss.weld.util.bytecode.ClassFileUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2019.12.02 20:01:21 INFO org.jboss.weld.Event Thread[main,5,main]: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jersey.ext.cdi1x.internal.ProcessAllAnnotatedTypes.processAnnotatedType(#Observes ProcessAnnotatedType<?>, BeanManager) receives events for all annotated types. Consider restricting events using #WithAnnotations or a generic type with bounds.
2019.12.02 20:01:21 INFO org.jboss.weld.Event Thread[main,5,main]: WELD-000411: Observer method [BackedAnnotatedMethod] private io.helidon.microprofile.openapi.IndexBuilder.processAnnotatedType(#Observes ProcessAnnotatedType<X>) receives events for all annotated types. Consider restricting events using #WithAnnotations or a generic type with bounds.
2019.12.02 20:01:22 INFO org.jboss.weld.Bootstrap Thread[main,5,main]: WELD-ENV-002003: Weld SE container 404f642b-892f-4676-960e-8df848aee3a3 initialized
2019.12.02 20:01:22 INFO io.helidon.microprofile.security.SecurityMpService Thread[main,5,main]: Security extension for microprofile is enabled, yet security configuration is missing from config (requires providers configuration at key security.providers). Security will not have any valid provider.
2019.12.02 20:01:22 INFO io.smallrye.openapi.api.OpenApiDocument Thread[main,5,main]: OpenAPI document initialized: io.smallrye.openapi.api.models.OpenAPIImpl#7793ad58
2019.12.02 20:01:23 INFO io.helidon.webserver.NettyWebServer Thread[main,5,main]: Version: 1.4.0
2019.12.02 20:01:24 INFO io.helidon.webserver.NettyWebServer Thread[nioEventLoopGroup-2-1,10,main]: Channel '#default' started: [id: 0x4e1f119b, L:/0:0:0:0:0:0:0:0:7200]
2019.12.02 20:01:24 INFO io.helidon.microprofile.server.ServerImpl Thread[nioEventLoopGroup-2-1,10,main]: Server initialized on http://localhost:7200 (and all other host addresses) in 5254 milliseconds.
BUMP, also, the generation works using custom filters and models, a static definition in META-INF also works. Currently using JDK 13.
EDIT: this is my Application class after Tim Quinn's suggested modifications.
APPLICATION CLASS
#ApplicationScoped
#ApplicationPath("/")
#OpenAPIDefinition(
info = #Info(
title = "Newsletter Microservice",
version = "1.0", description = "Microservice in charge of handling newsletter",
license = #License(name = "Apache 2.0", url = "https://www.apache.org/licenses/LICENSE-2.0"),
contact = #Contact(name = "Email", url = "mailto:john.doe#gmail.com")
),
tags = {
#Tag(name = "public"), #Tag(name = "private")
}
)
public class NewsletterApplication extends Application {
#Override
public Set<Class<?>> getClasses(){
HashSet<Class<?>> classes = new HashSet<Class<?>>();
classes.add(NewsletterClientResource.class);
return classes;
}
}
GENERATED FILE
---
openapi: 3.0.1
info:
title: Generated API
version: "1.0"
paths: {}
Brenno,
You didn't show your updated source code, but I'm assuming you added the #OpenAPIDefinition annotation to the quickstart GreetResource class, is that right?
That annotation's attributes describe the whole application, not a subset of its resources, so try moving the annotation to the GreetApplication class instead:
#ApplicationScoped
#ApplicationPath("/")
#OpenAPIDefinition(info = #Info(title = "QuickStart API", version = "1.1"))
public class GreetApplication extends Application {...}
That should work. I just tried this on the generated Helidon MP quickstart example source, rebuilt, and the server returned the expected results.
Here is the diff for the change I made:
diff --git a/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetApplication.java b/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetApplication.java
index fd140738..cca60da2 100644
--- a/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetApplication.java
+++ b/examples/quickstarts/helidon-quickstart-mp/src/main/java/io/helidon/examples/quickstart/mp/GreetApplication.java
## -23,12 +23,15 ## import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import io.helidon.common.CollectionsHelper;
+import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition;
+import org.eclipse.microprofile.openapi.annotations.info.Info;
/**
* Simple Application that produces a greeting message.
*/
#ApplicationScoped
#ApplicationPath("/")
+#OpenAPIDefinition(info = #Info(title = "QuickStart API", version = "1.1"))
public class GreetApplication extends Application {
#Override
And here is the beginning of the updated OpenAPI document returned from the server:
---
openapi: 3.0.1
info:
title: QuickStart API
version: "1.1"
paths:
The title and version have changed, as expected.
Case 1 : You are using jandex and your /openapi is not getting updated.
If you are using jandex, there is a high chance that your jandex.idx is not getting updated. You can do this by running mvn process-classes
Case 2 : You are not using jandex and when you hit /openapi you get somewhat blank response.
This seems to be an issue with Helidon. The dependencies helidon-integrations-cdi-jpa, helidon-integrations-cdi-jta, helidon-integrations-cdi-eclipselink etc... contains jandex.idx and Helidon now thinks that jandex is enabled and it
will read only from those jandex files, skipping your resources. So for the time-being, you can include jandex plugin to solve the issue.
i'm currently using Arquillian for jboss(remote) and i'm trying to make Jmockit work. I deployed an ear which works fine, but i'm getting this error for arquillian-service:
java.lang.NoClassDefFoundError: mockit/internal/state/TestRun
Caused by: java.lang.ClassNotFoundException: mockit.internal.state.TestRun from
[Module "deployment.arquillian-service:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
I'm using jMockit 1.7 and have it in EAR deployment.
How can i add library in this deployment (arquillian-service)
PS: This deployment is managed by arquillian, i have nothing to do with it.
I solved the problem of third-party libs as follows -
the list of dependencies:
protected static final String[] DEPENDENCIES = {
...,
"xbean:xbean:2.4.0",
...
};
Method which packs all them into separate jar:
protected JavaArchive thirdPartyLibs() {
JavaArchive lib = ShrinkWrap.create(JavaArchive.class, "libs.jar");
for (String dependency : DEPENDENCIES) {
lib.merge(Maven.resolver().resolve(dependency).withoutTransitivity().asSingle(JavaArchive.class));
}
return lib;
}
Eventually I merge it when packing core jar:
protected JavaArchive createJar() {
return ShrinkWrap.create(JavaArchive.class, "test.jar")
.addAsManifestResource("META-INF/test-persistence.xml", ArchivePaths.create("persistence.xml"))
.addAsManifestResource("META-INF/test-beans.xml", ArchivePaths.create("beans.xml"))
.....
.merge(thirdPartyLibs());
}
Also to use this next dependencies must be pointed out:
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>2.1.1</version>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven-archive</artifactId>
<scope>test</scope>
</dependency>
So as suggest in another thread (Arquillian ShrinkWrap have switched to managed container (Jboss AS 7.1) , now the error is different
New dependency managment (see previous link to original question to see )
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>2.1.2</version>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.5.Final</version>
<scope>test</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
Then
I have to add
<dependency>
<groupId>org.jboss.arquillian.core</groupId>
<artifactId>arquillian-core-api</artifactId>
<version>1.1.4.Final</version>
<scope>test</scope>
</dependency>
Because i have an Exception
Caused by: java.lang.NoClassDefFoundError: org/jboss/arquillian/core/api/threading/ExecutorService
And now the deploy on local instance of Jboss seems to work fine ( i will test with a simpler test as soon as i have a little time but i think all is fine)
Essentially the problem is to add a jar dependencies present in maven (mistral-be which is not part of this maven project) to the deployed test (see description this question(Arquillian ShrinkWrap)).
Finally i use this code
String str = "C:\\IntellijProject\\Import***\\import****\\migrazione****-be\\pom.xml";
JavaArchive pomFiles = ShrinkWrap.create(MavenImporter.class)
.loadPomFromFile(str).importBuildOutput().as(JavaArchive.class);
/* https://github.com/shrinkwrap/resolver/blob/master/README.asciidoc#resolution-of-artifacts-defined-in-pom-files */
JavaArchive[] mistral_be = Maven.configureResolver().workOffline().resolve("it.****.mistral:mistral-be:0.1.0").withTransitivity().as(JavaArchive.class);
for (int i = 0; i < mistral_be.length ; i++) {
pomFiles = pomFiles.merge(mistral_be[i]);
}
pomFiles.as(ZipExporter.class).exportTo(new File ("C:\\temp\\res.zip"));
It generate quite a big zip file only to check the result, but while try'n to deploy to jboss 7.1.1
18:46:17,003 INFO [org.jboss.as.repository] (management-handler-thread - 2) JBAS014900: Content added at location C:\jboss\jboss-as-7.1.1.Final\standalone\data\content\bc\b6fd502db2696342419c17a6d2ed82a4176a4e\content
18:46:17,008 INFO [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015876: Starting deployment of "arquillian-service"
I have an error:
org.jboss.arquillian.container.spi.client.container.DeploymentException: Could not deploy to container: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"postImportBE-1.0-SNAPSHOT.jar\".STRUCTURE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"postImportBE-1.0-SNAPSHOT.jar\".STRUCTURE: Failed to process phase STRUCTURE of deployment \"postImportBE-1.0-SNAPSHOT.jar\""}}
As i see in the app server log it is
Caused by: java.lang.SecurityException: Invalid signature file digest for Manifest main attributes.
I see in the META_INF of the zipped file directory a lot o files coming from transitive dependencies of mistral-be, so the problem could be this. Is there anyway to generate a JAR file with a valid signature? Or may be i am using a wrong aprroach to solve this problem (contruct jar in another way or similar idea)?
And i'm curios why the dependencies in pom:
<dependency>
<groupId>it.**.mistral</groupId>
<artifactId>mistral-be</artifactId>
<version>0.1.0</version>
<scope>compile</scope>
</dependency>
is not directly import by this instruction? Did i miss something?
String str = "C:\\IntellijProject\\Import***\\import****\\migrazione****-be\\pom.xml";
JavaArchive pomFiles = ShrinkWrap.create(MavenImporter.class)
.loadPomFromFile(str).importBuildOutput().as(JavaArchive.class);
Thank you
When dealing with pom dependencies I use a WebArchive instead of a JavaArchive for wrapping all the required code generated by ShrinkWrap:
String[] mavenLibs = {
"junit:junit:4.8.1"
};
WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war");
for (String dependency : mavenLibs) {
war.addAsLibrary(Maven.resolver().resolve(dependency).withTransitivity().asSingle(JavaArchive.class));
}
Using this mecanism I didn't have the issue you described.
I'm trying to setup tests with PAX Exam as follows:
#ExamReactorStrategy(PerMethod.class)
public class AbstractTest {
#Configuration
public Option[] config() {
return options(
junitBundles(),
/* PAX Logging */
mavenBundle("org.ops4j.pax.logging", "pax-logging-api", "1.7.2"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-service", "1.7.2"),
/* Apache Felix Config Admin */
mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.8.0"),
/* Eclipse Gemini dependencies */
mavenBundle().groupId("org.aopalliance").artifactId("com.springsource.org.aopalliance").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.aop").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.beans").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.context").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.core").versionAsInProject(),
/* Eclipse Gemini */
mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-core", GEMINI_VERSION),
mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-extender", GEMINI_VERSION),
mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-io", GEMINI_VERSION),
/* Other bundles */;
}
#Before
public void setUp() throws Exception {
....
}
}
#RunWith(PaxExam.class)
public class MyTest extends AbstractTest {
#Inject
private MyObject myObject;
#Test
public void testOne() {
...
}
}
For some reason, the method annotated with #Before is not called.
Thanks, Mickael
EDIT: The PAX EXAM dependencies I use are:
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<version>${pax.exam.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<version>${pax.exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-link-mvn</artifactId>
<version>${pax.exam.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.url</groupId>
<artifactId>pax-url-aether</artifactId>
<version>${url.version}</version>
<scope>test</scope>
</dependency>
I use PAX EXAM version 3.4.0.
I've set up a test project and it worked fine.
I finally found what is causing the issue. It seems that the execution of the tests is stopped during the configuration.
I use Eclipse Gemini 2.0.M02 and I use placeholders in my application contexts. For example, I need the datasource URL to be set as property. I wanted to use a #Before method to setup a configuration for a PID using the Configuration Admin service.
Since the application contexts are loaded during the configuration and that at this point the PID is not configured (since the #Before method is not called yet), I get an error from Spring which causes PAX EXAM to abort execution of current test.
Therefore, I can't use the Configuration Admin Service from the #Before method in my case.
The solution is to use the pax-exam-cm module which allows interacting with the Configuration Admin Service inside the configuration method as follows:
#Configuration
public static Option[] config() {
return options(
junitBundles(),
/* PAX Logging */
mavenBundle("org.ops4j.pax.logging", "pax-logging-api", "1.7.2"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-service", "1.7.2"),
/* Apache Felix Config Admin */
mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.8.0"),
ConfigurationAdminOptions.newConfiguration("my.pid")
.put("prop1", "value1")
.put("prop2", "value2")
.asOption(),
/* Eclipse Gemini + dependencies */
mavenBundle().groupId("org.aopalliance").artifactId("com.springsource.org.aopalliance").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.aop").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.beans").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.context").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.core").versionAsInProject(),
mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-core", GEMINI_VERSION),
mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-extender", GEMINI_VERSION),
mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-io", GEMINI_VERSION),
/* Other bundles */
);
}
You also need to add the pax-exam-cm dependency to your POM (if you use Maven):
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-cm</artifactId>
<version>3.4.0</version>
<scope>test</scope>
</dependency>