SwaggerContextService class not found in swagger-jersey2-jaxrs maven artifect - jax-rs

I have multiple Resource class and i don't know if i can use #SwaggerDefinition in all of them so i am trying to write a custom bootstrap servlet
I am fallowing the example in the fallowing link
Bootstrap for swagger-jersery2
and i am not able to find SwaggerContextService class in any package .
So i tried
BeanConfig beanConfig = new BeanConfig();
beanConfig.configure(swagger);
even that is not working
My maven dependency looks like this
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
can some one help me with this

It looks like you are using a much older version of swagger. SwaggerContextService was added in 1.5.7 and the latest stable version is 1.5.13.

Related

Extent Report plugin not working with testng + cucumber

I have a complex problem, please read -
I wanted to run the extent report with my framework which is created using cucumber, testng and java.
I am running the testng file to run the test class file which will eventually run the #CucumberOptions and features added in it.
My test class is extended with AbstractTestNGCucumberTests to support testng with cucumber.
Now everything is working fine. basic testng report is getting generated.
note : I am running some tests parallel and they are also working fine.
Now i wanted to implement the extent report in my framework. Can you tell me how to do it using plugin which which add the logs same as the cucumber statement added in the feature file.
ps : I have gone through some link which shows me how to run the extent report with junit using #AfterClass, but how to use this with testng.
What I have tried -
libraries used - com.aventstack --> extentreports and com.vimalselvam --> cucumber-extentsreport
Error - cucumber.runtime.CucumberException: Couldn't load plugin class: com.vimalselvam.cucumber.ExtentCucumberFormatter
used plugin - plugin = {"com.vimalselvam.cucumber.ExtentCucumberFormatter:output/report.html"}
and code added under #AfterTest is : Reporter.loadXMLConfig(new File("xml path")
PLEASE HELP !!!
I wanted to generate extent report which will also support parallel execution.
If you want to run test cases in parallel and want to have stable extent report, please go for cucumber 4.x.x version and there are 2 ways of implementing extent report in Cucumber
1. Using Cucumber-JVM 4 adapter for Extent Framework(extentreports-cucumber4-adapter) & below are the steps to implement - (Beauty - You do not need to write any code any where to generate report this way except from setting adapter in runner below)
Add adapter dependency under POM.XML
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports-cucumber4-adapter</artifactId>
<version>1.0.6</version>
</dependency>
Add the com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter plugin to the runner.
#RunWith(Cucumber.class)
#CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"})
public class RunCukesTest {
// ..
}
Report Output Directory - ../Project Directory/test-output/HtmlReport
2. Adding aventstack dependency under POM.XML
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.5</version>
</dependency>
In this workflow, Do not Add the com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter plugin to the runner.
I assume you are using cucumber-extentsreport.*.jar as dependency.
You must specify the extent properties #beforesuite method.
ExtentProperties extentProperties = ExtentProperties.INSTANCE;
extentProperties.setReportPath();
you will also need to add plugin - com.cucumber.listener.ExtentCucumberFormatter:

Cannot resolve BasicConfigurator class on Log4j-core 2.3

I'm trying to use log4j on my selenium testing and I use maven to import log4j in my project. By going to mvnrepository.com I searched for apache log4j and added the Apache log4j 1.2.17 in my project but there was around 50 artifact missing errors displayed. I checked back to mvnrepository, It has a note that the log4j 1.2.17 was moved to New Group: org.apache.logging.log4j and New Artifact: log4j-core.
I added the Log4j-core 2.3 dependency on my maven project but the BasicConfigurator class cannot be resolved. I search for the class list of Log4j-core 2.3 and found out that the BasicConfigurator class is not part of the package. Only the Log4j 1.2.17 has this class.
How can I successfully import the BasicConfigurator class in my maven project? What Dependency do I need?
Thanks!
This will work in log4j2-
ConfigurationSource configSource = new ConfigurationSource(logConfigurationStream);
Configurator.initialize(null, configSource);
or you can make a use of Logger context by setting the configlocation in the following way-
LoggerContext context = (LoggerContext)LogManager.getContext(false);
context.setConfigLocation(new File(//log4j2.xmlPath).toURI());

Apache CXF + JavaFX No conduit initiator was found for the namespace

I'm triying to run a JavaFX Rest client using CXF. A very simple test. When I try to get an URL I get the org.apache.cxf.BusException: No conduit initiator was found for the namespace http://cxf.apache.org/transports/http. I took a look at some related questions here, but no luck. Any help would be appreciated.
Then only maven dependency I added was cxf-rt-rs-client 3.1.0
The code is:
WebClient client = WebClient.create("http://www.stackoverflow.com");
client.type("text/html").accept("text/html");
System.out.println(client.get());
Stacktrace:
Caused by: org.apache.cxf.BusException: No conduit initiator was found for the namespace http://cxf.apache.org/transports/http.
at org.apache.cxf.bus.managers.ConduitInitiatorManagerImpl.getConduitInitiator(ConduitInitiatorManagerImpl.java:110)
at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:104)
at org.apache.cxf.endpoint.UpfrontConduitSelector.selectConduit(UpfrontConduitSelector.java:77)
at org.apache.cxf.message.ExchangeImpl.getConduit(ExchangeImpl.java:159)
at org.apache.cxf.interceptor.MessageSenderInterceptor.getConduit(MessageSenderInterceptor.java:71)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.jaxrs.client.AbstractClient.doRunInterceptorChain(AbstractClient.java:624)
at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1100)
The shading overwrites bus-extension.txt file. Programmatically your can fix it by initializing it.
void initializeCxf() {
final Bus defaultBus = BusFactory.getDefaultBus();
final ConduitInitiatorManager extension = defaultBus.getExtension(ConduitInitiatorManager.class);
extension.registerConduitInitiator("http://cxf.apache.org/transports/http", new HTTPTransportFactory());
}
Based on the comment by #hba you can also try following in case the above does not work
extension.registerConduitInitiator("http://cxf.apache.org/transports/http", new HTTPTransportFactory(defaultBus));
You are fine with your Maven dependencies.
Client construction looks a bit off per CXF 3.x guides, wherein JAX-RS 2.0 is supported.
See AX-RS 2.0 Client API.
Try this code:
WebTarget target = ClientBuilder.newClient().target("http://stackoverflow.com/");
Response response = target.request().get();
System.out.println(response.getEntity().getClass().getName());
Using this code, you will learn the response entity is an input stream .. a sequence of characters being the HTML content of the StackOverflow home page.
If you're feeling adventurous, and to demonstrate I'm not a charlatan, add the following dependency to your POM:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
and then attempt this:
WebTarget target = ClientBuilder.newClient().target("http://stackoverflow.com/");
System.out.println(IOUtils.toString((InputStream) target.request().get().getEntity(), "UTF-8"));
You will be rewarded with a textual rendering (on standard output) of the StackOverflow home page – equivalent to performing a "view source" operation in your browser.
I don't know what your ultimate goal is, but if you're attempting to build anything useful from information on the StackExchange network, I suggest use of their APIs documented here.
Best of luck!
I got the same exception when using Apache CXF REST client in JavaFX project. The code is below:
MyClass rest = (MyClass) JAXRSClientFactory.create(endpoint, MyClass.class, Collections.singletonList(new JacksonJsonProvider()));
System.out.println("Service health: " + rest.health());
A test with plain Java project works fine with the same code and same dependencies. It is apparently a conflict between JavaFX and Apache CXF. I am trying to figure out why.
If you guys already solved this issue, that should be great to update this thread, which is the only result on Google search.
Updated solution:
After a while, I found that the default Maven project does not include enough the dependencies in the plugin "maven-dependency-plugin". I tried to add more packages in the list but still not work. So the final solution is in this thread: How to package an Apache CXF application into a monolithic JAR with the Maven "shade" plugin. Shade plugin is much better and works.

java.lang.NoSuchMethodError: org.apache.xml.security.encryption.XMLCipher.martial(Document;ReferenceList;)

I m trying to encrypt my XMl with this call:
XMlCipher.martial(Document context,ReferenceList referenceList)
for this the Project is referencing the xmlsec-1.5.3.jar
I'm able to build and deploy the code successfully on weblogic server , but post execution I'm getting the below error in logs.
Caused by: java.lang.NoSuchMethodError:
org.apache.xml.security.encryption.XMLCipher.martial(Lorg/w3c/dom/Document;Lorg/apache/xml/security/encryption/ReferenceList;)Lorg/w3c/dom/Element;
at com.ally.util.encryption.EncryptionUtil.generateEncryptedXML(EncryptionUtil.java:381)
at com.ally.util.encryption.EncryptionUtil.getEnryptedXMLDocument(EncryptionUtil.java:443)
at com.ally.partner.fis.acctinq.FISSoapHandler.getFISEncryptedHeader(FISSoapHandler.java:154)
This kind of error is ALWAYS caused by having more than one reference of the XMlCipher on your classpath. It could be a duplicate xmlsec.jar or another instance of the XMlCipher in a different jar.
You have a few options to debug the problem:
Edit your war file to remove the duplicate jar and/or different version of the XMlCipher class
Connect to your weblogic managed server with jconsole and look at the classpath. See if you notice another instance of the xmlsec.jar being included
You may need to tell weblogic to prefer the instance of the class that lives within your .war/.ear file by specifying the following in your weblogic.xml:
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.apache.xml.security.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
See the docs for more details and similar questions like: Weblogic 10.3.1.0 is using com.bea.core.apache.commons.net_1.0.0.0_1-4-1.jar... I want to use commons-net-2.0.jar from my code
I realize you didn't mention the use of Maven or SoapUI, but I was receiving a similar exception (java.lang.NoSuchMethodError: org.apache.xml.security.encryption.XMLCipher.setSecureValidation) when attempting to use the soapui-maven-plugin and wanted to post my solution to hopefully help.
The fix for me was to add an xml-security dependency to the soapui-maven-plugin inside the pom.xml like so:
<!-- To run, enter this command from the module directory: mvn soapui:test -->
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.1.1</version>
<dependencies>
<dependency>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
<version>1.5.2</version>
</dependency>
</dependencies>
<configuration>
<projectFile>src/test/soap-ui/your-soapui-xml-file.xml</projectFile>
</configuration>
</plugin>
</plugins>
In my case, I didn't have an xml security dependency anywhere else in my project.
In other cases, it seems like some may be experiencing this error due to having multiple xml security dependencies throughout their project (and they are conflicting, like one answer is already alluding to). So, if the above fix doesn't work for you in that scenario, you may need to look into which dependencies in your project are including xml security and deciding which one you want to include and which one you want to exclude (e.g. using Maven's exclusion or provided scope markings in the given pom).

Single deployment for all test cases in Arquillian

We are using arquillian-junit-container 1.0.0 final version for Junit Test.
We have so many test classes and every test class as #Deployment method so when i run all test together then its creating issue of memory and performance.
Can anyone help me to sort out this issue by telling how we can avoid multiple deployment for each single class. How we can achive Single deployment for all test cases in Arquillian?
You can't, officially, yet.
The JIRA issue ARQ-197 was created to support running multiple tests classes against a single deployment. In 2010! If you want this feature, please vote for it.
This is Arquillian's most voted for issue. It's currently slated for version 2.0.0.CR1, which might be the next version, but I can't find a roadmap / release plan anywhere which confirms this.
In the meantime, there is the Arquillian Suite Extension (latest incarnation is here). It's not official, and so there are limitations, but the original codebase was written by one of the Arquillian core developers to prove they could eventually support JUnit suites. The issue to make this support official is here and is Arquillian's second-most voted issue.
I think you're asking why does Arquillian need to deploy a new war for each test class when you run the test. I have the deployment method as Petr Mensik describes, but each test class will still deploy in it's own war when you run the tests. Putting it in the super class only simplifies the code from a less lines perspective. It will mean that every test class that is sub class will have the same deployment. That means your deployment will be the super set of dependencies, and thus much larger than doing it individually. I think it's easier to manage, and worth the price especially with larger projects.
To answer your question, it looks like you will not be able to group your tests and deploy one war to test until version 2.0 (due out at the end of this year?).
Why should you have deployment method in every class?I use Arquillian for functional testing with Drone and Graphene and I have one base class with deployment method, initialization of Selenium Web Driver, few utils methods and my every other test class is just extending this class and reusing my Web Driver instance.
I don't see why shouldn't this work in your case (or even without extending the base class).
Ok, this is how it looks
public class WebDriverTest extends Arquillian { //I am using TestNG
#Drone
protected WebDriver driver;
#ArquillianResource
private URL contextRoot;
#Deployment(testable = false) //functional tests cannot run in container
public static WebArchive createDeployment() {
File archive = new File("target/myApp.war");
ShrinkWrap.createFromZipFile(WebArchive.class, archive);
}
}
public class TestClass extends WebDriverTest {
#Test
public void test1() {}
#Test
public void test2() {}
}
Everything is working fine here. Also make sure that you have right Maven dependencies, these has to be present in order to run functional tests (then make dependency for anything you need from these BOMs)
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.selenium</groupId>
<artifactId>selenium-bom</artifactId>
<version>${selenium.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${arquillian-core.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-drone-bom</artifactId>
<version>${arquillian-drone.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
EDIT
Ok, so according to this JIRA you won't see this feature in Arquillian until version 2.0.0.CR1. So the code I mentioned above is the best you can get right now:-)