unable to perform multipart form upload using rest-assured - rest

I am trying to upload file using multipart form upload using the following rest-assured method.
given().filter(new RequestLoggingFilter(captor)).when().multiPart("metadata", new File("S:\\testdata.prop")).multiPart("file",aFileStream).post("/uploadFile").then().statusCode(200);
This throws an error that
com.fasterxml.jackson.databind.Module: Provider
com.fasterxml.jackson.datatype.joda.JodaModule could not be
instantiated.
jackson library is added to classpath.the testdata.Prop file is a properties file

You need to add jackson-databind to the classpath. If you're using Maven you can add it like this:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.2</version>
</dependency>
Also if you're using JodaTime you may need to add this dependency:
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.6.2</version>
</dependency>
REST Assured automatically tries to register all jackson modules in classpath.

Related

Sometimes SAAJMetaFactoryImpl not found is thrown

I am using OpenJDK 11 and here's my code for Getting SOAP message.
SOAPMessage message = MessageFactory.newInstance(dataDTO.getSoapVersion()).createMessage(null, new ByteArrayInputStream(encryptedResponse.getBytes()));
Sometimes it throws error:
javax.xml.soap.SOAPException: Unable to create SAAJ meta-factoryProvider com.sun.xml.internal.messaging.saaj.soap.SAAJMetaFactoryImpl not found
at javax.xml.soap.SAAJMetaFactory.getInstance(SAAJMetaFactory.java:94) ~[saaj-api-1.3.5.jar:?]
I think it is because it looking for the method under saaj-api 1.3.5 instead of saaj-impl 1.5.1
below is my POM dependency:
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>javax.xml.soap-api</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3.5</version>
</dependency>
Since javax.xml.soap-api 1.4.0 is using by some critical function, the risk is too high for removing it. Anyway can make sure my function work as expected with loading proper class ?

open api swagger-ui giving white label error page (404) after moving the project as a module in a project

I have the working project in Spring boot which was a standalone app. Now, to modularize, I have split the app and put the api in a module. Earlier the swagger-ui.html page was working, but after this, it is not working.
my pom.xml has these 2 dependencies
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
<version>1.5.1</version>
</dependency>
My Application.java has the following code
#Bean
#Profile("!prod")
public OpenAPI caffeAPIRegistry() {
return new OpenAPI()
.info(new Info().title("My Awesome API")
.description("Powering UI")
.version("v3.0.0")
.license(new License().name("google Inc.,").url("https://google.com")));
}
The pom.xml fragment for the parent project mapping
<parent>
<artifactId>API_Project</artifactId>
<groupId>com.abc</groupId>
<version>2.0.0.RELEASE</version>
</parent>
I have been searching for a long time in internet if moving api as a module might require any other change, but could not find any help.
Are the interfaces with the REST annotations in a different package? if yes then that is the issue.

Necessity for declaring RestEasy dependencies although bundled with WildFly?

According to the RESTEasy modules in WildFly documentation:
In WildFly, RESTEasy and the JAX-RS API are automatically loaded into
your deployment's classpath if and only if you are deploying a JAX-RS
application (as determined by the presence of JAX-RS annotations).
However I don't really understand this paragraph. What does it exactly mean? As an exmaple, let's say I want to use ResteasyClient in a class. My IDE tells me that I must add this dependency in the corresponding pom.xml. But then how does that go with the above quote?
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
</dependency>
My pom.xml already includes this:
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-jakartaee8-with-tools</artifactId>
<version>20.0.1.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
When looking at this BOM it looks as if the resteasy-client is already included?
My IDE tells me that I must add this dependency in the corresponding pom.xml
Yes, you must declare this dependency in your pom.xml if you use the API of it, but you only need provided-scope, because as the documentation said, it is already included in your deployment's classpath. If you use only the standard api defined in wildfly-jakartaee8, you do not need this dependency.

Vertx is not available in Quarkus vertx munity web client extesions

I tried to test the reactive web client provided by vertx munity web client.
I followed the official guide Quarkus - Getting Started with Reactive.
And added the following in dependencies.
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-mutiny-vertx-web-client</artifactId>
</dependency>
But when I injected Vertx as mentioned in the article, and got the CDI unsatisfied dependency exception. Vertx is not available.
Caused by: javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type io.vertx.mutiny.core.Vertx and qualifiers [#Default]
- java member: com.example.PostResourceClient#vertx
The complete codes are here.
You need to add the io.quarkus:quarkus-vertx dependency to your POM to activate the Vertx extension. io.smallrye.reactive:smallrye-mutiny-vertx-web-client is an external dependency that does not activate any extension.

Apache CXF RS Extensions issue in 2.4.0

I'm using Apache CXF version 2.4.0. I'm trying to create a Restful service.
The below example works in 2.3.4 but does not work in 2.4.0. What should I do different in beans config file?
When I include the below xml line in my bean config file.
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
I get the following stacktrace error:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Failed to
import bean definitions from URL
location
[classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml]
Offending resource: ServletContext
resource [/WEB-INF/beans.xml]; nested
exception is
org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from
class path resource
[META-INF/cxf/cxf-extension-jaxrs-binding.xml];
nested exception is
java.io.FileNotFoundException: class
path resource
[META-INF/cxf/cxf-extension-jaxrs-binding.xml]
cannot be opened because it does not
exist at
org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
My POM dependency is below. This will work for 2.3.4 but not for 2.4.0. Any suggestions? Is that xml extension line deprecated or included in another jar?
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<version>2.3.4</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</exclusion>
</exclusions>
</dependency>
It's no longer needed. With 2.4.x, most of the META-INF/cxf files are no longer needed and can be removed. Really, the cxf.xml one is the only one needed.
Here is the CXF information about embedding cxf inside spring in version 2.4 and above.
http://cxf.apache.org/docs/embedding-cxf-inside-spring.html