Skip to content

读取weblog,无user-agent获取失败导致500 #21

Open
@sevck

Description

@sevck

在WeblogController里,59行:
tmpMap.put("userAgent", headerMap.get("user-agent").toString());
遇到如下数据:
{"x-real-ip":"1.1.1.1","remote-host":"2.2.2.2","accept-language":"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6","host":"test.1.dns.xxxx.cn:443","connection":"upgrade","x-forwarded-for":"3.3.3.3","x-scheme":"https","x-host":"test.1.dns.xxxx.cn:443"}
会获取失败,导致500
java.lang.NullPointerException: null at bridge.controller.WeblogController.getWeblogList(WeblogController.java:59) ~[classes!/:1.0-SNAPSHOT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_342] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_342] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_342] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_342]
添加判断:
if (headerMap.get("user-agent") == null){ tmpMap.put("userAgent", ""); }else{ tmpMap.put("userAgent", headerMap.get("user-agent").toString()); }
另,jar包fastjson等版本较老,可以升级一下:
`


org.springframework.boot
spring-boot-starter-web


org.mybatis.spring.boot
mybatis-spring-boot-starter
2.2.2


mysql
mysql-connector-java



io.netty
netty-all
4.1.42.Final

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-to-slf4j</artifactId>
        <version>2.15.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.15.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.20.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>28.2-jre</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
        <version>2.5.13</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

</dependencies>

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions