Integrate Swagger with Dropwizard, not able to produce the swagger.json file - java

I have done the following steps:
I have a existing drop-wizard project setup [0.8 version].
Added dependence
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.10</artifactId>
<version>1.3.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core</artifactId>
<version>1.5.1-M2</version>
</dependency>
I have added the #Api annotations to my resource file.
I have added the following code to the application run class:
environment.jersey().register(new ApiListingResource());
BeanConfig config = new BeanConfig();
config.setTitle("default Application");
config.setVersion("1.0.0");
config.setResourcePackage("com.class.where.the.api.annotation.are");
config.setScan(true);
The problem is when I run the application I can't get the swagger.json by going to http://localhost:8080/swagger.json.
pretty much follow the example here: https://github.com/swagger-api/swagger-core/tree/master/samples/java-dropwizard
Does anyone know what the problem is? What else do I need to setup? [The application runs and start up fine, I just can't get to that swagger.json file]

You're using conflicting and incomplete dependencies. If you take a look at the https://github.com/swagger-api/swagger-samples/tree/master/java/java-dropwizard sample, you'll see that you actually need to include:
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.1-M1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
and only that (no swagger-core directly). If you do follow that with a similar configuration to what you have, it should work fine.

Related

why is my maven sub dependency version for spark connector package different from others

I am trying to use a pom file from a existing project and I am getting an error "Cannot resolve org.yaml:snakeyaml:1.15"
What I find out about this error is that the com.datastax.spark:spark-cassandra-connector_2.11:2.5.0 uses a couple dependencies and a couple levels down it is using snakeyaml:1.15 which is quarantined by company proxy. Is there a way to specify for a given maven dependency that I want to use snakeyaml:1.16?
One thing I do not understand is that I look into the reference project that is also using com.datastax.spark:spark-cassandra-connector_2.11:2.5.0, it is using the updated com.datastax.oss:java-driver-core-shaded:4.9.0, which no longer requires snakeyaml:1.15
where as mine uses the old com.datastax.oss:java-driver-core-shaded:4.5.0
Why is it working in that pom? we have the same maven listing version for com.datastax.spark:spark-cassandra-connector_2.11:2.5.0
I see it has some exclusions but none addresses the snake yaml version or any of its parent dependencies.
Is there another section of the pom file that addresses this I am missing? please advise.
My pom
<scala.compat.version>2.11</scala.compat.version>
<spark.cassandra.version>2.5.0</spark.cassandra.version>
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector_${scala.compat.version}</artifactId>
<version>${spark.cassandra.version}</version>
</dependency>
where it goes wrong
however another project is using the correct shaded version com.datastax.oss:java-driver-core-shaded:4.9.0, which eliminates the snake dependency
working pom
<scala.compat.version>2.11</scala.compat.version>
<spark.cassandra.version>2.5.0</spark.cassandra.version>
<dependency>
<artifactId>spark-cassandra-connector_${scala.compat.version}</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
<exclusion>
<artifactId>netty-all</artifactId>
<groupId>io.netty</groupId>
</exclusion>
<exclusion>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</exclusion>
</exclusions>
<groupId>com.datastax.spark</groupId>
<version>${spark.cassandra.version}</version>
</dependency>
You add an entry your <dependencyManagement> section of your POM, where you specify the version of snakeyaml that you want.
This will override all transitive version definitions of snakeyaml.
I suggest to switch to the SCC 2.5.2 (or at least 2.5.1) - there were fixes there regarding dependencies, it has driver upgraded to 4.10.0, etc. Another possibility is to use spark-cassandra-connector-assembly instead, with all dependencies included & shaded.

NoSuchMethodError: What version of Apache Xml Security do I need?

I was getting this exception
java.lang.NoSuchMethodError: org.apache.xml.security.utils.XMLUtils.decode
Then I updated my dependencies and moved on to another similar exception which I am unable to resolve for quite a while:
I am getting NoSuchMethodError when my module receives the request upon calling this method
WebServiceTemplate client = ...;
client.marshalSendAndReceive(req, new ActionCallback("http://samples/RequestOrder"));
it throws
java.lang.NoSuchMethodError: org.apache.xml.security.encryption.AbstractSerializer: method <init>()V not found
at org.apache.cxf.ws.security.wss4j.StaxSerializer.<init>(StaxSerializer.java:62)
the (at least I think) relevant part of my dependencies
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.6.15</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<version>3.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>3.3.6</version>
</dependency>
I was looking at multiple versions of org.apache.xml.security.encryption and it doesn't look like any of those versions have such method. Any idea what would be the correct combination of versions?
as a sidenote I also found this library and thought that would be helpful , but it seems it is somewhat different than aforementioned <groupId>org.apache.ws.security</groupId>
<dependency>
<groupId>org.apache.wss4j</groupId>
<artifactId>wss4j</artifactId>
<version>2.3.0</version>
<type>pom</type>
</dependency>
I had similar issue and tried possible solutions online but to no avail.
Some of the documents suggested that dependency mismatch with other dependencies is key, like here.
In relation to this exact reported error, I kept on changing the version of the below dependency and finally reached this, which was the latest version as at the time this answer was posted.
<dependency>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
<version>2.1.4</version>
</dependency>
But remember to ensure that if you have the below dependency, exclude that of xmlsec :
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
</exclusion>
</exclusions>
</dependency>

Couldn't understand managed version under Maven dependency hierarchy

In my pom.xml, I have a SikuliX Jar which has a transitive dependency on jna-platform.
As seen in below image, version 4.5.2 has overrided version 5.4.0.
But i dont understand, how this version is overrided as i have not specified any dependency for jna-platform. I had also verified that no any there dependency is fetching this jar.
Please help me understand why this is happening. Any detailed document is well appreciated.
Related dependencies:-
<dependency>
<groupId>com.sikulix</groupId>
<artifactId>sikulixapi</artifactId>
<version>2.0.4</version>
<exclusions>
<exclusion>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
</exclusion>
</exclusions>
</dependency>
Thanks
Since you were using spring boot, as suggested here (there's also the reason of this behaviour):
java.lang.NoClassDefFoundError: com/sun/jna/platform/win32/SspiUtil$ManagedSecBufferDesc #882
you can change your order of dependencies, or specify the exact version, like this:
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.4.0</version>
</dependency>
or add this property:
<jna.version>5.4.0</jna.version>

LocalTransportSender not found when using web services

I am not a big fan of web services, but sometimes you have to conform with a client interface. I have successfully generated code from the the provided WSDLs, but when I try and run the application which actually uses the generated classes, I get the following:
java.lang.ClassNotFoundException: org.apache.axis2.transport.local.LocalTransportSender
I am keeping the generated code in a separate project and have the following dependencies in my pom:
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.6.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
As stated, the jar gets generated without any issues, but when it is includes in the application that makes use of it, I get the said exception.
Any ideas?
Adding below dependency would probably should solve this problem.
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.2</version>
</dependency>
Use next dependencies , and you should not have any problem
For api axis 2
axis2-adb
For runtime
axis2-transport-local
Laxis2-transport-http

What's wrong with my Apache CXF client?

This is part of my pom.xml:
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
<scope>runtime</scope>
</dependency>
I'm trying to use Apache CXF as an implementation of JAX-WS. Everything works fine (Java code is generated from WSDL by means of org.apache.cxf:cxf-codegen-plugin:2.4.0), until execution:
java.lang.NoSuchMethodError:
javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition;
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:237)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:186)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:91)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:203)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:90)
at javax.xml.ws.Service.<init>(Service.java:56)
....
What is it about? What dependency did I miss?
You likely have a 1.5 (or older) version of wsdl4j coming from someplace else. CXF requires the 1.6.x versions.
EDIT:
Also be on the lookout for the Axis version of this jar. You can exclude it like so:
<exclusions>
<exclusion>
<artifactId>axis-wsdl4j</artifactId>
<groupId>axis</groupId>
</exclusion>
</exclusions>
This dependency is wsdl4j-1.6.2.jar, it probably does not get transitively resolved with the current set of dependencies you have.

Categories

Resources