我有两个申请。第一个是python脚本,它从一些文件中读取JSON数据,对于每一行(JSON对象),它将整行发送到第二个应用程序。
第二个应用程序是一个spring boot API,它接收JSON行,执行一些业务逻辑并返回带有额外信息的JSON行。
对于某些JSON行,spring boot API不会收到整个JSON。
以下是调用API的python代码
def getNewMessage(self, message):
s = Session()
req = Request("POST", LOCMOJI_API, data=message)
prepared = req.prepare()
res = s.send(prepared)
if res.status_code == 200:
return res.text
return ""
这是Spring应用程序控制器,它接收消息并处理它。
@RestController
public class MyController {
@Autowired
private SomeService someService;
@Autowired
private AnotherService anotherService;
@RequestMapping(value = { "/detect/" }, method = { RequestMethod.POST })
public @ResponseBody String detect(@RequestBody String jsLine) {
System.err.println("------------------------------------------");
System.err.println(jsLine);
System.err.println("------------------------------------------");
// Do some business here
return "";
}
}
以下JSON将在spring API端被删除。
{
"body": "RT @MoslawiInsights: #WATCH: Video shows Mosul's Jisr al-Rabi' (fourth Bridge) and Mosul's West coast including the districts of al-Maleya…",
"gender": "unknown",
"retweetCount": 1,
"generator": {
"displayName": "Twitter Web Client",
"link": "http://twitter.com"
},
"sentiment": "neu",
"twitter_filter_level": "low",
"postedTime": "2017-01-10T00:21:47.000Z",
"favoritesCount": 0,
"object": {
"body": "#WATCH: Video shows Mosul's Jisr al-Rabi' (fourth Bridge) and Mosul's West coast including the districts of al-Male… ",
"verb": "post",
"generator": {
"displayName": "Twitter Ads",
"link": ""
},
"twitter_filter_level": "low",
"favoritesCount": 0,
"object": {
"postedTime": "2017-01-10T00:13:54.000Z",
"objectType": "note",
"link": "http://twitter.com/MoslawiInsights/statuses/818566491515678720",
"id": "object:search.twitter.com,2005:818566491515678720",
"summary": "#WATCH: Video shows Mosul's Jisr al-Rabi' (fourth Bridge) and Mosul's West coast including the districts of al-Male… "
},
"actor": {
"followersCount": 60926,
"preferredUsername": "MoslawiInsights",
"friendsCount": 90,
"displayName": "Mohammed",
"links": [{
"rel": "me"
}],
"twitterTimeZone": "Pacific Time (US & Canada)",
"favoritesCount": 136,
"statusesCount": 39956,
"summary": "Mouslawi | مصلاوي",
"languages": ["en"],
"utcOffset": "-28800",
"link": "http://www.twitter.com/MoslawiInsights",
"location": {
"displayName": "مقر قيادة الموساد | Mossad HQ",
"objectType": "place"
},
"id": "id:twitter.com:462293420",
"verified": false,
"listedCount": 91,
"postedTime": "2012-01-12T23:01:41.000Z",
"image": "",
"objectType": "person"
},
"twitter_lang": "en",
"twitter_entities": {
"symbols": [],
"user_mentions": [],
"hashtags": [{
"indices": [0, 6],
"text": "WATCH"
}],
"urls": [{
"indices": [117, 140],
"url": "",
"expanded_url": "",
"display_url": "twitter.com/i/web/status/8…"
}]
},
"long_object": {
"body": "#WATCH: Video shows Mosul's Jisr al-Rabi' (fourth Bridge) and Mosul's West coast including the districts of al-Maleya and al-Jawsaq ",
"display_text_range": [0, 131],
"twitter_extended_entities": {
"media": [{
"expanded_url": "",
"sizes": {
"small": {
"h": 191,
"resize": "fit",
"w": 340
},
"large": {
"h": 576,
"resize": "fit",
"w": 1024
},
"medium": {
"h": 338,
"resize": "fit",
"w": 600
},
"thumb": {
"h": 150,
"resize": "crop",
"w": 150
}
},
"url": "",
"media_url_https": "http_link",
"video_info": {
"aspect_ratio": [16, 9],
"duration_millis": 115440,
"variants": [{
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/1280x720/buUgbb_U8sVQK-Ij.mp4",
"bitrate": 2176000,
"content_type": "video/mp4"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/pl/XuPg7S0yg9YOWlo-.m3u8",
"content_type": "application/x-mpegURL"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/pl/XuPg7S0yg9YOWlo-.mpd",
"content_type": "application/dash+xml"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/640x360/duBhSamczOIc0ZAB.mp4",
"bitrate": 832000,
"content_type": "video/mp4"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/320x180/sHYQewgSXlhhI_KV.mp4",
"bitrate": 320000,
"content_type": "video/mp4"
}]
},
"display_url": "pic.twitter.com/qQfjYKelXu",
"id_str": "818564172929581056",
"indices": [132, 155],
"type": "video",
"id": 818564172929581000,
"media_url": "http://pbs.twimg.com/amplify_video_thumb/818564172929581056/img/7TiW8IO73UgkTO9y.jpg"
}]
},
"twitter_entities": {
"symbols": [],
"media": [{
"expanded_url": "https://twitter.com/MoslawiInsights/status/818566491515678720/video/1",
"sizes": {
"small": {
"h": 191,
"resize": "fit",
"w": 340
},
"large": {
"h": 576,
"resize": "fit",
"w": 1024
},
"medium": {
"h": 338,
"resize": "fit",
"w": 600
},
"thumb": {
"h": 150,
"resize": "crop",
"w": 150
}
},
"url": "",
"media_url_https": "https://pbs.twimg.com/amplify_video_thumb/818564172929581056/img/7TiW8IO73UgkTO9y.jpg",
"video_info": {
"aspect_ratio": [16, 9],
"duration_millis": 115440,
"variants": [{
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/1280x720/buUgbb_U8sVQK-Ij.mp4",
"bitrate": 2176000,
"content_type": "video/mp4"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/pl/XuPg7S0yg9YOWlo-.m3u8",
"content_type": "application/x-mpegURL"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/pl/XuPg7S0yg9YOWlo-.mpd",
"content_type": "application/dash+xml"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/640x360/duBhSamczOIc0ZAB.mp4",
"bitrate": 832000,
"content_type": "video/mp4"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/320x180/sHYQewgSXlhhI_KV.mp4",
"bitrate": 320000,
"content_type": "video/mp4"
}]
},
"display_url": "pic.twitter.com/qQfjYKelXu",
"id_str": "818564172929581056",
"indices": [132, 155],
"type": "video",
"id": 818564172929581000,
"media_url": "http://pbs.twimg.com/amplify_video_thumb/818564172929581056/img/7TiW8IO73UgkTO9y.jpg"
}],
"hashtags": [{
"indices": [0, 6],
"text": "WATCH"
}],
"user_mentions": [],
"urls": []
}
},
"link": "http://twitter.com/MoslawiInsights/statuses/818566491515678720",
"provider": {
"displayName": "Twitter",
"link": "http://www.twitter.com",
"objectType": "service"
},
"display_text_range": [0, 140],
"postedTime": "2017-01-10T00:13:54.000Z",
"id": "tag:search.twitter.com,2005:818566491515678720",
"objectType": "activity"
},
"actor": {
"followersCount": 217,
"preferredUsername": "blooddragon911",
"friendsCount": 284,
"displayName": "bloodwolf911",
"links": [{
"rel": "me"
}],
"favoritesCount": 19009,
"statusesCount": 28783,
"summary": "oooh (-_-) I'm a scary socialist!! I tweet about social justice, but i also tweet other things that interest me, things i 'm passionate about, and i love Anime",
"languages": ["en"],
"link": "http://www.twitter.com/blooddragon911",
"location": {
"displayName": "Shangri La ",
"objectType": "place"
},
"id": "id:twitter.com:714289549908832256",
"verified": false,
"listedCount": 117,
"postedTime": "2016-03-28T06:14:34.379Z",
"image": "https://pbs.twimg.com/profile_images/714290288882278401/oJ1EyzcD_normal.jpg",
"objectType": "person"
},
"twitter_lang": "en",
"twitter_entities": {
"symbols": [],
"user_mentions": [{
"indices": [3, 19],
"id_str": "462293420",
"screen_name": "MoslawiInsights",
"id": 462293420,
"name": "Mohammed"
}],
"hashtags": [{
"indices": [21, 27],
"text": "WATCH"
}],
"urls": []
},
"verb": "share",
"link": "http://twitter.com/blooddragon911/statuses/818568473873772545",
"provider": {
"displayName": "Twitter",
"link": "http://www.twitter.com",
"objectType": "service"
},
"gnip": {
"klout_profile": {
"link": "http://klout.com/user/id/159877818884456090",
"topics": [{
"displayName": "Middle East",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/7076043128808508468",
"id": "7076043128808508468"
}, {
"displayName": "Iraq",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/7895679606907690580",
"id": "7895679606907690580"
}, {
"displayName": "International Heads of State",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/10000000000000018360",
"id": "10000000000000018360"
}, {
"displayName": "Turkey",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/8055202137854805987",
"id": "8055202137854805987"
}, {
"displayName": "Syria",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/4870724842089262213",
"id": "4870724842089262213"
}, {
"displayName": "Syria",
"topic_type": "interest",
"score": 1,
"link": "http://klout.com/topic/id/4870724842089262213",
"id": "4870724842089262213"
}, {
"displayName": "Twitter",
"topic_type": "interest",
"score": 0.93,
"link": "http://klout.com/topic/id/10000000000000008253",
"id": "10000000000000008253"
}, {
"displayName": "Middle East",
"topic_type": "interest",
"score": 0.91,
"link": "http://klout.com/topic/id/7076043128808508468",
"id": "7076043128808508468"
}, {
"displayName": "Iraq",
"topic_type": "interest",
"score": 0.89,
"link": "http://klout.com/topic/id/7895679606907690580",
"id": "7895679606907690580"
}],
"klout_user_id": "159877818884456090"
},
"klout_score": 44,
"matching_rules": [{
"tag": "mosulenglishpart120161201",
"id": 804313992667787300
}],
"profileLocations": [{
"displayName": "La Plata, Buenos Aires, Argentina",
"objectType": "place",
"geo": {
"type": "point",
"coordinates": [-57.95453, -34.92145]
},
"address": {
"country": "Argentina",
"region": "Buenos Aires",
"subRegion": "Partido de La Plata",
"countryCode": "AR",
"locality": "La Plata"
}
}]
},
"id": "tag:search.twitter.com,2005:818568473873772545",
"objectType": "activity"
}
以下是来自弹簧控制器的打印声明的结果
{
"body": "RT @MoslawiInsights: #WATCH: Video shows Mosul's Jisr al-Rabi' (fourth Bridge) and Mosul's West coast including the districts of al-Maleya…",
"gender": "unknown",
"retweetCount": 1,
"generator": {
"displayName": "Twitter Web Client",
"link": "http://twitter.com"
},
"sentiment": "neu",
"twitter_filter_level": "low",
"postedTime": "2017-01-10T00:21:47.000Z",
"favoritesCount": 0,
"object": {
"body": "#WATCH: Video shows Mosul's Jisr al-Rabi' (fourth Bridge) and Mosul's West coast including the districts of al-Male… ",
"verb": "post",
"generator": {
"displayName": "Twitter Ads",
"link": ""
},
"twitter_filter_level": "low",
"favoritesCount": 0,
"object": {
"postedTime": "2017-01-10T00:13:54.000Z",
"objectType": "note",
"link": "http://twitter.com/MoslawiInsights/statuses/818566491515678720",
"id": "object:search.twitter.com,2005:818566491515678720",
"summary": "#WATCH: Video shows Mosul's Jisr al-Rabi' (fourth Bridge) and Mosul's West coast including the districts of al-Male… "
},
"actor": {
"followersCount": 60926,
"preferredUsername": "MoslawiInsights",
"friendsCount": 90,
"displayName": "Mohammed",
"links": [{
"rel": "me"
}],
"twitterTimeZone": "Pacific Time (US & Canada)",
"favoritesCount": 136,
"statusesCount": 39956,
"summary": "Mouslawi | مصلاوي",
"languages": ["en"],
"utcOffset": "-28800",
"link": "http://www.twitter.com/MoslawiInsights",
"location": {
"displayName": "مقر قيادة الموساد | Mossad HQ",
"objectType": "place"
},
"id": "id:twitter.com:462293420",
"verified": false,
"listedCount": 91,
"postedTime": "2012-01-12T23:01:41.000Z",
"image": "https://pbs.twimg.com/profile_images/815445760690962432/1QZO4C8W_normal.jpg",
"objectType": "person"
},
"twitter_lang": "en",
"twitter_entities": {
"symbols": [],
"user_mentions": [],
"hashtags": [{
"indices": [0, 6],
"text": "WATCH"
}],
"urls": [{
"indices": [117, 140],
"url": "",
"expanded_url": "https://twitter.com/i/web/status/818566491515678720",
"display_url": "twitter.com/i/web/status/8…"
}]
},
"long_object": {
"body": "#WATCH: Video shows Mosul's Jisr al-Rabi' (fourth Bridge) and Mosul's West coast including the districts of al-Maleya and al-Jawsaq",
"display_text_range": [0, 131],
"twitter_extended_entities": {
"media": [{
"expanded_url": "https://twitter.com/MoslawiInsights/status/818566491515678720/video/1",
"sizes": {
"small": {
"h": 191,
"resize": "fit",
"w": 340
},
"large": {
"h": 576,
"resize": "fit",
"w": 1024
},
"medium": {
"h": 338,
"resize": "fit",
"w": 600
},
"thumb": {
"h": 150,
"resize": "crop",
"w": 150
}
},
"url": "",
"media_url_https": "https://pbs.twimg.com/amplify_video_thumb/818564172929581056/img/7TiW8IO73UgkTO9y.jpg",
"video_info": {
"aspect_ratio": [16, 9],
"duration_millis": 115440,
"variants": [{
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/1280x720/buUgbb_U8sVQK-Ij.mp4",
"bitrate": 2176000,
"content_type": "video/mp4"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/pl/XuPg7S0yg9YOWlo-.m3u8",
"content_type": "application/x-mpegURL"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/pl/XuPg7S0yg9YOWlo-.mpd",
"content_type": "application/dash+xml"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/640x360/duBhSamczOIc0ZAB.mp4",
"bitrate": 832000,
"content_type": "video/mp4"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/320x180/sHYQewgSXlhhI_KV.mp4",
"bitrate": 320000,
"content_type": "video/mp4"
}]
},
"display_url": "pic.twitter.com/qQfjYKelXu",
"id_str": "818564172929581056",
"indices": [132, 155],
"type": "video",
"id": 818564172929581000,
"media_url": "http://pbs.twimg.com/amplify_video_thumb/818564172929581056/img/7TiW8IO73UgkTO9y.jpg"
}]
},
"twitter_entities": {
"symbols": [],
"media": [{
"expanded_url": "https://twitter.com/MoslawiInsights/status/818566491515678720/video/1",
"sizes": {
"small": {
"h": 191,
"resize": "fit",
"w": 340
},
"large": {
"h": 576,
"resize": "fit",
"w": 1024
},
"medium": {
"h": 338,
"resize": "fit",
"w": 600
},
"thumb": {
"h": 150,
"resize": "crop",
"w": 150
}
},
"url": "",
"media_url_https": "https://pbs.twimg.com/amplify_video_thumb/818564172929581056/img/7TiW8IO73UgkTO9y.jpg",
"video_info": {
"aspect_ratio": [16, 9],
"duration_millis": 115440,
"variants": [{
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/1280x720/buUgbb_U8sVQK-Ij.mp4",
"bitrate": 2176000,
"content_type": "video/mp4"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/pl/XuPg7S0yg9YOWlo-.m3u8",
"content_type": "application/x-mpegURL"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/pl/XuPg7S0yg9YOWlo-.mpd",
"content_type": "application/dash+xml"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/640x360/duBhSamczOIc0ZAB.mp4",
"bitrate": 832000,
"content_type": "video/mp4"
}, {
"url": "https://video.twimg.com/amplify_video/818564172929581056/vid/320x180/sHYQewgSXlhhI_KV.mp4",
"bitrate": 320000,
"content_type": "video/mp4"
}]
},
"display_url": "pic.twitter.com/qQfjYKelXu",
"id_str": "818564172929581056",
"indices": [132, 155],
"type": "video",
"id": 818564172929581000,
"media_url": "http://pbs.twimg.com/amplify_video_thumb/818564172929581056/img/7TiW8IO73UgkTO9y.jpg"
}],
"hashtags": [{
"indices": [0, 6],
"text": "WATCH"
}],
"user_mentions": [],
"urls": []
}
},
"link": "http://twitter.com/MoslawiInsights/statuses/818566491515678720",
"provider": {
"displayName": "Twitter",
"link": "http://www.twitter.com",
"objectType": "service"
},
"display_text_range": [0, 140],
"postedTime": "2017-01-10T00:13:54.000Z",
"id": "tag:search.twitter.com,2005:818566491515678720",
"objectType": "activity"
},
"actor": {
"followersCount": 217,
"preferredUsername": "blooddragon911",
"friendsCount": 284,
"displayName": "bloodwolf911",
"links": [{
"rel": "me"
}],
"favoritesCount": 19009,
"statusesCount": 28783,
"summary": "oooh (-_-) I'm a scary socialist!! I tweet about social justice, but i also tweet other things that interest me, things i 'm passionate about, and i love Anime",
"languages": ["en"],
"link": "http://www.twitter.com/blooddragon911",
"location": {
"displayName": "Shangri La ",
"objectType": "place"
},
"id": "id:twitter.com:714289549908832256",
"verified": false,
"listedCount": 117,
"postedTime": "2016-03-28T06:14:34.379Z",
"image": "https://pbs.twimg.com/profile_images/714290288882278401/oJ1EyzcD_normal.jpg",
"objectType": "person"
},
"twitter_lang": "en",
"twitter_entities": {
"symbols": [],
"user_mentions": [{
"indices": [3, 19],
"id_str": "462293420",
"screen_name": "MoslawiInsights",
"id": 462293420,
"name": "Mohammed"
}],
"hashtags": [{
"indices": [21, 27],
"text": "WATCH"
}],
"urls": []
},
"verb": "share",
"link": "http://twitter.com/blooddragon911/statuses/818568473873772545",
"provider": {
"displayName": "Twitter",
"link": "http://www.twitter.com",
"objectType": "service"
},
"gnip": {
"klout_profile": {
"link": "http://klout.com/user/id/159877818884456090",
"topics": [{
"displayName": "Middle East",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/7076043128808508468",
"id": "7076043128808508468"
}, {
"displayName": "Iraq",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/7895679606907690580",
"id": "7895679606907690580"
}, {
"displayName": "International Heads of State",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/10000000000000018360",
"id": "10000000000000018360"
}, {
"displayName": "Turkey",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/8055202137854805987",
"id": "8055202137854805987"
}, {
"displayName": "Syria",
"topic_type": "influence",
"score": 1,
"link": "http://klout.com/topic/id/4870724842089262213",
"id": "4870724842089262213"
}, {
"displayName": "Syria",
"topic_type": "interest",
"score": 1,
"link": "http://klout.com/topic/id/4870724842089262213",
"id": "4870724842089262213"
}, {
"displayName": "Twitter",
"topic_type": "interest",
"score": 0.93,
"link": "http://klout.com/topic/id/10000000000000008253",
"id": "10000000000000008253"
}, {
"displayName": "Middle East",
"topic_type": "interest",
"score": 0.91,
"link": "http://klout.com/topic/id/7076043128808508468",
"id": "7076043128808508468"
}, {
"displayName": "Iraq",
"topic_type": "interest",
"score": 0.89,
"link": "http://klout.com/topic/id/7895679606907690580",
"id": "7895679606907690580"
}],
"klout_user_id": "159877818884456090"
},
"klout_score": 44,
"matching_rules": [{
"tag": "mosulenglishpart120161201",
"id": 804313992667787300
}],
"profileLocations": [{
"displayName": "La Plata, Buenos Aires, Argentina",
"objectType": "place",
"geo": {
"type": "point",
"coordinates": [-57.95453, -34.92145]
},
"address": {
"country": "Argentina",
"region": "Buenos Aires",
"subRegion": "Partido de La Plata",
"countryCode": "AR",
"locality": "La Plata"
}
}]
},
"id": "tag:search.twitter.com,2005:81856847387377254
您会注意到JSON在id字段中被删除。
我将spring API中的最大请求大小更改为10MB,但情况相同。