No content to map due to end-of-input swagger maven plugin - java

I am including security definitions in pom.xml file. When I run a goal mvn compile, it throws an exception:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.2:generate (default) on project test: com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
I have included security definitions in Swagger Maven plugin as below
<securityDefinitions>
<securityDefinition>
<json>src/main/resources/securityDefinition.json</json>
</securityDefinition>
</securityDefinitions>
I have tried with ${basedir} but still get the above exception. How can this be resolved also as the spec says?
The file will be read by getClass().getResourceAsStream, so please note the path you configured. How can I fullfil this condition?

You need to wait to next plugin release (3.1.6). They just merged the changes to the master branch with the solution to the classpath file loading problem that you are facing. The classloader used when the plugin executes has no access to the project's files, be it resources or Java source files.
Next release will have a <jsonPath> tag to allow access to file location and <json> tag for classpath file loading (solving the problem).
Update (tested):
If you don't mind about it you can use the 3.1.6-SNAPSHOT version.
Then, in your POM:
<securityDefinitions>
<securityDefinition>
<jsonPath>${project.basedir}/securityDefinition.json</jsonPath>
</securityDefinition>
</securityDefinitions>
And in the JSON file follow the author's intructions:
https://github.com/kongchen/swagger-maven-plugin

Related

Including DevTools in Spring Boot's JAR with Gradle during development

I've been looking for an answer but pretty much everything I found so far is either outdated or didn't work. I'd like to include Spring DevTools inside my JAR so that I can use live reloading feature.
What I did so far;
Built a Docker image with ./gradlew bootBuildImage.
Created a docker-compose.yml which uses this image.
Changed configuration in IntelliJ to use org.springframework.boot.devtools.RemoteSpringApplication as the main class.
However, when I change something and build the project I always get the same error:
Exception in thread "File Watcher" java.lang.IllegalStateException: Unexpected 404 NOT_FOUND response uploading class files
Do I need to change the way I build the image or apply some additional Gradle configuration for this to work? With Maven it was enough to just set excludeDevTools to false but looks like it doesn't work with Gradle.
Solved it by adding this in the build.gradle.kts;
tasks.getByName<BootJar>("bootJar") {
classpath(configurations["developmentOnly"])
}

Ivy Install task fails with JSCH SFTP error 4 first time, but is successful on subsequent attempts

I am trying to use the ANT Ivy install task to copy a library from one repository to the other.
Some example code within my ANT target:
<ivy:install organisation="testOrg" module="testModuleName" revision="1.2.3" from="fromRepo" to="toRepo"/>
The fromRepo and toRepo are defined in a local ivysettings.xml file.
The resolve (from fromRepo) of the library is successful but the install to toRepo fails, with an SFTP Code 4 error.
impossible to install testOrg#testModuleName;1.2.3: java.io.IOException: Failure
at org.apache.ivy.plugins.repository.sftp.SFTPRepository.put(SFTPRepository.java:164)
at org.apache.ivy.plugins.repository.AbstractRepository.put(AbstractRepository.java:130)
at org.apache.ivy.plugins.resolver.RepositoryResolver.put(RepositoryResolver.java:234)
at org.apache.ivy.plugins.resolver.RepositoryResolver.publish(RepositoryResolver.java:215)
at org.apache.ivy.core.install.InstallEngine.install(InstallEngine.java:150)
at org.apache.ivy.Ivy.install(Ivy.java:537)
at org.apache.ivy.ant.IvyInstall.doExecute(IvyInstall.java:102)
at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:271)
...
Caused by: 4: Failure
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2833)
at com.jcraft.jsch.ChannelSftp.mkdir(ChannelSftp.java:2142)
at org.apache.ivy.plugins.repository.sftp.SFTPRepository.mkdirs(SFTPRepository.java:186)
at org.apache.ivy.plugins.repository.sftp.SFTPRepository.mkdirs(SFTPRepository.java:184)
at org.apache.ivy.plugins.repository.sftp.SFTPRepository.put(SFTPRepository.java:160)
... 37 more
However if I simply run the same target again, the install completes successfully!
It seems to be some issue with creating a directory, from com.jcraft.jsch.ChannelSftp.mkdir(ChannelSftp.java:2142) in the stacktrace.
After running the 1st time, the testOrg/testModuleName directory exists (only testOrg having previously existed).
The 2nd time running the testOrg/testModuleName/1.2.3 directory is created (along with the library artifacts).
If after running the 1st time I delete the testOrg/testModuleName directory it created, it will continue to return the code 4 error.
My ANT library directory contains: jsch-0.1.50.jar which I assume it is using to upload to the destination Ivy Server.
In addition I am using:
Ant 1.8.4
Ivy 2.4.0
Java 1.7.0_80
By debugging the Ivy SFTP source code that creates the new directories on the destination toRepo repository, I was able to see why this was happening.
The code is in the method: SFTPRepository.mkdirs() this recursively calls itself to make each directory in the path if they do not exist.
For my example the directory being uploaded was:
/toRepo/testOrg/testModuleName//1.2.3/
You can see the double slash: // in the middle of the path.
The meant that the mkdirs() method tried to create the testModuleName directory twice. The 2nd time failed which caused the code 4 error.
The reason there is a double slash in the path is because there is no branch for this artifact.
Within my ivy settings file the sftp resolver (for my toRepo repository) artifact patterns were configured to:
<ivy pattern="/toRepo/[organisation]/[module]/[branch]/[revision]/ivy-[revision].xml"/>
<artifact pattern="/toRepo/[organisation]/[module]/[branch]/[revision]/[artifact]-[revision].[ext]"/>
The /[branch]/ part of the pattern is what was generating the // in the path.
There are 2 configurations, one for the ivy.xml file itself and the other for all other artifacts.
Ivy patterns allow the use of parenthesis for optional parts of the pattern.
So changing my configuration to:
<ivy pattern="/toRepo/[organisation]/[module](/[branch])/[revision]/ivy-[revision].xml"/>
<artifact pattern="/toRepo/[organisation]/[module](/[branch])/[revision]/[artifact]-[revision].[ext]"/>
Fixed the issue and the ivy install functioned as expected.
This means that for antifacts where there is no branch defined (like 3rd party artifacts), then the branch directory will not be included in the path.

Jenkins ERROR: Failed to create /usr/share/tomcat7/.m2 on Maven project

I am running Jenkins ver. 2.60.2 and it doesn't seem possible, within a Maven Job, to define a local repository not in /usr/share/tomcat7/.m2.
Here are my attempts:
I created a Global Maven settings.xml and a Settings file with the Config File Management Plugin, that contains:
<settings>
<localRepository>/srv/maven/.m2/repository</localRepository>
...
</settings>
I Created a new Maven Project. Tried to make the Job see that file by attempting all of the following:
a) Defining either Settings file or Global settings file (I created two identical files) within the build step:
b) Adding a Pre-step Provide Configuration files, and then using the variable MY_SETTINGS either in the Goals and options or MAVEN_OPTS:
c) Use the Provide Configuration files within the build environment (and using the MY_SETINGS in the same way as in the previous step.:
However, none of these seems to work. The job always fails, trying to use the default maven repository location (/usr/share(tomcat7/.m2) - which I have no idea how to re-define:
provisioning config files...
copy managed file [MYFILE settings] to file:/srv/webapps/jenkins/jobs/testJob/workspace#tmp/config3408982272576109420tmp
provisioning config files...
copy managed file [MYFILE settings] to file:/srv/webapps/jenkins/jobs/testJob/workspace#tmp/config2203063037747373567tmp
Parsing POMs
using global settings config with name MYFILE settings
Replacing all maven server entries not found in credentials list is true
Deleting 1 temporary files
ERROR: Failed to create /usr/share/tomcat7/.m2
Finished: FAILURE
Do you know how to make this work within a Maven Job type in Jenkins?

How to build the war files for oAuth2-sample project?

I cloned the project here https://github.com/OhadR/oAuth2-sample
Set appropriate version for parent in pom.xml of all 3 projects oauth2-client, oauth2-auth-server, resource-sercer to
<version>1.6.2-SNAPSHOT</version>
I added the 3 projects to modules section in auth-parent. I built war files using mvn install.
<modules>
<module>auth-common</module>
<module>common-crypto</module>
<module>authentication-flows</module>
<module>oauth2-auth-server</module>
<module>oauth2-client</module>
<module>oauth2-resource-server</module>
</modules>
I put the 3 generate war file in jetty/webapps. Client and Resource-server seem to load fine but oauth2-auth-server doesnt. At localhost:8080 I get UNAVAILABLE for oauth2-auth-server.
I tried debugging by adding maven-jetty plugin and mvn jetty:run for oauth2-auth-server. But I get
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'authenticationSuccessHandler' for bean class [com.ohadr.auth_flows.core.AuthenticationSuccessHandler] conflicts with existing, non-compatible bean definition of same name and class [com.ohadr.oauth_srv.web.OhadAuthenticationSuccessHandler]
Not sure I see the problem - did you try build it from the main directory, by using maven command "mvn clean install"?
Maven will then build all sub-modules, which are common-crypto and authentication-flows.
My oAuth-Sample project is in use as an oAuth example as well as "authentication-flows" logic.
Do you build this oAuth-sample for oAuth-sample, or for "authentication-flows"?
Hope that helps (and sorry about the delay)

eclipse : Can not find the tag library descriptor for "/struts-tags"

I am following the steps given in
http://www.tutorialspoint.com/struts_2/struts_quick_guide.htm
for a sample struts 2 application
but I am getting following error message :
Can not find the tag library descriptor for "/struts-tags
I followed several helps :
Error - Can not find the tag library descriptor for "/struts-tags"
Cannot find the tag library descriptor for /WEB-INF/struts-html.tld in Struts
still the error persists.. what shall I do?
Thanks
This message can be produced if the struts2-core-[VERSION].jar is not marked as an Export Dependency.
To correct this:
Project Properties > Java Build Path > Order and Export
Then mark struts2-core-[VERSION].jar as an Export Dependency (or, if included via Ivy, make sure the Ivy library is marked as an Export Dependency).
Have you added the struts2-core-.jar to the libraries of the project? Clean the project. The error will go away.

Categories