How to upload the stub.jar generated by spring cloud contract - spring-cloud

I've been using Spring Cloud Contract to test the Producer Side. And now, I wanted to upload the stub.jar file to nexus, so my colleague could write some integration test against my producer. And I found the Spring Documentation hard to follow.
<!-- First disable the default jar setup in the properties section-->
<!-- we don't want the verifier to do a jar for us -->
<spring.cloud.contract.verifier.skip>true</spring.cloud.contract.verifier.skip>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>stubs</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/java</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**com/example/model/*.*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**com/example/model/*.*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/snippets/stubs</directory>
<outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/mappings</outputDirectory>
<includes>
<include>**/*</include>
</includes>
</fileSet>
<fileSet>
<directory>${basedir}/src/test/resources/contracts</directory>
<outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/contracts</outputDirectory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileSet>
</fileSets>
After I add the "skip" line to the pom, I found that stubs json never get generated.
I'm using Spring Cloud Contract 1.2.4, and I think there is only "stub" folder in the target, not a "snippets/stubs".
What files are required in the stub.jar for the Stub Runner to run it?

I've been using Spring Cloud Contract to test the Producer Side. And now, I wanted to upload the stub.jar file to nexus, so my colleague could write some integration test against my producer.
If you use the DSL there's nothing you need to do. Just do ./mvnw deploy and we will generate the fat jar and the stubs jar.
And I found the Spring Documentation hard to follow.
That's not really specific is it? What exactly is hard to follow?
After I add the "skip" line to the pom, I found that stubs json never get generated.
Which skip line? If you add <spring.cloud.contract.verifier.jar.skip>false</spring.cloud.contract.verifier.jar.skip> then we will disable only JAR creation.
I'm using Spring Cloud Contract 1.2.4, and I think there is only "stub" folder in the target, not a "snippets/stubs".
Are you even using Rest Docs? Where did you get the snippet from? From here https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_publishing_stubs_as_jars ? If you read the text over the snippet you'll see For both Maven and Gradle, the setup comes ready to work. However, you can customize it if you want to.. If you follow the step by step section of the documentation we describe the whole, most basic flow. Also there are multiple tutorials out there, including a very thorough one over here http://cloud-samples.spring.io/spring-cloud-contract-samples/workshops.html
What files are required in the stub.jar for the Stub Runner to run it?
We describe that in the documentation. If you want to use the classpath mapping read this section https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_classpath_scanning . Otherwise, we unpack and go through any WireMock Json file that we can parse.
Here you have a working example of manual creation of stubs jar - https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/master/producer_with_restdocs . I think you should read the documentation from the beginning and follow the tutorials. Or tell us what exactly is unclear with the documentation that made you feel confused.

Related

Generate REST API documentation

Is there a way to auto-generate a ZOHO-style documentation of my Jersey Rest Services? This is one of the best REST documentations I have seen so far. I'm open to alternatives.
Swagger also looks promising but I don't see how to generate it. It seems like it needs a YAML style documentation.
Can I generate it from javadoc somehow?
I'd prefer to generate the docs via Maven.
You can generate swagger-ui from Javadoc by using Enunciate, which has a Swagger module. First, you need to add the maven plugin to your pom file; e.g.
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>${enunciate.version}</version>
<executions>
<execution>
<goals>
<goal>docs</goal>
</goals>
<configuration>
<configFile>enunciate.xml</configFile>
<docsDir>${project.build.directory}</docsDir>
</configuration>
</execution>
</executions>
</plugin>
where 'enunciate.xml' contains your project specific configurations and looks like this:
<enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.0.0-M.3.xsd">
<application root="/rest" />
</enunciate>
Then run mvn package and it will generate Swagger documentation files from your Javadoc.
p.s. taken from my answer here.
Adding swagger to jersey based services is not too complicated.
See these detailed steps on how to go about it:
Hope that helps
You can use Swagger to document your REST API, it's not difficult to set up. There are some instructions here. To summarize:
Adding Swagger dependencies
Add the following dependency to your pom.xml:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
Setting up Swagger
Add the following to your Application class (change the values according to your needs):
#ApplicationPath("/api")
public class MyApplication extends Application {
public MyApplication() {
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/api");
beanConfig.setResourcePackage("io.swagger.resources,com.example.project");
beanConfig.setScan(true);
}
}
Build your project, start your server and access http://localhost:8080/app/api/swagger.json (the URL might be different in your environment) to get the JSON which documents your API.
Setting up Swagger UI
Download Swagger UI from GitHub and copy the content from the dist folder to your web content folder. I usually create a folder called api-docs to store all Swagger UI files.
Open Swagger UI's index.html and change the URL which refers to the swagger.json:
var swaggerUi = new SwaggerUi({
url: "http://localhost:8080/app/api/swagger.json",
dom_id: "swagger-ui-container"
});
Access http://localhost:8080/app/api-docs (the URL might be different in your environment). The Swagger UI with your API documentation should be there.
More information
You always can customize Swagger UI to fit your needs.
Swagger reads JAX-RS annotations to generate the documentation. Additionally, you can use Swagger annotations to improve it.

Use Maven Cargo to install Wildfly with Keycloak

I'm trying to use Maven Cargo to produce a Wildfly container and get Keycloak running on it. I've been at this for a while now and the way I see it there are two ways to go about it. I could either use an artifact installer for Wildfly and then try to deploy Keycloak to it, or I could use a zip installer and have it install Keycloak's appliance build. I have the basics of both solutions working although neither of them work all the way.
They both seem to have downsides. If you use the artifact installer you have a more stable installer, but deploying the war takes quite a bit of lower level configuration for Wildfly. (Deployment Instructions). On the other hand, the zip installer requires finding a place to download a distribution from and then manipulating it a bit before Cargo will recognize it, because the zip structure is not what Cargo seems to be expecting.
I'm getting the zip from here: https://repository.jboss.org/nexus/content/repositories/releases/org/keycloak/keycloak-appliance-dist-all/1.0.2.Final/keycloak-appliance-dist-all-1.0.2.Final.zip)
Thanks in advance guys.
I figured out a way to do this and attached the relevant pom snippet. The only oddball piece here ends up being the files section. It's being used to deploy a database file that has a couple test users, realms, apps, etc.
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.6</version>
<configuration>
<container>
<containerId>wildfly8x</containerId>
<!-- <log>${basedir}/target/cargo.log</log> -->
<!-- <output>${basedir}/target/wildfly.log</output> -->
<home>${project.basedir}/target/cargo/installs/keycloak-appliance-dist-all-1.0.4.Final/keycloak-appliance-dist-all-1.0.4.Final/keycloak</home>
<artifactInstaller>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-appliance-dist-all</artifactId>
<version>1.0.4.Final</version>
</artifactInstaller>
</container>
<configuration>
<properties>
<cargo.servlet.port>8080</cargo.servlet.port>
<cargo.servlet.users>root:root:ManagementRealm</cargo.servlet.users>
<cargo.jboss.configuration>standalone</cargo.jboss.configuration>
</properties>
<files>
<file>
<file>${project.basedir}/WildflyKeycoakConfigs/keycloak.h2.db</file>
<todir>/data</todir>
</file>
</files>
</configuration>
</configuration>
</plugin>

Eclipse: Change webapp folder in Maven pom.xml file

Is it possible to define a different location for the webapp folder than the standard one ("/src/main/webapp/") in pom.xml? I know that you can define your web folder with
<wb-resource deploy-path="/" source-path="/webapp"/>
in a file called "org.eclipse.wst.common.component".
The problem is when I click Maven -> Update Project, this line is overwritten with the standard
<wb-resource deploy-path="/" source-path="/src/main/webapp"/>
And then I have problems testing my project with Tomcat7 within Eclipse.
I'm very thankful for every hint.
Answers in How to configure custom maven project structure are sufficient for a purely Maven build, i.e. from commandline. When import the project into Eclipse (via m2e), you need tell m2e a little bit more so that it can create and maintain the project structure properly within Eclipse.
Actually, from Eclipse's perspective, it doesn't really care about how your project folder structure looks like, as long as the webapp folder is declared as a source folder or inside a source folder, however, by modifying .classpath doesn't make much sense as it's a auto-generated file and changed quite often.
It is highly recommended to obey the convention if you are able to, if not, using the following configuration for your customization:
<build>
<resources>
<resource>
<directory>${basedir}/webapp</directory>
</resource>
... ...
</resources>
... ...
</build>

Eclipse - Wicket - HTML files from dependent projects not being found

I want to build a reusable Wicket component in Eclipse. I have one project "components" which have files such as MyComponent.java and MyComponent.html. Then I have a project "application" which contains my application code, from which I wish to use a MyComponent.
However, Wicket cannot find the MyComponent.html. If I copy this file from "components" to "application", and use exactly the same path, then Wicket finds it no problem.
I therefore summize that Eclipse is not copying the HTML file from the dependent project "components" and making it available to the web application. I cannot really confirm that as I don't know where the JAR is being generated from the "components" project, nor do I know where/if the WAR is being generated from the "application" project.
I have looked at the project settings in "components" and cannot find any option to explicitly publish HTML (non-Java) files when the project is being built; but I cannot find any option which is explicitly forbidding this either. In the "application" project I find no option to include HTML files from the other project (there is only the option to include the JAR - which potentially should be enough?)
Update: I am not using Maven, just using the default build process of Eclipse.
Update: I am using Tomcat within Eclipse (but without any Eclipse plug-in for Tomcat; it seems to work fine without it - only obviously that's not quite true hence my question...)
Check Eclipse's source folders inclusion/exclusion filters. Project -> right button -> Properties -> Java Build path -> tab Source -> select Source Folder -> button Edit.
I'm assuming you're using Tomcat - during testing I normally use a Tomcat context to reference my Eclipse project workspace.
The workspace contains a context/WEB-INF directory structure, into which all my compiled classes, properties, HTML and other resources are copied.
The Tomcat context file lives in the directory (Tomcat)/conf/Catalina/localhost and contains an entry of the following format:
<Context path="/mywebapp" docBase="C:/eclipse/workspace/myapp/context" reloadable="true">
OK - Classic Eclipse action - for other reasons (restarting the project always resulted in a 404 for no apparent reason: I checked all the config files and everything seemed fine..), I deleted the "application" project from Eclipse and re-created it. Now everything works fine (HTML files are available...)
I had the same problem! After some time doing research I had a solution!
You need to specify to maven that it needs to include all the files, the way how maven understand this is by adding the next command.
<build>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>
It worked for me, I hope it works for any of you that have the same problem!
I guess for the person that posted this query its too late, but not for you that have this problem!

How to add a jar to the server lib for *embedded* JBoss?

I need to add a crypto provider to the embedded JBoss used by Seam for integration tests.
For the regular JBoss it's a simple matter, just drop the files into the /lib folder of the server instance. With the embedded JBoss, however, things seem to be different. I've tried putting the jars in /embedded-jboss/bootstrap/lib and /embedded-jboss but no change, the classes are not seen.
I've read http://community.jboss.org/wiki/EmbeddedAndJavaSE and also looked in the source of org.jboss.embedded.Bootstrap but I haven't found a way yet. The build is done with Maven if it matters.
Thanks a lot for any suggestions.
I found an answer in the meantime: they can be added to the classpath of the plugin that runs the tests, like below. Works for me.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- snip -->
<additionalClasspathElements>
<additionalClasspathElement>add/here/your/jar</additionalClasspathElement>
</additionalClasspathElements>