Spring Boot Custom ContextLoaderListener - resteasy

I am trying to use RestEasy with Spring Boot. I need to configure it so it uses RestEasy's SpringContextLoaderListener instead of the Spring Boot default. I tried adding the listener in the config class but I get an error saying that a Context Loader Listener already exists.
Is there a way I can do this?

Rather than trying to use RESTEasy's SpringContextLoaderListener, you should be able to get this to work by dependency on org.jboss.resteasy:rest easy-spring and importing its springmvc-resteasy.xml configuration:
package sample.resteasy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
#Configuration
#ComponentScan
#EnableAutoConfiguration(exclude=WebMvcAutoConfiguration.class)
#ImportResource("classpath:springmvc-resteasy.xml")
public class SampleResteasyApplication {
public static void main(String[] args) {
SpringApplication.run(SampleResteasyApplication.class, args);
}
}
Note that WebMvcAutoConfiguration has been disabled. This is to work around a problem with RESTEasy's SpringBeanProcessor that causes a failure when it encounters a non-public #Bean method. WebMvcAutoConfiguration declares such a method so, to get RESTEasy to work, it has to be disabled.

Related

Start Camunda instance from React

I am trying to start using camunda.
So far I have created a spring boot service in order to build an api and later use it in my react application to start a process instance. This is my spring boot code :
package com.example.camundaNewTest;
import io.camunda.zeebe.client.ZeebeClient;
import io.camunda.zeebe.client.api.response.ProcessInstanceEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import static io.camunda.zeebe.client.impl.util.VersionUtil.LOG;
#RestController
public class RestCalls {
#Qualifier("zeebeClientLifecycle")
#Autowired
private ZeebeClient client;
#CrossOrigin(origins = "http://localhost:3000")
#PostMapping("/start")
public void startInstance(#RequestHeader(value="var") String var) {
final ProcessInstanceEvent event =
client
.newCreateInstanceCommand()
.bpmnProcessId("demo")
.latestVersion()
.variables(Map.of("var", var))
.send()
.join();
LOG.info("Started instance for processDefinitionKey='{}', bpmnProcessId='{}', version='{}' with processInstanceKey='{}'",
event.getProcessDefinitionKey(), event.getBpmnProcessId(), event.getVersion(), event.getProcessInstanceKey());
}
}
This is working as expected. Now I want to do this call directly from my react app without a third service (spring). However, I can't find anything useful to achieve this. According to camunda documentation, it uses a grpc call to start the instance. So far, I have found some resources talking about react hooks (https://reactjsexample.com/a-react-hook-which-helps-you-to-deal-with-grpc-apis/) but I cannot make it work. Are there any ideas? Or similar situation that may hint the solution? Thank you!!

Not able to ignore ssl certificate using capability (CapabilityType.ACCEPT_SSL_CERTS)

Trying to run below code by disbaling ssl ccertificate using capability (capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true) via IE.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.apache.jmeter.samplers.SampleResult;
io.github.bonigarcia.wdm.WebDriverManager.iedriver().setup()
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
WebDriver driver = new InternetExplorerDriver(capabilities)
def wait = new WebDriverWait(driver, 20);
driver.get('https://google.com/');
WDS.sampleResult.sampleStart();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//input[#name='q']")));
WDS.sampleResult.sampleEnd();
ended up getting below error.
2020-10-11 09:43:21,585 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script iecONFIG, message: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: CapabilityType for class: Script63
javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: CapabilityType for class: Script63
Does anyone know how to handle SSL certificated? and run IE with headless mode?
I fail to see where do you declare the import for the CapabilityType class, you either need to add the next line:
import org.openqa.selenium.remote.CapabilityType
to the beginning of your script
or replace
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true)
with
capabilities.setCapability(org.openqa.selenium.remote.CapabilityType.ACCEPT_SSL_CERTS, true)
and I don't think you will be able to run Internet Explorer in headless mode, the only option would be running JMeter as the system service so the browser won't show up on your desktop, see Headless Execution of Selenium Tests in Jenkins article for more information if needed

Cucumber test failed : Exception in thread "main" java.lang.NoClassDefFoundError: io/cucumber/plugin/SummaryPrinter

I was trying to execute basic test from Cucumber feature file but found the error:
Exception in thread "main" java.lang.NoClassDefFoundError: io/cucumber/plugin/SummaryPrinter
Feature File:
Feature: Login Action
Scenario: Successful Login with Valid Credentials
Given User is on Home Page
When User Navigate to LogIn Page
And User enters UserName and Password
Then Message displayed Login Successfully
Scenario: Successful LogOut
When User LogOut from the Application
Then Message displayed LogOut Successfully
Test Runner File:
package test;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "Feature"
,glue={"stepdefinition"}
)
public class TestRunner {
}
I am using eclipse and have installed cucumber plugin through eclipse marketplace.
Can anyone help me to fix this issue?
package cucumberOptions;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
//#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/java/features",
glue = "stepDefinations")
public class TestRunner extends AbstractTestNGCucumberTests {
}
Just keep in mind that features, stepDefinations, are folders at the same level, also my testRunner class is inside a folder called 'cucumberOptions' which is at the same level than the other 2 folders, in my case they are inside test folder, since this is a maven like project
It looks that missing dependency of one of the jar. It's really bean hectic and cumbersome with new versions of cucumber as there are always coming with breaking changes. I also seen same error while upgrading from cucumber 5.1.3 to 5.7.0. After spending sometime i resolved it by adding below additional dependency in pom:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-plugin</artifactId>
<version>5.7.0</version>
</dependency>

Annotation issue: #PrepareForTest cannot be resolved to a type

I am quite new to Selenium Webdriver with cucumber and is facing an issue while running the Junit test. I tried searching for the resolution to this issue on different forums but didn't get anything helpful, probably since I am new to this.
Below is the code where the problem is. All and any help is appreciated.
package firstCucumber;
import org.junit.runner.*;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.*;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.*;
import org.junit.Test;
#RunWith(Cucumber.class)
#PrepareForTest(TestRunner.class)
#CucumberOptions(
features = "Feature",
glue = {"stepDefiition"}
)
public class TestRunner {
}
It says #PrepareForTest cannot be resolved to a type at the line where # PrepareForTest is written
Add powermock-core-1.6.5.jar to the build path. I faced similar issue and it got resolved once after adding this jar

How to use OSGi service reference into whole other classes?

I have one bundle Activator class and some of codes there.
I need to use #Autowired inside my bundle activator class. It is not working.
Here is my bundle Activator class,
public class ProviderActivator implements BundleActivator {
#Autowired
public TestingClass testingClass;
public void start(final BundleContext bundleContext) throws Exception {
System.out.println("bundle starter!!!!!!!!!!!!!!" +testingClass );
}
}
testingClass SOP is null. Spring context scanning added in spring-context.xml.
here my suggestion is,
the bean injected after bundleActivator class loaded.
How to prevent that? why the bean is null when startup bundle class?
Why would you even expect this to work? The activator class is instantiated by the OSGi Framework, and #Autowired is not an OSGi feature.

Resources