Can we create stub JAR with just the Groovy Contract DSL file and without having the whole Producer code - spring-cloud-contract

I have a producer service code base. I added contract DSL Groovy files to it and maven dependencies and plugins to the pom. I am running mvn clean install to generate the Stub jar, wiremock stub json and the tests.
Is it possible to create the Stub jar without having the whole code base? Can we create Stub jar just by having the Contract DSL?
Previously I tried the below command on the folder where the contracts are residing. This would create Wiremock Stub JSON from the Groovy Contracts
mvn org.springframework.cloud:spring-cloud-contract-maven-plugin:convert
I want to generate Stub Jar too by just using the Groovy contracts and not the building the whole code base. Is it possible?
Thanks in advance

This is that happens out of the box. We create a sub hat with stubs and contracts. If you do mvn clean install you very the built code and the stub jar. You could create an assembly plugin setup to manually setup the jar.

Related

Writing a standalone Corda client that depends on classes defined in a CorDapp

I am writing a Corda RPC client that depends on state classes defined in a separate CorDapp.
How can I include these classes as dependencies when running the client?
You need to include the CorDapp JAR as a dependency in the project where you are defining the RPC client:
Create the CorDapp JAR that your client will depend on. You can do this by running gradlew deployNodes in a project where a deployNodes task is defined and extracting the CorDapp JAR from one of the node's plugins folders
Copy the JAR to somewhere in the RPC client project (e.g. ./lib/cordapp-name.jar)
Reference the JAR as a dependency in your build.gradle file, using the syntax cordapp files('lib/yo.jar'). Make sure you set the relative path correctly (e.g. if the build.gradle file is nested one level down, the above would become cordapp files('../lib/yo.jar'))
Currently, CorDapp JAR dependencies added in this way cannot be referenced from deployNode. This will be addressed in a future version of Corda.
You'll need to add the relevant CorDapp JARs as a dependency to the project containing your RPC Client. First copy your CorDapp JARs to a folder within your RPC client project. Then inside your RPC client's build.gradle file (make sure this is the file in the clients directory or the root of the RPC client project) , within the dependencies{} block, add the following line:
compile fileTree(include: ['*.jar'], dir: '../cordapp-jars')
Make sure to replace the directory path with one that points to the folder that you placed the CorDapp JARs. Lastly, within your RPC client, import the necessary Corda states or flows.

debugging contract test cases in spring cloud contract

I have a question related to spring cloud contract framework.Is it possible to debug the test cases which are auto-generated by spring cloud contracts. usually I do gradle build to execute the contracts.But to understand the actual problem, I would like to do debug and see the results.
The Spring Cloud Contract Plugin generates standard Junit test files based on your contracts. For Maven you can find these in the target/generated-test-sources/contracts directory (Gradle will have similar output in the build directory).
When opening the files in this directory, you can have a look at the generated code. If the intention is to debug these tests, they can be copy/pasted from this directory into the actual test sources directory in your project. Then you can directly run the tests in debug mode (as previously pointed out by Marcin). To avoid the copy/pasting, add the target/generated-test-sources/contracts directory as test sources folder in your IDE.

Does Spring Cloud Contract support JavaScript and JMS?

I want to start using the framework Spring Cloud Contract for contract testing. But does Spring Cloud Contract support JavaScript and JMS?
I haven't found any information about this.
As for the JMS, we do support it either via spring-integration or Apache Camel. You can also write your own JMS support. It's enough to register a couple of beans.
As for Javascript and non-jvm languages. There's no out of the box support but we have a process for that. The workflow is described here (in those cases the consumer is a Java app but in the next section I'll describe how the flow would differ) - https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_common_repo_with_contracts or https://cloud.spring.io/spring-cloud-contract/spring-cloud-contract.html#_step_by_step_guide_to_cdc. We will try to obviously simplify the process but currently there's a bunch of manual tasks to be done (not very tedious though).
The consumer can very easily download and run the stubs. Just clone https://github.com/spring-cloud-samples/stub-runner-boot, build it and push the fat jar to your Nexus/Artifactory. This application will be used by the consumers to automatically download stubs and run them locally. As a consumer you can then call java -jar stub-runner-boot --stubrunner.ids="com.example.groupid:artifactid:classifier:version:8090" --stubrunner.repositoryRoot="http://localhost:8081/artifactory/libs-release-local" . That way the application will start, download the provided jar with stubs from the given address where your artifactory is. Now your front end application can call the stubs of the producer at localhost:8090.
Of course we will try to simplify the cloning and pushing process (https://github.com/spring-cloud/spring-cloud-contract/issues/37) etc. but for now you have to do those 2 steps manually.
UPDATE:
With this article https://spring.io/blog/2018/02/13/spring-cloud-contract-in-a-polyglot-world we're presenting a way how to work in a polyglot environment. It's enough to use the provided docker images to run contract tests against a running application and to run the stub runners too.

include model libraries in appclient jar

I'm deploying an ear with an EJB onto glassfish 3.1 which I want to call using the appclient script.
The EJB has a method with as parameter a model object which is defined in a separate library.
If I want to use the appclient script I have a Main class with a main method which calls the EJB.
This is also put into a separate jar which is also deployed onto glassfish.
As the model object is located in a separate library I need it in the client jar but also in the EJB.
So I need to reference it somehow in the client jar.
The client jar is a jar (duh) so I cannot add other jars. The Java EE 6 docs say that I should create an ear with the libs but if I do that it doesn't deploy because an ear needs at least an ejb or web module and my client lib has neither.
The solution I found is using the assembly plugin/jar-with-dependencies. This plugin creates a new jar which contains all classes of all dependencies.
This solution works but I'm wondering if this is the way to go or I'm missing something obvious because I cannot imagine this is required. EJB's usually have model objects as parameters so this situation will happen a lot.
So my question is: is there a way to tell glassfish to reference the shared libraries between the app client jar and the ejb jar.
The way I do this is like this:
Separate Maven project with the model. In my case that's a bunch of simple POJOs with JPA and JAX-B annotations, some constants, etc. In Maven, I define this as an OSGi bundle, by specifying <packaging>bundle</packaging>. I call this project MyAppInterface.
Separate Maven projects for other elements that need to deal with the model. In my case, I have one Java EE application with EJBs, Database facade, REST servlet; I have an Integration-Test project which only does tests; a GWT application; etc... In those projects I specify the dependency to the model:
<dependency>
<groupId>com.skalio</groupId>
<artifactId>MyAppInterface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
When deploying MyAppInterface to Glassfish, I use the following syntax:
asadmin deploy --type osgi --name MyAppInterface /path/to/MyAppInterface-1.0-SNAPSHOT.jar
I understand it that this is placing the model on the classpath of Glassfish, similar to a mysql-connector, only OSGi-style.
I let all these projects be built by a central jenkins CI server, which deploys the artifacts to our internal maven repository. We then add the internal repository in pom.xml of each project. As a result, everyone automatically works with the latest stable MyAppInterface, even if they don't have the code checked out in NetBeans / Eclipse.
Let me know if you need more examples.

WebSphere wsadmin ClassNotFound Exceptions

I'm trying to use wsadmin with Jython to deploy an EAR file. Before the actual deployment, I need to run a DB update using a Java class. I'm running into a ClassNotFoundException that isn't making sense to me.
Background:
The EAR file is exploded. The wsadmin tool is started with the following options:
-wsadmin_classpath %CP%
-javaoption -Dpython.path=%CP%
Both of those point to the same classpath, which contains all necessary JARs.
The jython script gets a connection to a database, and calls a utility class to create a database script. The utility class uses reflection to load other classes from the classpath (that is a hard-and-fast requirement of the library we are using, it can't be changed). It basically looks like this:
from liquibase import Liquibase
def main(args):
conn = getConnection(args)
updater = Liquibase(conn)
updater.update()
During the update() method, Liquibase uses reflection to instantiate some Java classes. This is where I get a ClassNotFoundException, for example ClassNotFoundException: com.foo.CustomUpdate
In my script, I can import the com.foo.CustomUpdate class and get no errors:
from com.foo import CustomUpdate
c = CustomUpdate("select 1")
print c.getUpdate()
So I know that the class is on the classpath. My only idea is that it has something to do with the reflection aspect of the library we are using. Has anybody else run up against anything like this?
My only other idea, if the above is unfixable, is to split things out into a shell script and use Java to run the DB update and then wsadmin to deploy the EAR.

Resources