java.lang.NoClassDefFoundError: feign/Request$Body in feign while adding support for multipart/form-data - multipartform-data

I am trying to proxy multipart request via feign.
#PostMapping(value = "{pathUri1}/{pathUri2}",consumes = MediaType.MULTIPART_FORM_DATA_VALUE,produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<BaseResponse<?>> uploadFileCall(#PathVariable(value = "pathUri1") String pathUri1, #PathVariable(value = "pathUri2") String pathUri2, #RequestPart(name = "file") MultipartFile file, #RequestParam Map<Object,Object> requestParam, #RequestHeader HttpHeaders httpHeaders);
this is service call.
#Configuration
class MultipartSupportConfig {
#Autowired
ObjectFactory<HttpMessageConverters> messageConverters;
#Bean
#Primary
#Scope("prototype")
public Encoder feignFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(messageConverters));
}
}
added encoder config for multipart/form-data .
I have followed this
https://github.com/OpenFeign/feign-form
But I am getting hystrixRunTimeException which is caused because of
java.lang.NoClassDefFoundError: feign/Request$Body error.

Use feign-form-spring 3.4.1 version.
Gradle
compile(group: 'io.github.openfeign.form', name: 'feign-form-spring', version: '3.4.1')
Maven
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.4.1</version>
</dependency>
Check requirements https://github.com/OpenFeign/feign-form#requirements

According to the open-feign's github document, Please Note the feign-form's versions:
all feign-form releases before 3.5.0 works with OpenFeign 9.* versions;
starting from feign-form's version 3.5.0, the module works with OpenFeign 10.1.0 versions and greater.

The following config works for me:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<version>${feign.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
<version>${feign.version}</version>
</dependency>
Where:
<feign.version>11.0</feign.version>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>

Related

Read a csv file in Flink 1.15 using Table API

I'm doing a simple tutorial with flink + java using Table API. What I want to do is really simple - I want to read a csv file from a local filesystem, using a schema and print it out.
The way I'm doing this is this(the code below is compiled from samples from Flink's website tutorial section):
package p1;
import org.apache.flink.table.api.*;
import org.apache.flink.api.java.utils.ParameterTool;
public class CabAggregation {
public static void main(String[] args) throws Exception {
ParameterTool params = ParameterTool.fromArgs(args);
EnvironmentSettings settings = EnvironmentSettings
.newInstance()
.inBatchMode()
.build();
TableEnvironment tableEnv = TableEnvironment.create(settings);
final Schema schema = Schema.newBuilder()
.column("cab_id", DataTypes.INT())
.column("cab_plate", DataTypes.STRING())
.column("cab_make", DataTypes.STRING())
.column("cab_driver", DataTypes.STRING())
.column("active_trip", DataTypes.STRING())
.column("pickup_location", DataTypes.STRING())
.column("target_location", DataTypes.STRING())
.column("num_pass", DataTypes.INT())
.build();
tableEnv.createTemporaryTable("cabs",
TableDescriptor
.forConnector("filesystem")
.schema(schema)
.option("path", "file:///Users/virtual/Downloads/cabs.csv")
.format(FormatDescriptor.forFormat("csv").build())
.build());
Table result = tableEnv.from("cabs").select("*");
result.execute().print();
}
}
Running this gives me this:
Caused by: org.apache.flink.table.api.ValidationException: Could not find any factory for identifier 'filesystem' that implements 'org.apache.flink.table.factories.DynamicTableFactory' in the classpath.
Available factory identifiers are:
blackhole
datagen
print
Now, it seems evident that somehow CSV is not available as a factory identifier. I can't figure out why.
I'm building the project with maven.
You'll be needing these dependencies. Have you added them?
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-files</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-csv</artifactId>
<version>${flink.version}</version>
</dependency>

Report builder says Cucumber is not a valid report

I have used below code for creating html reports , this code is present in after class of Junit Runner in a cucumber framework , but am getting error saying cucumber.json is not a valid cucumber report. I am assuming that report builder is trying to get the cucumber.json even before it is created completely,
I kept code in cucumber options to create Json file
#CucumberOptions(features = "features/",
glue = { "report"},
format = {"pretty","json:target/cucumber.json"},
tags = {"#testing" }, monochrome = true)
private void generateReportForJsonFiles(File reportOutputDirectory,
List<String> jsonFiles) {
String jenkinsBasePath = "";
String buildNumber = "1";
String projectName = project.getName();
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
configuration.setParallelTesting(false);
configuration.setJenkinsBasePath(jenkinsBasePath);
configuration.setRunWithJenkins(false);
configuration.setBuildNumber(buildNumber);
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
reportBuilder.generateReports();
}
Below is the error:
File 'target/cucumber.json' is not proper Cucumber report!
you should provide a small example (MCVE) which others can use to reproduce your problem
your code snippet configuration.setParallelTesting(false) and your answer cucumber report version is <version>4.2.0</version> do not match, as the method configuration.setParallelTesting was removed in version 4.1.0
Have a look at this small working snippet (based on the few information you provided).
Assume the following structure
pom.xml
src/main/java/CreateReport.java
src/main/resources/log4j2.properties
src/test/java/TestRunner.java
src/test/java/stepdefs/StepDefinitions.java
src/test/resource/features/demo.feature
pom.xml
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<!--
info.cukes:cucumber-java:1.2.5 is quite old and has been superseded by
io.cucumber:cucumber-java see: https://mvnrepository.com/artifact/io.cucumber/cucumber-java
-->
<version.cucumber>1.2.5</version.cucumber>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
...
CreateReport.java
import java.io.File;
import java.util.Arrays;
import java.util.List;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
public class CreateReport {
private void generateReportForJsonFiles(File reportOutputDirectory, List<String> jsonFiles) {
String buildNumber = "1";
String projectName = "StackOverflow example";
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
configuration.setParallelTesting(false);
// configuration.setJenkinsBasePath(jenkinsBasePath);
configuration.setRunWithJenkins(false);
configuration.setBuildNumber(buildNumber);
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
reportBuilder.generateReports();
}
public static void main(String[] args) {
new CreateReport().generateReportForJsonFiles(new File("target/"),
Arrays.asList("target/cucumber.json"));
}
}
log4j2.properties
status = info
name = PropertiesConfig
appenders = console
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%level] %m%n
rootLogger.level = info
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
TestRunner.java
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src/test/resource/features"},
glue = {"stepdefs"},
plugin = {"json:target/cucumber.json"}
)
public class TestRunner {
}
StepDefinitions.java
package stepdefs;
import org.junit.Assert;
import cucumber.api.java.en.Given;
public class StepDefinitions {
#Given("^a successful step$")
public void aSuccessfulStep() throws Throwable {
System.out.println("a successful step");
}
#Given("^a not successful step$")
public void aNotSuccessfulStep() throws Throwable {
System.out.println("a not successful step");
Assert.fail();
}
}
demo.feature
Feature: Test cucumber reporting plugin
Scenario: Run a non failing scenario
Given a successful step
Scenario: Run a failing scenario
Given a not successful step
run the Cucumber test (this creates the target/cucumber.json file)
$ mvn clean test
run the report creator (
$ mvn exec:java -Dexec.mainClass=CreateReport
...
12:55:21 [INFO] --- exec-maven-plugin:1.6.0:java (default-cli) # cuke-test23.so ---
Dec 18, 2018 12:55:22 PM net.masterthought.cucumber.ReportParser parseJsonFiles
INFO: File 'target/cucumber.json' contains 1 features
the report is generated in target/cucumber-html-reports/overview-features.html

Spring AOP No visible constructors in class

Error: java.lang.IllegalArgumentException: No visible constructors in class org.springframework.hateoas.config.HypermediaSupportBeanDefinitionRegistrar$DefaultObjectMapperCustomizer
Mostly, I used example given in link, and the following code can be found at github repository
Annotation:
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.TYPE)
public #interface NeedTestClass {
}
Aspect:
#After("#args(NeedTestClass)")
public void afterReturningAtArgs() {
log.info("aspect: after #args {}");
}
Service:
#Slf4j
#Component
public class BusinessService {
public void logicWithAnnotatedArgs1(Child c) {
log.info("service");
}
}
Pojo (top class, not sub class):
#NoArgsConstructor // tried with or without
#NeedTestClass
public class Child {}
Test:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration
#WebAppConfiguration
#SpringBootTest
public class AopTest {
#Autowired
private BusinessService myBusinessService;
#Test
public void testAtArgsPCD() {
myBusinessService.logicWithAnnotatedArgs1(new Child());
}
I attempted to examine aop and annotated class inheritance, but it seems the first step could not be ok. I have tried #annotation() and this() PCD both ok.
EDIT:
So far I am wondering maybe the error is related with the bean loading sequence.
Your GitHub project does not even compile. Have you even tested it? First by trial and error I had to add all of these dependencies:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.alibaba.druid</groupId>
<artifactId>druid-wrapper</artifactId>
<version>0.2.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
Next, I noticed that the Maven build does not seem to start the local (127.0.0.1) database because Spring Boot says this at start-up:
(...)
2018-01-02 17:57:18.882 INFO 14480 --- [ main] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited
2018-01-02 17:57:20.007 ERROR 14480 --- [tionPool-Create] com.alibaba.druid.pool.DruidDataSource : create connection error
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:590) ~[mysql-connector-java-6.0.6.jar:6.0.6]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:57) ~[mysql-connector-java-6.0.6.jar:6.0.6]
(...)
Would you mind refactoring your GitHub project into an MCVE first before I can check on your actual problem? This way the error is not reproducible.
But having said this, I did notice something in your POM and Java files: Maybe the problem is not where you think it is. I can see that you want to use Lombok in combination with Spring AOP. According to my answer here, there are compatibility problems between AspectJ and Lombok. Maybe they also affect Spring AOP. So can you temporarily test without #Slf4j and other Lombok stuff? As soon as you will have fixed your project I can also test by myself.
Update after GitHub repo project has been repaired:
Now I can build and run your program, thanks. It seems that the parameter is somehow passed through to internal Spring classes you do not wish to target. So just modify your pointcut like this:
#After("#args(com.example.demosm.my.aop.NeedTestClass) && within(com.example.demosm..*)")

JAX-RS client returns entity of null

I have a JAX-RS service defined like this:
#Produces(MediaType.APPLICATION_JSON)
#GET
#Path("/namestartswith")
public List<ProductBrand> nameStartsWith(#QueryParam("name") String name) {
List<ProductBrand> productBrandList = productBrandService.findByNameStartsWith(name);
System.out.println("productBrandList: " + productBrandList);
return productBrandList;
}
Issuing the following URL:
http://localhost:19191/productbrand/namestartswith?name=f
produces:
{"productBrand":[{"brandImage":"ffbrand.png","description":"the brand called ff","id":"1","name":"ffbrand"},{"brandImage":"flfl.png","description":"flfl","id":"6","name":"flfl"},{"brandImage":"ffbran.png","description":"ffbr","id":"16","name":"ffbran"}]}
which means the service is working as intended.
Now I use RestEasy for client access.
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
The following code accesses the service:
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:19191/productbrand/namestartswith?name=" + name);
Response restEasyResponse = target.request(MediaType.APPLICATION_JSON).get();
log("entity: " + restEasyResponse.readEntity(new GenericType<List<ProductBrand>>() {
}););
The output is:
entity: null
Even calling restEasyResponse.getEntity() returns null. What might be wrong?
I had a similar issue and I work around it using:
restEasyResponse.readEntity(List.class)
It will return a List<Map<String, Object>> where each item represents an element of the json array.

Can't run Geb tests using HtmlUnitDriver under Maven

I am running the example Google spec, i.e:
class GoogleHomePageSpec extends GebReportingSpec {
def "first result for wikipedia search should be wikipedia"() {
given:
to GoogleHomePage
expect:
at GoogleHomePage
when:
search.field.value("wikipedia")
then:
waitFor { at GoogleResultsPage }
and:
firstResultLink.text().startsWith "Wikipedia"
when:
firstResultLink.click()
then:
waitFor { at WikipediaPage }
}
}
with the following GebSpec:
reportsDir = "target/geb-reports"
/* webdriver.*.driver system properties are set in the POM */
driver = {
new HtmlUnitDriver();
}
and the following relevant pom.xml excerpt:
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>0.7-groovy-2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.39.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gebish</groupId>
<artifactId>geb-spock</artifactId>
<version>0.9.2</version>
<scope>test</scope>
</dependency>
and it fails with the message if I run it from CLI or IDE:
First result for wikipedia search should be wikipedia(scratch.GoogleHomePageSpec) Time elapsed: 0.96 sec <<< ERROR!
geb.driver.DriverCreationException: failed to create driver from callback 'GebConfig$_run_closure1#20fcbdaf'
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:35)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections/set/ListOrderedSet
at com.gargoylesoftware.htmlunit.CookieManager.<init>(CookieManager.java:59)
at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:131)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.newWebClient(HtmlUnitDriver.java:289)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.createWebClient(HtmlUnitDriver.java:263)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:144)
at GebConfig.run_closure1(GebConfig.groovy:10)
at GebConfig.run_closure1(GebConfig.groovy)
at geb.driver.CallbackDriverFactory.getDriver(CallbackDriverFactory.groovy:29)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy:80)
at geb.driver.CachingDriverFactory.getDriver_closure3(CachingDriverFactory.groovy)
at geb.driver.CachingDriverFactory$SimpleCache.get(CachingDriverFactory.groovy:30)
at geb.driver.CachingDriverFactory.getDriver(CachingDriverFactory.groovy:79)
at geb.Configuration.createDriver(Configuration.groovy:354)
at geb.Configuration.getDriver(Configuration.groovy:343)
at geb.Browser.getDriver(Browser.groovy:105)
at geb.Browser.clearCookies(Browser.groovy:483)
at geb.Browser.clearCookiesQuietly(Browser.groovy:491)
at geb.spock.GebSpec.resetBrowser(GebSpec.groovy:45)
at geb.spock.GebSpec.cleanup(GebSpec.groovy:67)
I've checked and the commons-collection jar is present and contains the 'missing' class.
I don't get this error at all using ChromeDriver, FirefoxDriver and InternetExplorerDriver.
Unfortunately for environmental reasons I have to use HtmlUnitDriver so I'm really scratching my head about this one.
Would be grateful for any suggestions.
EDIT 1:
Have managed to run a portion of this test successfully on my Mac, the remainder times out.
But am not seeing the same errors as above (which were observed on Windows).
Resolved this problem by rebuilding the maven_repo i.e. moving the old one out of the way so maven is forced to rebuild it on the next run of the tests.
The exception no longer appears.

Resources