Tag Archives: java

OpenJDK11 failed: PKIX path building failed XXXXX

Prospect review

Because the company’s project needs, it needs to connect with Amazon IOT and send messages to Amazon IOT. It uses Amazon’s SDK. Everything seems normal. However, the test service reports an error and the local environment is normal.

Local JDK configuration:

java version "11.0.11" 2021-04-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode)

JDK configuration of test service:

openjdk version "11.0.12" 2021-07-20 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.12+7-LTS, mixed mode, sharing)

Is there a big difference?There is no big difference. Oracle jdk11 is used locally. The server uses openjdk11 because it knows why. That’s all, but the program will always report an error:

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

solve the problem

First changed a configuration

Find a link, which is a link on the official website of Oracle. The description of Oracle certificate roughly means that Oracle JDK will no longer trust the TLS certificate issued by Symantec, which is consistent with the similar plans recently announced by Google, Mozilla, apple and Microsoft. If necessary, you can bypass these restrictions by commenting out or deleting “symantec_tls” in the jdk.security.cadisttrustpolicies security attribute of the java.security configuration file.

https://blogs.oracle.com/java/post/oracles-plan-for-distrusting-symantec-tls-certificates-in-the-jdk

The above configuration is in Java_ The file home/conf/security/java.security is opened in the form of text. It is around line 1187. There is such a sentence JDK. Security. Cadistrustpolicies = Symantec_ TLS needs to be commented out and changed to the following:

#jdk.security.caDistrustPolicies=SYMANTEC_ TLS

Then, then the server still can’t, Gan!

In the middle, I made a lot of attempts, but I didn’t describe it in detail. Finally, I was surprised and did a magical operation!

Then replaced a file

In Java_ Home/lib/security/cacerts file. This file is mainly a warehouse used by JDK to store certificates, including self trusted certificates and some certificates imported by keytool. Then I used Oracle cacerts certificate to replace the file with the same name under the same path of openjdk on the server. OK, done!

Problem estimation

Through the keytool – List – keystore cacerts command to view the two files, it is found that the date of the oreclejdk is irregular and the date is relatively long, while the date of the openjdk is 2021. I don’t know if it has anything to do with this problem. If I encounter it at present, I’ll remember it first and make a note.

The typereference reported an error classnotfoundexception:

Error message

java.lang.ClassNotFoundException: com.alibaba.fastjson.TypeReference

First, I went to the mvnrepository to find the fastjson package
introduced into the common service dependency
but still reported an error

Later, in project structure, I found that the dependencies of search service are also divided into complie, runtime, test, etc. my fastjson scope is test. After I modify it to complie, it can be used normally

Solution to Tomcat’s broken pipe error

         Broken pipe means that a pipe is broken. It is simply understood that there may be an IO or network problem between Tomcat’s server and client, resulting in one end being closed. Often occurs when the verification code cannot be displayed.

        Solution: enter the Linux environment variable file configuration parameters and configure them in/etc/profile.

        Set parameters at the end of the document:    export _ JAVA_ SR_ SIGNUM=12

export _ JAVA_ SR_ Signum = 12, 12 can be replaced by 16

Note: this method may solve the symptoms but not the root cause, or it should solve the problem code, or it is the wrong connection method. It’s best to tune the JVM. I hope you can give me some advice.

[Solved] Tomcat Error: org.apache.tomcat.util.digester.Digester.fatalError Parse fatal error at line [40] column [36]

Error Messages:

org.apache.tomcat.util.digester.Digester.fatalError Parse fatal error at line [40] column [36]
org.xml.sax.SAXParseException; lineNumber: 40; columnNumber: 36; The value of attribute “password” associated with an element type “user” must not contain the ‘<‘ character.

Solution:
apache-tomcat-10.0.12\conf\tomcat-users

  <user username=”admin” password=”admin” roles=”manager-gui”/>
<user username=”robot” password=”<must-be-changed>” roles=”manager-script”/>
<user username=”tomcat” password=”admin” roles=”tomcat”/>
<user username=”both” password=”<must-be-changed>” roles=”tomcat,role1″/>
<user username=”role1″ password=”<must-be-changed>” roles=”role1″/>

Change password, e.g.
<user username=”robot” password=”admin” roles=”manager-script”/>

How to Solve JVM Common Errors: outofmemoryerror & stackoverflowerror

OutOfMemoryError

Error cause: java.lang.outofmemoryerror: Java heap space heap memory overflow
solution: adjust the size of the heap memory

// -Xms1m -Xmx10m -XX:+PrintGCDetails
		List<Object> listObject = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			System.out.println("i:" + i);
			Byte[] bytes = new Byte[1 * 1024 * 1024];
			listObject.add(bytes);
		}
		System.out.println("Added successfully...");

StackOverflowError

Cause of error: java.lang.stackoverflowerror is expressed as stack overflow, which generally occurs in recursive calls
solution: set the maximum thread call depth, which is 1m by default

//-Xss5m Set the maximum call depth
public class StackTest {
	private static int count;
	public static void count(){
		try {
			count++;
			count(); 
		} catch (Throwable e) {
			System.out.println("the maximum depth:"+count);
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
			 count();
	}
}

[Solved] ERROR org.apache.struts2.dispatcher.Dispatcher – Dispatcher initialization failed

Problem description
the newly created eclipse project cannot run JSP

the console reports an error, as shown in the figure

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
09:04:55.281 [localhost-startStop-1] ERROR org.apache.struts2.dispatcher.Dispatcher - Dispatcher initialization failed
com.opensymphony.xwork2.config.ConfigurationException: Unable to load configuration.
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) ~[xwork-core-2.3.37.jar:2.3.37]
	at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:978) ~[struts2-core-2.3.37.jar:2.3.37]
	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446) ~[struts2-core-2.3.37.jar:2.3.37]
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490) [struts2-core-2.3.37.jar:2.3.37]
	at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74) [struts2-core-2.3.37.jar:2.3.37]
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57) [struts2-core-2.3.37.jar:2.3.37]
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281) [catalina.jar:7.0.107]
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262) [catalina.jar:7.0.107]
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:106) [catalina.jar:7.0.107]
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4973) [catalina.jar:7.0.107]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5672) [catalina.jar:7.0.107]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) [catalina.jar:7.0.107]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1689) [catalina.jar:7.0.107]
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1679) [catalina.jar:7.0.107]
	at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_51]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_51]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_51]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
Caused by: com.opensymphony.xwork2.config.ConfigurationException: Action class [Action.complexAction] not found
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:486) ~[xwork-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:429) ~[xwork-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:556) ~[xwork-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295) ~[xwork-core-2.3.37.jar:2.3.37]
	at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112) ~[struts2-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264) ~[xwork-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) ~[xwork-core-2.3.37.jar:2.3.37]
	... 17 more
十月 22, 2021 9:04:55 上午 org.apache.catalina.core.StandardContext filterStart
Severe: Start filter exception
Unable to load configuration. - action - file:/F:/JavaEE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Week7/WEB-INF/classes/struts.xml:14:64
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:504)
	at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:106)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4973)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5672)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1689)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1679)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: Unable to load configuration. - action - file:/F:/JavaEE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Week7/WEB-INF/classes/struts.xml:14:64
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
	at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:978)
	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
	... 14 more
Caused by: Action class [Action.complexAction] not found - action - file:/F:/JavaEE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Week7/WEB-INF/classes/struts.xml:14:64
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:486)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:429)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:556)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295)
	at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264)
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
	... 17 more

There are many solutions to online search, such as jar package conflict in Tomcat and reinstalling tomcat, but other projects can still run before, so there is no blind operation. Some things still need to see the essence. In fact, where the problem appears has been prompted.

Caused by: com.opensymphony.xwork2.config.ConfigurationException: Action class [Action.complexAction] not found
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:486) ~[xwork-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:429) ~[xwork-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:556) ~[xwork-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:295) ~[xwork-core-2.3.37.jar:2.3.37]
	at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112) ~[struts2-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:264) ~[xwork-core-2.3.37.jar:2.3.37]
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67) ~[xwork-core-2.3.37.jar:2.3.37]

Yes, complexaction was not found in the action configuration
there is a problem with the action configuration in the struts.xml file. If you also encounter this problem, first see if there is a problem with the configuration file

Mybatis Error: The error may exist in xxxxMapper.xml [How to Solve]

After learning mybatis, this exception is reported during one-to-one mapping

### Error building SqlSession.
### The error may exist in StudentMapper.xml
### The error occurred while processing mapper_resultMap[AddressResult]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'StudentMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Address'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Address

In fact, the exception report is quite clear. This is the mapping file, that is, the code in studentmapper.xml

	<resultMap id="selectStudentResult1" type="Student">
		<id property="studId" column="id"/>
		<result property="name" column="name"/>
		<result property="email" column="email"/>
		<result property="dob" column="dob"/>
		<result property="phone" column="phone"/>
		<association property="address" resultMap="AddressResult"/>
	</resultMap>

//Note the type of the following line
	<resultMap id="AddressResult" type="Address">
		<id property="addrId" column="addr_id"/>
		<result property="street" column="street"/>
		<result property="city" column="city"/>
		<result property="state" column="state"/>
		<result property="zip" column="zip"/>
		<result property="country" column="country"/>

	</resultMap>

	<! -- This is used to test one-to-one ResultMap One-to-one mapping of better method nesting results -->
	<select id="selectStudentWithAddress1" parameterType="int" resultMap="selectStudentResult1">
		select id,name,email,dob,phone,
		street,city,state,zip,country from students s left join addresses a
		on s.addr_id = a.addr_id
		where id = #{id}
	</select>

There are also corresponding files

The reason for my error is mybatis-config.xml in the configuration file. There is no alias for address. (because the type attribute in the resultmap uses address, the alias is called address)
(the type attribute is the fully qualified name of the class. Add address)

	<typeAliases>
		<typeAlias type="Full name" alias="Student" />
<!--		<typeAlias type="Full name" alias="Address"/>-->
	</typeAliases>

In this tab, you can also use package to set the default name of all classes in a directory
(if you use package, you don’t need to add the class name)

	<typeAliases>
		<package name="Full qualified name without class name" />
	</typeAliases>

This will work properly.

[Solved] Initialization of anonymous inner class member variable causes java.lang.stackoverflowerror

Project scenario:

An abstract class A in Java needs to initialize a member variable of the same type anonymously,

public class Main {
  public static void main(String[] args) {
    new B();
  }

}

abstract class A {
   A a = new A() {//Member variables of the same type
     @Override
     void do_sth() {
       System.out.println("do nothing");
     }
   };
  abstract void do_sth();
}

class B extends A{

  @Override
  void do_sth() {
	System.out.println("doing B");
  }
}

Problem Description:

Java.lang.stackoverflowerror directly overflowed the stack


Cause analysis:

When creating object B, the anonymous inner class in object a is also created, and the inner class creates its own inner class, resulting in infinite recursion.


Solution:

Try not to use anonymous inner classes as member variables. If you want to use them, be sure to pay attention to whether they contain the possibility of infinite recursion.

error:unable to access jarfile cracker2017.jar [How to Solve]

Today, I encountered some problems when opening cracker2017.jar file. Please record it.

Command prompt opening method: press Win + R, enter CMD and enter.

First of all, you should use the absolute path to open the jar package!!!

Therefore, it is convenient to open the command prompt directly from the folder. (the file above the jar file)

On the command line, enter:

java -jar cracker2017.jar E:\Baiduwangpan\Myeclipse2017\Activation file

Java – jar the file name you want to open. Jar, and then type the path again

Note: the path is a folder above the jar file

Enter and you’ll open it! oh yeah!

oh,that’s a nice night.

[Solved] JSON parse error: Cannot deserialize instance of `java.util.ArrayList<..> out of START_OBJECT token;

JSON parse error: Cannot deserialize instance of java.util.ArrayList<com.sangfor.ngsoc.knowledge.to.UserEntity> out of START_OBJECT token;
1. problem replication
① First, configure both knowledge and auth services into eureka.

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

② The project path of auth service is:

server:
  port: 8081
  servlet.context-path: /ngso/AUTH/

③ Interface of remote auth service:

@Api(tags = "Usersheet")
@Slf4j
@Validated
@RestController
@ResponseResult
@RequestMapping("/api/v2")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/users/inner/exact")
    public PageData<UserEntity> exactPageQueryUserList(@Validated @RequestBody UserQo userQo,
                                                       @RequestParam(SessionKey.DOMAIN_ID) String domainId) {
        userQo.setDomainId(domainId);
        return userService.exactPageQueryUserList(userQo);
    }
}

④ Feign interface of knowledge service, calling the interface of remote auth service:

@FeignClient(name = "AUTH")
public interface AuthFeignService {
    @PostMapping("/ngso/AUTH/api/v2/users/inner/exact")
    PageData<UserResp> exactPageQueryUserList(
            @RequestBody UserReqDto userReqDto,
            @RequestParam(SessionKey.DOMAIN_ID) String domainId);
}

(5) calling feign interface in knowledge service:

@Override
public String addDoc() {
    List<String> userIds = new ArrayList<>();
     UserInfo userInfo = UserInfoShareHolder.getUserInfo();
    userIds.add(userInfo.getId());
    UserReqDto userReqDto = new UserReqDto(userIds);
    userReqDto.setPageNum(1);
    userReqDto.setPageSize(1);
    PageData<UserResp> pageDataApiResponse = authFeignService
        .exactPageQueryUserList(userReqDto, UserInfoShareHolder.getUserInfo().getDomainId());
}

Result error:

JSON parse error: Cannot deserialize instance of `java.util.ArrayList<com.sangfor.ngsoc.knowledge.to.UserEntity>` out of START_OBJECT token; 

2. Solutions

① First, directly call the auth service interface without using the remote service: localhost: 8081/NGSO/auth/API/V2/users/inner/exact

There are more code and message messages than the actual response data, indicating that the response data is encapsulated

{
    "code": 0,
    "message": "成功",
    "data": {
        "pageNum": 1,
        "pageSize": 1,
        "totalCount": 1,
        "data": [
            {
                "id": "fx-user-fec844b9e0dc0d80000004",
                "name": "sysadmin",
                "phone": "",
                "email": "",
                "description": "Built-in user: default platform system administrator account",
                "domainId": "fx-domain-fec833bfa0dbcc40000001",
                "projectId": " ",
                "enabled": 1,
                "createTime": "2021-10-18 15:41:17",
                "updateTime": "2021-10-21 16:35:11",
                "changeTime": "2021-10-18 16:44:37",
                "loginTime": "2021-10-21 16:35:11",
                "options": 0,
                "builtIn": 1
            }
        ]
    }
}

② View the code and add a layer of encapsulation:

@FeignClient(name = "AUTH" )
public interface AuthFeignService {
   @PostMapping("/ngso/AUTH/api/v2/users/inner/exact")
    ApiResponse<PageData<UserResp>> exactPageQueryUserList(
            @RequestBody UserReqDto userReqDto,
            @RequestParam(SessionKey.DOMAIN_ID) String domainId);
}

Idea error: (4, 28) Java: package com.alibaba.fastjson does not exist

The package has been imported through Maven in DEA, and the location of the package can also be located in idea, but error is always reported when compiling, and the package cannot be found.

Presumably, the reason is that the version of idea is incompatible with the build built by Maven

It is recommended to uninstall the idea and install it with another version of the idea. If you do not want to replace the idea, you can take the following measures.

The solution is as follows:

Hosting the build and run of idea under maven

When checked, recompilation can run normally