简体   繁体   English

从HTTP事件流Java中提取数据

[英]Extract data from HTTP event stream Java

I am currently carrying out test automation using a Selenium based Automation framework. 我目前正在使用基于Selenium的自动化框架进行测试自动化。 I am currently sending in HTTP requests in order to create an API suite. 我目前正在发送HTTP请求以创建API套件。

However the next URL I need to post in is part of a text/event-stream. 但是,我需要发布的下一个URL是文本/事件流的一部分。 The data I require to extract is within the eventStream itself. 我需要提取的数据在eventStream本身内。

a["{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"VirgoSessionToken\":\"8C7A0FAA-EA27-473A-BCC3-E568ABDBD403\",\"Localization\":{\"LocaleString\":\"en_UK\",\"LanguageTag\":\"en-UK\",\"DecimalSeparator\":\".\",\"ZeroDigit\":\"0\",\"ThousandsSeparator\":\",\",\"CurrencySymbolLocation\":\"PREFIX\"},\"Balance\":{\"Timestamp\":1493730819967,\"Banks\":{\"CREDIT\":{\"Amount\":83872,\"CurrencyCode\":\"GBP\",\"MinorCurrencyUnits\":2,\"CurrencySymbol\":\"GBP\"},\"WINNINGS\":{\"Amount\":0,\"CurrencyCode\":\"GBP\",\"MinorCurrencyUnits\":2,\"CurrencySymbol\":\"GBP\"}}},\"Preferences\":{\"Global\":{},\"Game\":{}},\"State\":{\"value\":\"{\\\"serverState\\\":{\\\"player\\\":{\\\"uniqueVirgoId\\\":\\\"f85551d0-2f36-11e7-9136-314c3f96f318\\\",\\\"playerBindingState\\\":{\\\"20\\\":0,\\\"40\\\":0,\\\"60\\\":0,\\\"80\\\":0,\\\"100\\\":0,\\\"200\\\":0,\\\"400\\\":0,\\\"600\\\":0,\\\"800\\\":0,\\\"1000\\\":0,\\\"2000\\\":0,\\\"4000\\\":0,\\\"6000\\\":0,\\\"8000\\\":0,\\\"10000\\\":0},\\\"populated\\\":true},\\\"game\\\":{\\\"currencyCode\\\":\\\"\\\"}},\\\"jackpotState\\\":{}}\"},\"ApiPhase\":\"Idle\"}}"]   

I need to extract the Amount value using Java. 我需要使用Java提取Amount值。 Apologies if the code formatting isn't great. 如果代码格式不是很好,请道歉。

Is there a best way to extract Data from EventStreams? 有没有从EventStreams中提取数据的最佳方法?

As an example of what my framework does: 作为我的框架的一个例子:

String webSocketUrl = insHostedUrl + responseTitle + "/xc_yx4r_" + "/eventsource";
assertTrue(httpCreateRequest("post", webSocketUrl);
assertTrue(httpSendRequest());
response = httpGetResponse();

This posts in the URL that is visible in the requests. 这将在请求中显示的URL中发布。 However this does not get me to the eventStream data. 但是,这并没有让我看到eventStream数据。

You can probably use the google json library and run some code like this. 您可以使用google json库并运行这样的代码。

 JsonObject jsonObject = new JsonParser().parse({\\"Amount\\":0}").getAsJsonObject(); System.out.println(jsonObject.get("Amount").getAsString()); 

Here is another article with more information How to parse JSON in Java 这是另一篇文章,提供了更多信息如何在Java中解析JSON

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM