Example usage for org.apache.commons.lang.builder ReflectionToStringBuilder toString

List of usage examples for org.apache.commons.lang.builder ReflectionToStringBuilder toString

Introduction

In this page you can find the example usage for org.apache.commons.lang.builder ReflectionToStringBuilder toString.

Prototype

public static String toString(Object object, ToStringStyle style) 

Source Link

Document

Builds a toString value through reflection.

Usage

From source file:jp.primecloud.auto.zabbix.client.ItemClientTest.java

@Test
@Ignore/*from   w ww.  j  a  va  2 s  .co  m*/
public void testGet() {
    // ?
    ItemGetParam param = new ItemGetParam();
    // List<String> list = new ArrayList<String>();
    //  list.add("18359");
    //  param.setItemids(list);
    param.setOutput("extend");
    List<String> hostids = new ArrayList<String>();
    hostids.add("10001");
    param.setHostids(hostids);
    List<Item> items = client.item().get(param);

    for (Item item : items) {
        log.debug(ReflectionToStringBuilder.toString(item, ToStringStyle.SHORT_PREFIX_STYLE));

    }
    /*        if (items.size() > 0) {
            // ItemId???
            List<Integer> itemIds = new ArrayList<Integer>();
            itemIds.add(items.get(0).getItemId());
            param.set(tempids);
            List<Template> templates2 = client.template().get(param);
            
            assertEquals(1, templates2.size());
            assertEquals(templates.get(0).getTemplateid(), templates2.get(0).getTemplateid());
        }*/
}

From source file:io.reign.coord.ZkLockWatcher.java

@Override
public void process(WatchedEvent event) {
    // log if DEBUG
    if (logger.isDebugEnabled()) {
        logger.debug("***** Received ZooKeeper Event:  {}",
                ReflectionToStringBuilder.toString(event, ToStringStyle.DEFAULT_STYLE));

    }/*from ww w . j a  v  a  2  s .co  m*/

    // process events
    switch (event.getType()) {
    case NodeCreated:
    case NodeChildrenChanged:
    case NodeDataChanged:
    case NodeDeleted:
        synchronized (this) {
            this.notifyAll();

            if (logger.isDebugEnabled()) {
                logger.debug("Notifying threads waiting on LockWatcher:  lockWatcher.hashcode()="
                        + this.hashCode() + "; instancesOutstanding=" + instancesOutstanding.get()
                        + "; lockName=" + lockPath + "; lockReservation=" + lockReservationPath);
            }
        }
        break;

    case None:
        Event.KeeperState eventState = event.getState();
        if (eventState == Event.KeeperState.SyncConnected) {
            // connection event: check children
            synchronized (this) {
                this.notifyAll();
            }

        } else if (eventState == Event.KeeperState.Disconnected || eventState == Event.KeeperState.Expired) {
            // disconnected: notifyAll so we can check children again on
            // reconnection
            synchronized (this) {
                this.notifyAll();
            }

        } else {
            logger.warn("Unhandled event state:  "
                    + ReflectionToStringBuilder.toString(event, ToStringStyle.DEFAULT_STYLE));
        }
        break;

    default:
        logger.warn("Unhandled event type:  "
                + ReflectionToStringBuilder.toString(event, ToStringStyle.DEFAULT_STYLE));
    }

    // }// if

}

From source file:jp.primecloud.auto.zabbix.client.HostClientTest.java

@Test
@Ignore/*from   ww w. j  a  va 2s. c o  m*/
public void testGet() {
    // ?
    HostGetParam param = new HostGetParam();
    param.setOutput("extend");
    List<Host> hosts = client.host().get(param);
    for (Host host : hosts) {
        log.trace(ReflectionToStringBuilder.toString(host, ToStringStyle.SHORT_PREFIX_STYLE));
    }

    if (hosts.size() > 0) {
        // hostid???
        List<String> hostids = new ArrayList<String>();
        hostids.add(hosts.get(0).getHostid().toString());
        param.setHostids(hostids);
        param.setSelectParentTemplates("extend");
        param.setSelectGroups("extend");
        List<Host> hosts2 = client.host().get(param);

        assertEquals(1, hosts2.size());
        assertEquals(hosts.get(0).getHostid(), hosts2.get(0).getHostid());

        Host host = hosts2.get(0);
        log.trace(ReflectionToStringBuilder.toString(host, ToStringStyle.SHORT_PREFIX_STYLE));
        //for (Template template : host.getTemplates()) {
        for (Template template : host.getParenttemplates()) {
            log.trace(ReflectionToStringBuilder.toString(template, ToStringStyle.SHORT_PREFIX_STYLE));
        }
        for (Hostgroup hostgroup : host.getGroups()) {
            log.trace(ReflectionToStringBuilder.toString(hostgroup, ToStringStyle.SHORT_PREFIX_STYLE));
        }
    }
}

From source file:jp.primecloud.auto.zabbix.client.HostgroupClientTest.java

@Test
@Ignore/*from   w  w  w.  j  a va  2s. co m*/
public void testGet() {
    // ?
    HostgroupGetParam param = new HostgroupGetParam();
    param.setOutput("extend");
    List<Hostgroup> hostgroups = client.hostgroup().get(param);
    for (Hostgroup hostgroup : hostgroups) {
        log.trace(ReflectionToStringBuilder.toString(hostgroup, ToStringStyle.SHORT_PREFIX_STYLE));
    }

    if (hostgroups.size() > 0) {
        // hostgroupid???
        List<String> hostgroupids = new ArrayList<String>();
        hostgroupids.add(hostgroups.get(0).getGroupid());
        param.setGroupids(hostgroupids);
        List<Hostgroup> hostgroups2 = client.hostgroup().get(param);

        assertEquals(1, hostgroups2.size());
        assertEquals(hostgroups.get(0).getGroupid(), hostgroups2.get(0).getGroupid());
    }
}

From source file:jp.primecloud.auto.zabbix.client.TemplateClientTest.java

@Test
@Ignore/*w w  w .j  ava 2 s  .  com*/
public void testGet5() {
    // ?
    TemplateGetParam param = new TemplateGetParam();
    List<String> templateids = new ArrayList<String>();
    //templateids.add("11022");
    templateids.add("10057");
    param.setTemplateids(templateids);
    param.setOutput("extend");
    List<Template> templates = client.template().get(param);

    for (Template template : templates) {
        log.trace(ReflectionToStringBuilder.toString(template, ToStringStyle.SHORT_PREFIX_STYLE));
    }

}

From source file:jp.primecloud.auto.zabbix.client.UserClientTest.java

@Test
@Ignore//w w  w.  j a  va2s  .c  o  m
public void testGet() {
    // ?
    UserGetParam param = new UserGetParam();
    param.setOutput("extend");
    List<User> users = client.user().get(param);
    for (User user : users) {
        log.trace(ReflectionToStringBuilder.toString(user, ToStringStyle.SHORT_PREFIX_STYLE));
    }

    if (users.size() > 0) {
        // userid???
        List<String> userids = new ArrayList<String>();
        userids.add(users.get(0).getUserid());
        param.setUserids(userids);
        List<User> users2 = client.user().get(param);

        assertEquals(1, users2.size());
        assertEquals(users.get(0).getUserid(), users2.get(0).getUserid());
    }
}

From source file:jp.primecloud.auto.zabbix.client.ItemClientTest.java

@Test
@Ignore//from   ww  w .ja va2s  .c  o  m
public void testGetFromItemid() {
    ItemGetParam param = new ItemGetParam();
    List<String> itemids = new ArrayList<String>();
    itemids.add("83062");

    List<String> hostids = new ArrayList<String>();
    hostids.add("11367");

    //   param.setItemids(itemids);
    param.setHostids(hostids);
    param.setOutput("extend");
    List<Item> items = client.item().get(param);
    log.debug("itemSize: " + items.size());
    for (Item item : items) {
        log.debug(ReflectionToStringBuilder.toString(item, ToStringStyle.SHORT_PREFIX_STYLE));
    }
}

From source file:jp.primecloud.auto.common.component.DnsStrategy.java

/**
 * TODO: /*from  w  ww.jav a 2  s.c o m*/
 *
 * @param fqdn
 * @param ipAddress
 */
public void addReverse(String fqdn, String ipAddress) {
    List<String> commands = createCommands();

    List<String> stdins = createStdinsCommon();
    stdins.addAll(createAddReverse(fqdn, ipAddress));
    stdins.add("quit");

    CommandResult result = execute(commands, stdins);

    if (result.getExitValue() != 0) {
        // ????
        AutoException exception = new AutoException("ECOMMON-000203", fqdn, ipAddress);
        exception.addDetailInfo(
                "result=" + ReflectionToStringBuilder.toString(result, ToStringStyle.SHORT_PREFIX_STYLE));
        throw exception;
    }

    // ????
    long timeout = 10000L;
    long startTime = System.currentTimeMillis();
    while (true) {
        String hostName = getHostName(ipAddress);
        if (StringUtils.equals(fqdn, hostName)) {
            break;
        }
        if (System.currentTimeMillis() - startTime > timeout) {
            // 
            throw new AutoException("ECOMMON-000204", ipAddress, fqdn, hostName);
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ignore) {
        }
    }
}

From source file:jp.primecloud.auto.zabbix.client.ItemClientTest.java

@Test
@Ignore/*from w  w w.j av  a2 s  .co  m*/
public void testGetItemFromTemplateid() {
    // ?
    ItemGetParam param = new ItemGetParam();

    List<String> hostids = new ArrayList<String>();
    hostids.add("11749");
    param.setHostids(hostids);
    param.setApplication("tomcat");

    param.setOutput("extend");
    List<Item> items = client.item().get(param);
    log.debug("item_size :" + items.size());
    for (Item item : items) {
        log.debug(ReflectionToStringBuilder.toString(item, ToStringStyle.SHORT_PREFIX_STYLE));

    }
}

From source file:jp.primecloud.auto.zabbix.ZabbixAccessor.java

public synchronized Object execute(String method, JSON params) {
    // auth??????
    if (!"user.login".equals(method) && StringUtils.isEmpty(auth)) {
        authenticate();// w  ww  .j  av  a  2 s  .  com
    }

    Map<String, Object> request = new HashMap<String, Object>();
    request.put("jsonrpc", "2.0");
    request.put("method", method);
    request.put("params", params == null ? Collections.EMPTY_MAP : params);
    request.put("auth", auth == null ? "" : auth);
    request.put("id", ++id);

    String jsonRequest = JSONObject.fromObject(request).toString();
    if (log.isDebugEnabled()) {
        // ?
        String str = jsonRequest;
        if (str.contains("password")) {
            str = str.replaceAll("\"password\":\".*?\"", "\"password\":\"--------\"");
        }
        if (str.contains("passwd")) {
            str = str.replaceAll("\"passwd\":\".*?\"", "\"passwd\":\"--------\"");
        }

        log.debug(str);
    }

    String jsonResponse = post(jsonRequest);
    if (log.isDebugEnabled()) {
        log.debug(jsonResponse);
    }

    JSONObject response = JSONObject.fromObject(jsonResponse);

    if (response.containsKey("error")) {
        ResponseError error = (ResponseError) JSONObject.toBean(response.getJSONObject("error"),
                ResponseError.class);

        // ?????????????
        if ("Not authorized".equals(error.getData())) {
            auth = "";
            return execute(method, params);
        }

        // 
        AutoException exception = new AutoException("EZABBIX-000001", method);
        exception.addDetailInfo("params=" + params);
        exception.addDetailInfo(
                "error=" + ReflectionToStringBuilder.toString(error, ToStringStyle.SHORT_PREFIX_STYLE));
        throw exception;
    }

    return response.get("result");
}