Fetch a Monitor Poll/Field Report

This use case describes the requirements for fetching a monitor poll or field report using BroadSign Open.

SOAP API Method Reference

To fetch a monitor poll, use the following methods:

To fetch a field report, use the field_report_mgr_list method.

Code Samples
#!/usr/bin/php
<?php
  ## Fetch a monitor poll/field report
  ## Show the poll status and field report of one player (or edge) or poll status of all players and edges on your domain.
  ##
  ## Usage : php fetching_monitor_poll_field_report --domain=domainId [--client=playerID|egdeserverId]
  ## Usage example : php fetching_monitor_poll_field_report --domain=68110253 --client=76360527

  include "soaplib.php";
  include "cmdutil.php";

  $options = get_arguments("domain!", "client");

  if (isset($options["client"])) 
  {
    # Display poll status for a given player or edge server
    $body = new stdClass();
    $body -> domain_id = $options["domain"]; # ID of your domain
    $body -> client_resource_id = $options["client"]; # ID of the player or edge server
    $response = performSimpleOperation("monitor_poll", "list_by_client_resource_id", 2, $body);
    
    # Display field report for a given player or edge server
    $body = new stdClass();
    $body -> domain_id = $options["domain"]; # The ID of your domain
    $body -> target_resource_id = $options["client"]; # The ID of your player or edge server
    $response = performSimpleOperation("field_report", "list", 4, $body);
  } 
      else 
  {
    # Display poll status of all players and edge servers in your domain
    $body = new stdClass();
    $body -> domain_id = $options["domain"]; # ID of your domain
    $body -> client_resource_id = 112578507; # ID of the player or edge server
    $response = performSimpleOperation("monitor_poll", "list", 2, $body);
  }
  #echo json_encode($response) . "\n";
?>

/*
 * (c) 2002 - 2015 BroadSign International, LLC
 */

import java.util.List;

import org.apache.axis2.Constants.Configuration;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.TransportOutDescription;
import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
import org.apache.axis2.transport.http.HTTPConstants;

import com.broadsign.www.wsdl_ops.BsapiStub;
import com.broadsign.www.wsdl_ops.FieldReportMgrListResponseBody;
import com.broadsign.www.wsdl_ops.MonitorPollMgrListByClientResourceIdResponseBody;
import com.broadsign.www.wsdl_ops.MonitorPollMgrListResponseBody;

class Main {

  public static void main(String[] args) throws Exception
  {
    setupKeystore();
    BsapiStub javaStub = createStub();
    
    String basicPlayerId = "12345678";
    String basicDomainId = "23456789";

    MonitorPollFactory monitorPollFactory = new MonitorPollFactory(javaStub);

    MonitorPollMgrListByClientResourceIdResponseBody response = monitorPollFactory.listByClientResourceId(basicPlayerId);
    printMonitorPoll(response);
    
    List<MonitorPollMgrListResponseBody> responses = monitorPollFactory.list(basicDomainId);
    for(MonitorPollMgrListResponseBody r : responses) {
      printMonitorPoll(r);
    }
    
    FieldReportFactory fieldReportFactory = new FieldReportFactory(javaStub);
    List<FieldReportMgrListResponseBody> fieldReportResponses = fieldReportFactory.list(basicDomainId,basicPlayerId);
    for(FieldReportMgrListResponseBody r : fieldReportResponses) {
      System.out.println(r.getFieldReport());
    }
  }
  
  private static void printMonitorPoll(MonitorPollMgrListByClientResourceIdResponseBody response) {
    System.out.println("Player ID: " + response.getClientResourceId());
    System.out.println("Private IP: " + response.getPrivateIp());
    System.out.println("Public IP: " + response.getPublicIp());
    System.out.println("Status: " + response.getMonitorStatus());
    System.out.println("Last poll: " + response.getPollLastUtc());
    System.out.println("Next poll: " + response.getPollNextExpectedUtc());
    System.out.println("Version: " + response.getProductVersion());
    System.out.println();
  }
  
  private static void printMonitorPoll(MonitorPollMgrListResponseBody response) {
    System.out.println("Player ID: " + response.getClientResourceId());
    System.out.println("Private IP: " + response.getPrivateIp());
    System.out.println("Public IP: " + response.getPublicIp());
    System.out.println("Status: " + response.getMonitorStatus());
    System.out.println("Last poll: " + response.getPollLastUtc());
    System.out.println("Next poll: " + response.getPollNextExpectedUtc());
    System.out.println("Version: " + response.getProductVersion());
    System.out.println();
  }


  private static BsapiStub createStub()
  {
    try {
      ConfigurationContext config = ConfigurationContextFactory.createDefaultConfigurationContext();
      TransportOutDescription transport = new TransportOutDescription("https_mutual_auth");
      CommonsHTTPTransportSender sender = new CommonsHTTPTransportSender();

      sender.init(config, transport);
      BsapiStub javaStub = new BsapiStub();
      transport.setSender(sender);
      javaStub._getServiceClient().getOptions().setProperty(Configuration.CHARACTER_SET_ENCODING, "utf-16");
      javaStub._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, "false");
      javaStub._getServiceClient().getOptions().setTransportOut(transport);
      return javaStub;
    } catch (java.lang.Exception e) {
      System.out.println("Error:" + e.toString());
    }
    return null;
  }
  private static void setupKeystore()
  {
    // NOTE: Make sure to update the folders where your keystore files are located
        //       as well as the actual passwords for your keystores
    System.setProperty("javax.net.ssl.keyStoreType", "jks");
    System.setProperty("javax.net.ssl.keyStore", "YOUR_SOAP_KEYSTORE_HERE.keystore");
    System.setProperty("javax.net.ssl.keyStorePassword", "YOUR_SOAP_KEYSTORE_PASSWORD_HERE");
    System.setProperty("javax.net.ssl.trustStoreType", "jks");
    System.setProperty("javax.net.ssl.trustStore", "YOUR_TRUSTED_KEYSTORE_HERE.keystore");
    System.setProperty("javax.net.ssl.trustStorePassword", "YOUR_TRUSTED_KEYSTORE_PASSWORD_HERE");
  }
}

/*
 * (c) 2002 - 2015 BroadSign International, LLC
 */

/*
 * FieldReportFactory Class
 *
 * This class allows the listing of field reports
 */

import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;

class FieldReportFactory {

  public FieldReportFactory(BsapiStub stub)
  {
    assert(stub != null);
    m_stub = stub;
  }
  
  public List<FieldReportMgrListResponseBody> list(String domainId, String targetResourceId) throws Exception
  {
    List<FieldReportMgrListResponseBody> results = new ArrayList<FieldReportMgrListResponseBody>();
    WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
    XmlObject xmlBodies[];
    RequestDocument requestDocument = RequestDocument.Factory.newInstance();
    ResponseDocument responseDocument;
    WsdlResponse response;

    FieldReportMgrListRequestBody requestBody = FieldReportMgrListRequestBody.Factory.newInstance();

    requestBody.setDomainId(domainId);
    requestBody.setTargetResourceId(targetResourceId);
    wsdlRequest.setName("field_report_mgr_list");
    wsdlRequest.setVersion(4);
    wsdlRequest.setFieldReport(requestBody);

    requestDocument.setRequest(wsdlRequest);
    requestDocument.documentProperties().setEncoding("utf-16");
    System.out.println(requestDocument.xmlText());

    responseDocument = m_stub.field_report_mgr_list_v4(requestDocument);

    System.out.println(responseDocument.xmlText());
    response = responseDocument.getResponse();
    xmlBodies = response.getFieldReportArray();

    if (xmlBodies.length > 0) {
      for (XmlObject xmlBody : xmlBodies) {
        FieldReportMgrListResponseBody monitorPoll = FieldReportMgrListResponseBody.Factory.parse(xmlBody.xmlText());
        results.add(monitorPoll);
      }
    }

    return results;
  }

  private BsapiStub m_stub = null;
}

/*
 * (c) 2002 - 2015 BroadSign International, LLC
 */

/*
 * MonitorPollFactory Class
 *
 * This class allows the listing of monitor polls
 */

import java.util.ArrayList;
import java.util.List;

import org.apache.xmlbeans.*;

import com.broadsign.www.wsdl_ops.*;

class MonitorPollFactory {

  public MonitorPollFactory(BsapiStub stub)
  {
    assert(stub != null);
    m_stub = stub;
  }

  public MonitorPollMgrListByClientResourceIdResponseBody listByClientResourceId(String clientResourceId) throws Exception
  {
    MonitorPollMgrListByClientResourceIdResponseBody result = null;
    WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
    XmlObject xmlBodies[];
    RequestDocument requestDocument = RequestDocument.Factory.newInstance();
    ResponseDocument responseDocument;
    WsdlResponse response;

    MonitorPollMgrListByClientResourceIdRequestBody requestBody = MonitorPollMgrListByClientResourceIdRequestBody.Factory.newInstance();

    requestBody.setClientResourceId(clientResourceId);
    wsdlRequest.setName("monitor_poll_mgr_list_by_client_resource_id");
    wsdlRequest.setVersion(2);
    wsdlRequest.setMonitorPoll(requestBody);

    requestDocument.setRequest(wsdlRequest);
    requestDocument.documentProperties().setEncoding("utf-16");
    System.out.println(requestDocument.xmlText());

    responseDocument = m_stub.monitor_poll_mgr_list_by_client_resource_id_v2(requestDocument);

    System.out.println(responseDocument.xmlText());
    response = responseDocument.getResponse();
    xmlBodies = response.getMonitorPollArray();

    if (xmlBodies.length > 0) {
      for (XmlObject xmlBody : xmlBodies) {
        result = MonitorPollMgrListByClientResourceIdResponseBody.Factory.parse(xmlBody.xmlText());
      }
    }

    return result;
  }
  
  public List<MonitorPollMgrListResponseBody> list(String domainId) throws Exception
  {
    List<MonitorPollMgrListResponseBody> results = new ArrayList<MonitorPollMgrListResponseBody>();
    WsdlRequest wsdlRequest = WsdlRequest.Factory.newInstance();
    XmlObject xmlBodies[];
    RequestDocument requestDocument = RequestDocument.Factory.newInstance();
    ResponseDocument responseDocument;
    WsdlResponse response;

    MonitorPollMgrListRequestBody requestBody = MonitorPollMgrListRequestBody.Factory.newInstance();

    requestBody.setDomainId(domainId);
    wsdlRequest.setName("monitor_poll_mgr_list");
    wsdlRequest.setVersion(2);
    wsdlRequest.setMonitorPoll(requestBody);

    requestDocument.setRequest(wsdlRequest);
    requestDocument.documentProperties().setEncoding("utf-16");
    System.out.println(requestDocument.xmlText());

    responseDocument = m_stub.monitor_poll_mgr_list_v2(requestDocument);

    System.out.println(responseDocument.xmlText());
    response = responseDocument.getResponse();
    xmlBodies = response.getMonitorPollArray();

    if (xmlBodies.length > 0) {
      for (XmlObject xmlBody : xmlBodies) {
        MonitorPollMgrListResponseBody monitorPoll = MonitorPollMgrListResponseBody.Factory.parse(xmlBody.xmlText());

        results.add(monitorPoll);
      }
    }

    return results;
  }

  private BsapiStub m_stub = null;
}