完成json配置文件的读取。
This commit is contained in:
parent
7dce36562c
commit
628b08e1ef
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"java.configuration.updateBuildConfiguration": "automatic",
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
"java.format.settings.url": "D:\\工作文档\\配置备份\\vscode\\eclipse-java-google-style.xml",
|
"java.format.settings.url": "E:\\工作文档\\4、配置备份\\vscode\\eclipse-java-google-style.xml",
|
||||||
"[java]": {
|
"[java]": {
|
||||||
"editor.detectIndentation": true
|
"editor.detectIndentation": true
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
"proxy_setting": {
|
"proxy_setting": {
|
||||||
"enable": true,
|
"enable": true,
|
||||||
"proxy_mode": "http",
|
"proxy_mode": "http",
|
||||||
"ip_address": "172.16.39.2",
|
"proxy_address": "172.16.39.2",
|
||||||
"port": 18080
|
"proxy_port": 18080
|
||||||
},
|
},
|
||||||
"cities": [
|
"cities": [
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-04-24 10:21:46
|
* @Date: 2022-04-24 10:21:46
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-05-10 16:16:28
|
* @LastEditTime: 2022-11-04 15:03:05
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\WeatherDisasterNotifyConfig.java
|
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\WeatherDisasterNotifyConfig.java
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
@ -11,7 +11,7 @@
|
|||||||
package com.cpic.xim.config;
|
package com.cpic.xim.config;
|
||||||
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
import com.cpic.xim.config.db.ProxySetting;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
|
||||||
@ -67,6 +67,15 @@ public class WeatherDisasterNotifyConfig
|
|||||||
this.queryInterval = queryInterval;
|
this.queryInterval = queryInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProxySetting getProxySetting()
|
||||||
|
{
|
||||||
|
return proxySetting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxySetting( ProxySetting proxySetting )
|
||||||
|
{
|
||||||
|
this.proxySetting = proxySetting;
|
||||||
|
}
|
||||||
|
|
||||||
public void setCities( Vector<City> cities )
|
public void setCities( Vector<City> cities )
|
||||||
{
|
{
|
||||||
@ -105,6 +114,9 @@ public class WeatherDisasterNotifyConfig
|
|||||||
@JsonProperty( "query_interval")
|
@JsonProperty( "query_interval")
|
||||||
private int queryInterval;
|
private int queryInterval;
|
||||||
|
|
||||||
|
@JsonProperty( "proxy_setting")
|
||||||
|
private ProxySetting proxySetting;
|
||||||
|
|
||||||
@JsonProperty( "wechat_officalaccount_url")
|
@JsonProperty( "wechat_officalaccount_url")
|
||||||
private String wechatOfficalAccountURL;
|
private String wechatOfficalAccountURL;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: Kane
|
* @Author: Kane
|
||||||
* @Date: 2022-04-25 21:45:12
|
* @Date: 2022-04-25 21:45:12
|
||||||
* @LastEditors: Kane
|
* @LastEditors: Kane
|
||||||
* @LastEditTime: 2022-05-03 22:34:37
|
* @LastEditTime: 2022-11-04 14:51:25
|
||||||
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfigManager.java
|
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\OracleConfigManager.java
|
||||||
* @Description: oracle数据库配置文件加载类
|
* @Description: oracle数据库配置文件加载类
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* @Author: Kane
|
||||||
|
* @Date: 2022-11-04 14:18:19
|
||||||
|
* @LastEditors: Kane
|
||||||
|
* @LastEditTime: 2022-11-04 15:01:58
|
||||||
|
* @FilePath: \DisasterWarning\src\main\java\com\cpic\xim\config\db\ProxySetting.java
|
||||||
|
* @Description: 用于存放代理服务器设置的类。
|
||||||
|
*
|
||||||
|
* Copyright (c) ${2022} by Kane, All Rights Reserved.
|
||||||
|
*/
|
||||||
|
package com.cpic.xim.config.db;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.*;;
|
||||||
|
|
||||||
|
/*****************************************************
|
||||||
|
* 用于存放代理服务器设置的类。
|
||||||
|
*****************************************************/
|
||||||
|
public class ProxySetting
|
||||||
|
{
|
||||||
|
public ProxySetting()
|
||||||
|
{}
|
||||||
|
|
||||||
|
public boolean isEnable()
|
||||||
|
{
|
||||||
|
return enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnable( boolean enable )
|
||||||
|
{
|
||||||
|
this.enable = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProxyMode()
|
||||||
|
{
|
||||||
|
return proxyMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxyMode( String proxyMode )
|
||||||
|
{
|
||||||
|
this.proxyMode = proxyMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProxy_address()
|
||||||
|
{
|
||||||
|
return proxy_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxy_address( String proxy_address )
|
||||||
|
{
|
||||||
|
this.proxy_address = proxy_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProxy_port()
|
||||||
|
{
|
||||||
|
return proxy_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProxy_port( int proxy_port )
|
||||||
|
{
|
||||||
|
this.proxy_port = proxy_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + (enable ? 1231 : 1237);
|
||||||
|
result = prime * result + ((proxyMode == null) ? 0 : proxyMode.hashCode());
|
||||||
|
result = prime * result + ((proxy_address == null) ? 0 : proxy_address.hashCode());
|
||||||
|
result = prime * result + proxy_port;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals( Object obj )
|
||||||
|
{
|
||||||
|
if ( this == obj)
|
||||||
|
return true;
|
||||||
|
if ( obj == null)
|
||||||
|
return false;
|
||||||
|
if ( getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
ProxySetting other = (ProxySetting) obj;
|
||||||
|
if ( enable != other.enable)
|
||||||
|
return false;
|
||||||
|
if ( proxyMode == null)
|
||||||
|
{
|
||||||
|
if ( other.proxyMode != null)
|
||||||
|
return false;
|
||||||
|
} else if ( !proxyMode.equals( other.proxyMode ))
|
||||||
|
return false;
|
||||||
|
if ( proxy_address == null)
|
||||||
|
{
|
||||||
|
if ( other.proxy_address != null)
|
||||||
|
return false;
|
||||||
|
} else if ( !proxy_address.equals( other.proxy_address ))
|
||||||
|
return false;
|
||||||
|
if ( proxy_port != other.proxy_port)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty( "enable")
|
||||||
|
private boolean enable = true;
|
||||||
|
|
||||||
|
@JsonProperty( "proxy_mode")
|
||||||
|
private String proxyMode = "http";
|
||||||
|
|
||||||
|
@JsonProperty( "proxy_address")
|
||||||
|
private String proxy_address;
|
||||||
|
|
||||||
|
@JsonProperty( "proxy_port")
|
||||||
|
private int proxy_port;
|
||||||
|
|
||||||
|
}
|
@ -6,13 +6,15 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
|||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
//import com.fasterxml.jackson.annotation.JsonIgnore;
|
//import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
public class QWeatherDisasterWarningItem {
|
public class QWeatherDisasterWarningItem
|
||||||
public QWeatherDisasterWarningItem() {
|
{
|
||||||
}
|
public QWeatherDisasterWarningItem()
|
||||||
|
{}
|
||||||
|
|
||||||
public QWeatherDisasterWarningItem(String id, String sender, Date pubTime, String title, String status,
|
public QWeatherDisasterWarningItem( String id, String sender, Date pubTime, String title,
|
||||||
String level, String severity, String severityColor, String type, String typeName, String text,
|
String status, String level, String severity, String severityColor, String type,
|
||||||
String related, String urgency, String certainty) {
|
String typeName, String text, String related, String urgency, String certainty)
|
||||||
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.pubTime = pubTime;
|
this.pubTime = pubTime;
|
||||||
@ -30,7 +32,8 @@ public class QWeatherDisasterWarningItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode()
|
||||||
|
{
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + ((certainty == null) ? 0 : certainty.hashCode());
|
result = prime * result + ((certainty == null) ? 0 : certainty.hashCode());
|
||||||
@ -51,204 +54,247 @@ public class QWeatherDisasterWarningItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals( Object obj )
|
||||||
if (this == obj)
|
{
|
||||||
|
if ( this == obj)
|
||||||
return true;
|
return true;
|
||||||
if (obj == null)
|
if ( obj == null)
|
||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if ( getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
QWeatherDisasterWarningItem other = (QWeatherDisasterWarningItem) obj;
|
QWeatherDisasterWarningItem other = (QWeatherDisasterWarningItem) obj;
|
||||||
if (certainty == null) {
|
if ( certainty == null)
|
||||||
if (other.certainty != null)
|
{
|
||||||
|
if ( other.certainty != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!certainty.equals(other.certainty))
|
} else if ( !certainty.equals( other.certainty ))
|
||||||
return false;
|
return false;
|
||||||
if (id == null) {
|
if ( id == null)
|
||||||
if (other.id != null)
|
{
|
||||||
|
if ( other.id != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!id.equals(other.id))
|
} else if ( !id.equals( other.id ))
|
||||||
return false;
|
return false;
|
||||||
if (level == null) {
|
if ( level == null)
|
||||||
if (other.level != null)
|
{
|
||||||
|
if ( other.level != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!level.equals(other.level))
|
} else if ( !level.equals( other.level ))
|
||||||
return false;
|
return false;
|
||||||
if (pubTime == null) {
|
if ( pubTime == null)
|
||||||
if (other.pubTime != null)
|
{
|
||||||
|
if ( other.pubTime != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!pubTime.equals(other.pubTime))
|
} else if ( !pubTime.equals( other.pubTime ))
|
||||||
return false;
|
return false;
|
||||||
if (related == null) {
|
if ( related == null)
|
||||||
if (other.related != null)
|
{
|
||||||
|
if ( other.related != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!related.equals(other.related))
|
} else if ( !related.equals( other.related ))
|
||||||
return false;
|
return false;
|
||||||
if (sender == null) {
|
if ( sender == null)
|
||||||
if (other.sender != null)
|
{
|
||||||
|
if ( other.sender != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!sender.equals(other.sender))
|
} else if ( !sender.equals( other.sender ))
|
||||||
return false;
|
return false;
|
||||||
if (severity == null) {
|
if ( severity == null)
|
||||||
if (other.severity != null)
|
{
|
||||||
|
if ( other.severity != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!severity.equals(other.severity))
|
} else if ( !severity.equals( other.severity ))
|
||||||
return false;
|
return false;
|
||||||
if (severityColor == null) {
|
if ( severityColor == null)
|
||||||
if (other.severityColor != null)
|
{
|
||||||
|
if ( other.severityColor != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!severityColor.equals(other.severityColor))
|
} else if ( !severityColor.equals( other.severityColor ))
|
||||||
return false;
|
return false;
|
||||||
if (status == null) {
|
if ( status == null)
|
||||||
if (other.status != null)
|
{
|
||||||
|
if ( other.status != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!status.equals(other.status))
|
} else if ( !status.equals( other.status ))
|
||||||
return false;
|
return false;
|
||||||
if (text == null) {
|
if ( text == null)
|
||||||
if (other.text != null)
|
{
|
||||||
|
if ( other.text != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!text.equals(other.text))
|
} else if ( !text.equals( other.text ))
|
||||||
return false;
|
return false;
|
||||||
if (title == null) {
|
if ( title == null)
|
||||||
if (other.title != null)
|
{
|
||||||
|
if ( other.title != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!title.equals(other.title))
|
} else if ( !title.equals( other.title ))
|
||||||
return false;
|
return false;
|
||||||
if (type == null) {
|
if ( type == null)
|
||||||
if (other.type != null)
|
{
|
||||||
|
if ( other.type != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!type.equals(other.type))
|
} else if ( !type.equals( other.type ))
|
||||||
return false;
|
return false;
|
||||||
if (typeName == null) {
|
if ( typeName == null)
|
||||||
if (other.typeName != null)
|
{
|
||||||
|
if ( other.typeName != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!typeName.equals(other.typeName))
|
} else if ( !typeName.equals( other.typeName ))
|
||||||
return false;
|
return false;
|
||||||
if (urgency == null) {
|
if ( urgency == null)
|
||||||
if (other.urgency != null)
|
{
|
||||||
|
if ( other.urgency != null)
|
||||||
return false;
|
return false;
|
||||||
} else if (!urgency.equals(other.urgency))
|
} else if ( !urgency.equals( other.urgency ))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId()
|
||||||
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId( String id )
|
||||||
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSender() {
|
public String getSender()
|
||||||
|
{
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSender(String sender) {
|
public void setSender( String sender )
|
||||||
|
{
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getPubTime() {
|
public Date getPubTime()
|
||||||
|
{
|
||||||
return pubTime;
|
return pubTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPubTime(Date pubTime) {
|
public void setPubTime( Date pubTime )
|
||||||
|
{
|
||||||
this.pubTime = pubTime;
|
this.pubTime = pubTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle()
|
||||||
|
{
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle( String title )
|
||||||
|
{
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public String getStatus()
|
||||||
|
{
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(String status) {
|
public void setStatus( String status )
|
||||||
|
{
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLevel() {
|
public String getLevel()
|
||||||
|
{
|
||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLevel(String level) {
|
public void setLevel( String level )
|
||||||
|
{
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSeverity() {
|
public String getSeverity()
|
||||||
|
{
|
||||||
return severity;
|
return severity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSeverity(String severity) {
|
public void setSeverity( String severity )
|
||||||
|
{
|
||||||
this.severity = severity;
|
this.severity = severity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSeverityColor() {
|
public String getSeverityColor()
|
||||||
|
{
|
||||||
return severityColor;
|
return severityColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSeverityColor(String severityColor) {
|
public void setSeverityColor( String severityColor )
|
||||||
|
{
|
||||||
this.severityColor = severityColor;
|
this.severityColor = severityColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType()
|
||||||
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setType( String type )
|
||||||
|
{
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTypeName() {
|
public String getTypeName()
|
||||||
|
{
|
||||||
return typeName;
|
return typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTypeName(String typeName) {
|
public void setTypeName( String typeName )
|
||||||
|
{
|
||||||
this.typeName = typeName;
|
this.typeName = typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText() {
|
public String getText()
|
||||||
|
{
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setText(String text) {
|
public void setText( String text )
|
||||||
|
{
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRelated() {
|
public String getRelated()
|
||||||
|
{
|
||||||
return related;
|
return related;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRelated(String related) {
|
public void setRelated( String related )
|
||||||
|
{
|
||||||
this.related = related;
|
this.related = related;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrgency() {
|
public String getUrgency()
|
||||||
|
{
|
||||||
return urgency;
|
return urgency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUrgency(String urgency) {
|
public void setUrgency( String urgency )
|
||||||
|
{
|
||||||
this.urgency = urgency;
|
this.urgency = urgency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCertainty() {
|
public String getCertainty()
|
||||||
|
{
|
||||||
return certainty;
|
return certainty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCertainty(String certainty) {
|
public void setCertainty( String certainty )
|
||||||
|
{
|
||||||
this.certainty = certainty;
|
this.certainty = certainty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
private String sender;
|
private String sender;
|
||||||
|
|
||||||
@JsonProperty("pubTime")
|
@JsonProperty( "pubTime")
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd\'T\'HH:mmXXX")
|
@JsonFormat( shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd\'T\'HH:mmXXX")
|
||||||
private Date pubTime;
|
private Date pubTime;
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
|
@ -19,17 +19,17 @@ import java.util.zip.GZIPInputStream;
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WeatherDisasterWarningGrabber {
|
public class WeatherDisasterWarningGrabber
|
||||||
|
{
|
||||||
/***
|
/***
|
||||||
* 从和风天气获取天气警报json字符串
|
* 从和风天气获取天气警报json字符串
|
||||||
*
|
*
|
||||||
* @param cityCode 城市或区域代码
|
* @param cityCode 城市或区域代码
|
||||||
* @return 返回警报的json字符串
|
* @return 返回警报的json字符串
|
||||||
*/
|
*/
|
||||||
public static String getWeatherDisasterWarningJSON(String queryURL,
|
public static String getWeatherDisasterWarningJSON( String queryURL, String userKey,
|
||||||
String userKey,
|
String cityCode, boolean useProxy )
|
||||||
String cityCode,
|
{
|
||||||
boolean useProxy) {
|
|
||||||
// 拼接url字符串
|
// 拼接url字符串
|
||||||
String json = "";
|
String json = "";
|
||||||
String requestURL = queryURL + "key=" + userKey + "&location=" + cityCode;
|
String requestURL = queryURL + "key=" + userKey + "&location=" + cityCode;
|
||||||
@ -41,54 +41,73 @@ public class WeatherDisasterWarningGrabber {
|
|||||||
BufferedReader bufferedReader = null;
|
BufferedReader bufferedReader = null;
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
|
|
||||||
try {
|
try
|
||||||
url = new URL(requestURL);
|
{
|
||||||
|
url = new URL( requestURL );
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod( "GET" );
|
||||||
connection.setConnectTimeout(15000);
|
connection.setConnectTimeout( 15000 );
|
||||||
connection.setReadTimeout(60000);
|
connection.setReadTimeout( 60000 );
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
// 如果responseCode为200,说明访问成功!
|
// 如果responseCode为200,说明访问成功!
|
||||||
if (connection.getResponseCode() == 200) {
|
if ( connection.getResponseCode() == 200)
|
||||||
|
{
|
||||||
// 注意,和风使用了gzip压缩响应体
|
// 注意,和风使用了gzip压缩响应体
|
||||||
inputStream = new GZIPInputStream(connection.getInputStream());
|
inputStream = new GZIPInputStream( connection.getInputStream() );
|
||||||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
bufferedReader =
|
||||||
|
new BufferedReader( new InputStreamReader( inputStream, "UTF-8" ) );
|
||||||
|
|
||||||
// 读出数据
|
// 读出数据
|
||||||
String temp = bufferedReader.readLine();
|
String temp = bufferedReader.readLine();
|
||||||
|
|
||||||
while (temp != null) {
|
while (temp != null)
|
||||||
buffer.append(temp);
|
{
|
||||||
|
buffer.append( temp );
|
||||||
|
|
||||||
temp = bufferedReader.readLine();
|
temp = bufferedReader.readLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
json = buffer.toString();
|
json = buffer.toString();
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException error) {
|
}
|
||||||
|
catch ( MalformedURLException error )
|
||||||
|
{
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
} catch (IOException error) {
|
}
|
||||||
System.out.println("读取失败!");
|
catch ( IOException error )
|
||||||
} finally {
|
{
|
||||||
if (bufferedReader != null) {
|
System.out.println( "读取失败!" );
|
||||||
try {
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if ( bufferedReader != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
bufferedReader.close();
|
bufferedReader.close();
|
||||||
} catch (IOException error) {
|
}
|
||||||
|
catch ( IOException error )
|
||||||
|
{
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputStream != null) {
|
if ( inputStream != null)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
} catch (IOException error) {
|
}
|
||||||
|
catch ( IOException error )
|
||||||
|
{
|
||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection != null) {
|
if ( connection != null)
|
||||||
|
{
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,10 +122,11 @@ public class WeatherDisasterWarningGrabber {
|
|||||||
* @return 返回 QWeatherDisasterWarning 对象。
|
* @return 返回 QWeatherDisasterWarning 对象。
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static QWeatherDisasterWarning convertWeatherDisasterWarning(String json)
|
public static QWeatherDisasterWarning convertWeatherDisasterWarning( String json )
|
||||||
throws IOException {
|
throws IOException
|
||||||
|
{
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
QWeatherDisasterWarning warning = mapper.readValue(json, QWeatherDisasterWarning.class);
|
QWeatherDisasterWarning warning = mapper.readValue( json, QWeatherDisasterWarning.class );
|
||||||
|
|
||||||
return warning;
|
return warning;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user