java.lang.NoClassDefFoundError: org/springframework/util/MultiValueMap - collections

I am using Spring-core 3.2 jar but I am getting error as
"java.lang.NoClassDefFoundError:
org/springframework/util/MultiValueMap".
MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
formData.add("xxx","xxxx");
formData.add("yyy","yyy");
formData.add("r","5");
formData.add("d","0");
I need to pass this data to HTTP post but I am getting above error. I have imported below Jars:
import org.springframework.http.converter.FormHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

try dependency
org.springframework spring-web 5.3.10

Related

openqa selenium Session Not Created Exception. Flutter Automation

I am trying to automate flutter Apk by using valuekey locators. I used following code to automate Apk. I am trying to use Appium and flutter finder for the automation.
package io.github.ashwith.flutter.example;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.appium.java_client.android.AndroidDriver;
import io.github.ashwith.flutter.FlutterFinder;
public class Flutter_Finder {
public static RemoteWebDriver driver;
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("noReset", true);
capabilities.setCapability("app", "E:\\Testsigma.apk");
capabilities.setCapability("automationName", "flutter");
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
FlutterFinder finder = new FlutterFinder(driver);
WebElement element = finder.byValueKey("incrementButton");
element.click();
}
}
When I am trying to run the code I am getting following error code.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException:
Could not start a new session.
Response code 500.
Message: An unknown server-side error occurred while processing the command.
Original error: Cannot read property 'match' of undefined
I have used following Appium java client version for this automation as my dependencies.
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.3.0</version>
</dependency>
Please help me to resolve this error.
Thank you very much!

Failed to meta-introspect annotation interface org.springframework.web.bind.annotation

error message
21:13:46,666 DEBUG AnnotationUtils:1889 - Failed to meta-introspect annotation interface org.springframework.web.bind.annotation.RequestBody: java.lang.NullPointerException
com.alibaba.dubbo.rpc.RpcException: No provider available from registry 172.16.33.23:2181 for service com.itheima.service.CheckItemService on consumer 172.16.33.29 use dubbo version 2.6.0, may be providers disabled or not registered ?
at com.alibaba.dubbo.registry.integration.RegistryDirectory.doList(RegistryDirectory.java:572)
I have checked my Dubbo annotation package and controller's import but find that is right.
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
#RestController
#RequestMapping("/checkitem")
public class CheckItemController {
#Reference
private CheckItemService checkItemService;
#RequestMapping("/add")
public Result add(#RequestBody CheckItem checkItem){
try{
checkItemService.add(checkItem);
}catch (Exception e){
e.printStackTrace();
return new Result(false, MessageConstant.ADD_CHECKITEM_FAIL);
}
return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
}
Also, my zookeeper started.
[root#localhost bin]# ./zkServer.sh start
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
And the front end request successful.
it seems that have no problems
[zk: 127.0.0.1:2181(CONNECTED) 1] ls /dubbo/com.itheima.service.CheckItemService
[consumers, configurators, routers, providers]
anyone who can give a direction?
I can almost understand where the mistake is,but I don't know what to do.
RegisteryDirectoty.class

Base class no longer working after upgrading to Spring Cloud Contract 1.2.0

I am in the process of upgrading to Spring Cloud Edgware.RELEASE, and I've got a question about how to properly set up a base class for Spring Cloud Contract tests. Following is what I have currently as a base class that works through Dalston.SR5:
import javax.servlet.Filter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc;
#RunWith(SpringRunner.class)
#ActiveProfiles("local")
#SpringBootTest(classes = {Bootstrap.class})
#DirtiesContext
public class ConsumerDrivenContractTests {
#Autowired
private WebApplicationContext applicationContext;
#Autowired
private Filter springSecurityFilterChain;
#Test
public void generateTestsFromGroovyFiles() {
}
#Before
public void setup() {
DefaultMockMvcBuilder defaultMockMvcBuilder =
MockMvcBuilders.webAppContextSetup(applicationContext).addFilter(springSecurityFilterChain);
MockMvc mockMvc = defaultMockMvcBuilder.build();
RestAssuredMockMvc.mockMvc(mockMvc);
}
}
Upon upgrading to Edgware.RELEASE, my import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc; no longer resolves, which is confusing. The Spring Cloud Contract documentation states "by default, Rest Assured 3.x is added to the classpath" (see http://cloud.spring.io/spring-cloud-static/spring-cloud-contract/1.2.0.RELEASE/single/spring-cloud-contract.html#maven-rest-assured), and the example given shows how to use Rest Assured 2.x with the <groupId>com.jayway.restassured</groupId> dependency. However, the <artifactId>spring-cloud-starter-contract-verifier</artifactId> for 1.2.0.RELEASE pulls in the <groupId>io.rest-assured</groupId> dependencies. Given the documentation, I was expecting the com.jayway... jars to be resolved.
Is my base class approach still valid upon upgrading to 1.2.0.RELEASE, and if so, do I need to explicitly add the com.jayway... dependencies to my pom.xml file? If so, it would be helpful if the documentation stated this.
By default, Rest Assured 3.x is added to the classpath. RestAssured 3.x. has imports io.restassured and they show up in your generated tests. You, in your base class have com.jayway which is RestAssured 2.x. So your generated tests require you to use io.restassured imports in your base class. So either you fix your base class to use Rest Assured 3.x or you have to provide an explicit dependency to Rest Assured 2.x. in your plugin to fix the imports in the generated tests.

Mock FileInputStream in FileReader can't work using PowerMock

I noticed that in FileReader constructor, the FileInputStream is created. So I what to Mock it in the FileReader class, but it can't work. Can anyone figure it out?
The code it like below:
package util;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest({ FileReader.class, ContentReader.class})
public class FileReaderTest {
#Test
public void testGetContent() throws Exception {
File file = PowerMockito.mock(File.class);
InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream("123".getBytes()));
PowerMockito.whenNew(InputStreamReader.class)
.withArguments(Mockito.any(FileInputStream.class)).thenReturn(isr);
Assert.assertEquals("123", ContentReader.getContent(file));
}
}
class ContentReader {
public static String getContent(File file) throws IOException {
String content = "unknown";
BufferedReader in = null;
in = new BufferedReader(new FileReader(file));
content = in.readLine();
in.close();
return content;
}
}
Shot answer - it's impossible, because to mock system classes the PowerMock should be able to modified a client class which uses system class. In your case both classes: who uses and what is used are system classes. More you can read here (it's about static calls of system classes, but same true for mocking constructor call)
Also, please check this good point: don't mock what you don't own. For you it means:
You should wrap reading data from file via util class which you can mock
Write an integration test for your util class. If ContentReader
is an util class then you shouldn't write unit test for it.

#WebServlet annotation and error 404 [duplicate]

This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 6 years ago.
First of all: I use GlassFish 3.1 + Eclipse Java EE indigo.
I want to testing cache solutions with javaee so I made a dummy app. I have a big generated database and I list, search, modify, etc some data. To do that I wrote some basic servlet and I call with GET parameters. e.g.: /app/list?page=product&pageSize=100
The ListServlet is annotated with
#WebServlet({ "/ListServlet", "/list" })
and it works like a charm, I can use both urls.
So I need some additional servlet (for search, modify). I created them and annotated the same way.
But when I type the url http://localhost/app/modify or /app/search?id=1 I get error 404.
I tried to write a very dummy helloservlet which is print a hello world message but it didn't work: error 404. I restarted the glassfish server and the computer but not helped.
What's the problem? Did I miss something?
EDIT:
the servlets are the same package uses the same imports...
Are you sure your url patterns are correct? Try something like this:
#WebServlet( name="ListServlet", displayName="ListServlet", urlPatterns = {"/list","/modify", "/search"}, loadOnStartup=1)
If you want all the patterns go into the same servlet. If not, you would have to have a different servlets for each pattern, and those servlets should be named differently I guess.
Anyway, for this kind of behaviour I would recommend using for example Restlet routing.
EDITED:
I tested it. Here you have my servlets working like a charm:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
#WebServlet(asyncSupported = false, name = "HelloServlet1", urlPatterns = {"/hello1"})
public class TestServlet extends HttpServlet {
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.write("<h2>Hello Servlet One </h2>");
out.close();
}
}
and the second one:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
#WebServlet(asyncSupported = false, name = "HelloServlet2", urlPatterns = {"/hello2"})
public class TestServlet2 extends HttpServlet {
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.write("<h2>Hello Servlet Two </h2>");
out.close();
}
}
I do call them like: http://localhost:8080/eetest/hello1 and http://localhost:8080/eetest/hello2 and they print 'Hello Servlet One' and 'Hello Servlet Two' respectivelly.
(tested on JBoss AS 7 - web profile)
I had this issue and the problem was a forgotten import statement in my servlet. Make sure your servlet is compiling correctly.

Resources