Example usage for com.fasterxml.jackson.databind.node ObjectNode toString

List of usage examples for com.fasterxml.jackson.databind.node ObjectNode toString

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ObjectNode toString.

Prototype

public String toString() 

Source Link

Usage

From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java

/**
 * ?????<br>//from w w w .  j a  v  a 2s.co  m
 * <br>
 * - : 10<br>
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public RoomJoinGatheringResult roomJoinGathering(RoomJoinGatheringRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();

    HttpPost post = createHttpPost(
            Gs2Constant.ENDPOINT_HOST + "/matchmaking/"
                    + (request.getMatchmakingName() == null || request.getMatchmakingName().equals("") ? "null"
                            : request.getMatchmakingName())
                    + "/room/"
                    + (request.getGatheringId() == null || request.getGatheringId().equals("") ? "null"
                            : request.getGatheringId())
                    + "",
            credential, ENDPOINT, RoomJoinGatheringRequest.Constant.MODULE,
            RoomJoinGatheringRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken());

    return doRequest(post, RoomJoinGatheringResult.class);

}

From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java

/**
 * ???????<br>// ww  w .j  a  va2s  .  c  o  m
 * <br>
 * - : 10<br>
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public PasscodeJoinGatheringResult passcodeJoinGathering(PasscodeJoinGatheringRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();

    HttpPost post = createHttpPost(
            Gs2Constant.ENDPOINT_HOST + "/matchmaking/"
                    + (request.getMatchmakingName() == null || request.getMatchmakingName().equals("") ? "null"
                            : request.getMatchmakingName())
                    + "/passcode/join/"
                    + (request.getPasscode() == null || request.getPasscode().equals("") ? "null"
                            : request.getPasscode())
                    + "",
            credential, ENDPOINT, PasscodeJoinGatheringRequest.Constant.MODULE,
            PasscodeJoinGatheringRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken());

    return doRequest(post, PasscodeJoinGatheringResult.class);

}

From source file:org.apache.olingo.fit.utils.JSONUtilities.java

@Override
protected InputStream normalizeLinks(final String entitySetName, final String entityKey, final InputStream is,
        final NavigationLinks links) throws IOException {

    final ObjectNode srcNode = (ObjectNode) mapper.readTree(is);

    if (links != null) {
        for (String linkTitle : links.getLinkNames()) {
            // normalize link
            srcNode.remove(linkTitle + Constants.get(ConstantKey.JSON_NAVIGATION_BIND_SUFFIX));
            srcNode.set(linkTitle + Constants.get(ConstantKey.JSON_NAVIGATION_SUFFIX),
                    new TextNode(String.format("%s(%s)/%s", entitySetName, entityKey, linkTitle)));
        }//from   ww  w . j a va2s.  c  o  m

        for (String linkTitle : links.getInlineNames()) {
            // normalize link if exist; declare a new one if missing
            srcNode.remove(linkTitle + Constants.get(ConstantKey.JSON_NAVIGATION_BIND_SUFFIX));
            srcNode.set(linkTitle + Constants.get(ConstantKey.JSON_NAVIGATION_SUFFIX),
                    new TextNode(String.format("%s(%s)/%s", entitySetName, entityKey, linkTitle)));

            // remove inline
            srcNode.remove(linkTitle);

            // remove from links
            links.removeLink(linkTitle);
        }
    }

    srcNode.set(Constants.get(ConstantKey.JSON_EDITLINK_NAME), new TextNode(
            Constants.get(ConstantKey.DEFAULT_SERVICE_URL) + entitySetName + "(" + entityKey + ")"));

    return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING);
}

From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java

/**
 * ????<br>//from w  ww.  j  a v a2 s.co m
 * <br>
 *     - : 10<br>
 * <br>
 *
 * @param request 
        
 */

public void roomEarlyCompleteGathering(RoomEarlyCompleteGatheringRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();

    HttpPost post = createHttpPost(
            Gs2Constant.ENDPOINT_HOST + "/matchmaking/"
                    + (request.getMatchmakingName() == null || request.getMatchmakingName().equals("") ? "null"
                            : request.getMatchmakingName())
                    + "/room/"
                    + (request.getGatheringId() == null || request.getGatheringId().equals("") ? "null"
                            : request.getGatheringId())
                    + "/complete",
            credential, ENDPOINT, RoomEarlyCompleteGatheringRequest.Constant.MODULE,
            RoomEarlyCompleteGatheringRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken());

    doRequest(post, null);

}

From source file:controllers.AnyplaceMapping.java

/**
 * Uploads a floor plan file and stores it at the server system.
 * If another floorplan exists for this floor we overwrite it.
 * <p>//from  w  w  w.  j  a  v  a 2 s . c o  m
 * Needs a field:
 * floorplan: the floor plan file
 * json: The json document
 *
 * @return
 */
public static Result floorPlanUpload() {
    OAuth2Request anyReq = new OAuth2Request(request(), response());

    Http.MultipartFormData body = anyReq.getMultipartFormData();
    if (body == null) {
        return AnyResponseHelper.bad_request("Invalid request type - Not Multipart!");
    }

    Http.MultipartFormData.FilePart floorplan;
    floorplan = body.getFile("floorplan");
    if (floorplan == null) {
        return AnyResponseHelper.bad_request("Cannot find the floor plan file in your request!");
    }

    Map<String, String[]> urlenc = body.asFormUrlEncoded();
    String json_str = urlenc.get("json")[0];
    //System.out.println("json: " + json_str);

    if (json_str == null) {
        return AnyResponseHelper.bad_request("Cannot find json in the request!");
    }

    JsonNode json = null;
    try {
        json = JsonUtils.getJsonTree(json_str);
    } catch (IOException e) {
        return AnyResponseHelper.bad_request("Cannot parse json in the request!");
    }
    LPLogger.info("Floorplan Request[json]: " + json.toString());
    LPLogger.info("Floorplan Request[floorplan]: " + floorplan.getFile().getAbsolutePath());

    //// Request has the required parts so now process the json data
    List<String> requiredMissing = JsonUtils.requirePropertiesInJson(json, "buid", "floor_number",
            "bottom_left_lat", "bottom_left_lng", "top_right_lat", "top_right_lng");
    if (!requiredMissing.isEmpty()) {
        return AnyResponseHelper.requiredFieldsMissing(requiredMissing);
    }

    String buid = json.path("buid").textValue();
    String floor_number = json.path("floor_number").textValue();

    String bottom_left_lat = json.path("bottom_left_lat").textValue();
    String bottom_left_lng = json.path("bottom_left_lng").textValue();
    String top_right_lat = json.path("top_right_lat").textValue();
    String top_right_lng = json.path("top_right_lng").textValue();

    String fuid = Floor.getId(buid, floor_number);
    try {
        ObjectNode stored_floor = (ObjectNode) ProxyDataSource.getIDatasource().getFromKeyAsJson(fuid);
        if (stored_floor == null) {
            return AnyResponseHelper.bad_request("Floor does not exist or could not be retrieved!");
        }

        // update the Floor document in couchbase to include the floor plan's coordinates
        stored_floor.put("bottom_left_lat", bottom_left_lat);
        stored_floor.put("bottom_left_lng", bottom_left_lng);
        stored_floor.put("top_right_lat", top_right_lat);
        stored_floor.put("top_right_lng", top_right_lng);

        if (!ProxyDataSource.getIDatasource().replaceJsonDocument(fuid, 0, stored_floor.toString())) {
            return AnyResponseHelper.bad_request("Floor plan could not be updated in the database!");
        }
    } catch (DatasourceException e) {
        return AnyResponseHelper.internal_server_error("Error while reading from our backend service!");
    }

    /////////////////////////////////////////////////////////////////////////////////////////////
    // store the new floor plan on the server
    File floor_file;
    try {
        floor_file = AnyPlaceTilerHelper.storeFloorPlanToServer(buid, floor_number, floorplan.getFile());
    } catch (AnyPlaceException e) {
        // TODO - I should put the old couchbase object in the database
        return AnyResponseHelper.bad_request("Cannot save floor plan on the server!");
    }

    /////////////////////////////////////////////////////////////////////////////////////////////
    // Now we should start the tiling process in order to create the tiles for the floor plan
    String top_left_lat = top_right_lat;
    String top_left_lng = bottom_left_lng;
    try {
        AnyPlaceTilerHelper.tileImage(floor_file, top_left_lat, top_left_lng);
    } catch (AnyPlaceException e) {
        // TODO - I should put the old couchbase object in the database
        return AnyResponseHelper.bad_request("Could not create floor plan tiles on the server!");
    }

    LPLogger.info("Successfully tiled [" + floor_file.toString() + "]");
    return AnyResponseHelper.ok("Successfully updated floor plan!");
}

From source file:io.gs2.matchmaking.Gs2MatchmakingClient.java

/**
 * ????<br>//from  ww  w.ja va 2 s.c  o m
 * <br>
 * - : 10<br>
 * <br>
 *
 * @param request 
        
 */

public void passcodeEarlyCompleteGathering(PasscodeEarlyCompleteGatheringRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode();

    HttpPost post = createHttpPost(
            Gs2Constant.ENDPOINT_HOST + "/matchmaking/"
                    + (request.getMatchmakingName() == null || request.getMatchmakingName().equals("") ? "null"
                            : request.getMatchmakingName())
                    + "/passcode/"
                    + (request.getGatheringId() == null || request.getGatheringId().equals("") ? "null"
                            : request.getGatheringId())
                    + "/complete",
            credential, ENDPOINT, PasscodeEarlyCompleteGatheringRequest.Constant.MODULE,
            PasscodeEarlyCompleteGatheringRequest.Constant.FUNCTION, body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    post.setHeader("X-GS2-ACCESS-TOKEN", request.getAccessToken());

    doRequest(post, null);

}

From source file:edu.nwpu.gemfire.monitor.controllers.PulseController.java

@RequestMapping(value = "/pulseVersion", method = RequestMethod.GET)
public void pulseVersion(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // json object to be sent as response
    ObjectNode responseJSON = mapper.createObjectNode();

    try {/* w  ww.  j  av a 2s  .  c  o m*/
        // Reference to repository
        Repository repository = Repository.get();
        // set pulse web app url
        String pulseWebAppUrl = request.getScheme() + "://" + request.getServerName() + ":"
                + request.getServerPort() + request.getContextPath();

        repository.setPulseWebAppUrl(pulseWebAppUrl);

        // Response
        responseJSON.put("pulseVersion", PulseController.pulseVersion.getPulseVersion());
        responseJSON.put("buildId", PulseController.pulseVersion.getPulseBuildId());
        responseJSON.put("buildDate", PulseController.pulseVersion.getPulseBuildDate());
        responseJSON.put("sourceDate", PulseController.pulseVersion.getPulseSourceDate());
        responseJSON.put("sourceRevision", PulseController.pulseVersion.getPulseSourceRevision());
        responseJSON.put("sourceRepository", PulseController.pulseVersion.getPulseSourceRepository());

    } catch (Exception e) {
        if (LOGGER.fineEnabled()) {
            LOGGER.fine("Exception Occured : " + e.getMessage());
        }
    }

    // Send json response
    response.getOutputStream().write(responseJSON.toString().getBytes());
}

From source file:io.gs2.stamina.Gs2StaminaClient.java

/**
 * ?????<br>//w ww.  j av a 2 s . co  m
 * <br>
 *
 * @param request 
        
 * @return ?
        
 */

public CreateStaminaPoolResult createStaminaPool(CreateStaminaPoolRequest request) {

    ObjectNode body = JsonNodeFactory.instance.objectNode().put("name", request.getName())
            .put("serviceClass", request.getServiceClass())
            .put("increaseInterval", request.getIncreaseInterval());
    if (request.getDescription() != null)
        body.put("description", request.getDescription());
    if (request.getConsumeStaminaTriggerScript() != null)
        body.put("consumeStaminaTriggerScript", request.getConsumeStaminaTriggerScript());
    if (request.getConsumeStaminaDoneTriggerScript() != null)
        body.put("consumeStaminaDoneTriggerScript", request.getConsumeStaminaDoneTriggerScript());
    if (request.getAddStaminaTriggerScript() != null)
        body.put("addStaminaTriggerScript", request.getAddStaminaTriggerScript());
    if (request.getAddStaminaDoneTriggerScript() != null)
        body.put("addStaminaDoneTriggerScript", request.getAddStaminaDoneTriggerScript());
    if (request.getGetMaxStaminaTriggerScript() != null)
        body.put("getMaxStaminaTriggerScript", request.getGetMaxStaminaTriggerScript());

    HttpPost post = createHttpPost(Gs2Constant.ENDPOINT_HOST + "/staminaPool", credential, ENDPOINT,
            CreateStaminaPoolRequest.Constant.MODULE, CreateStaminaPoolRequest.Constant.FUNCTION,
            body.toString());
    if (request.getRequestId() != null) {
        post.setHeader("X-GS2-REQUEST-ID", request.getRequestId());
    }

    return doRequest(post, CreateStaminaPoolResult.class);

}

From source file:controllers.CommentController.java

public Result editComment() {
    System.out.println("EDIT COMMENT");

    ObjectNode response = Json.newObject();
    JsonNode json = request().body().asJson();
    if (json == null) {
        System.out.println("Comment not updated, expecting Json data");
        return badRequest(failJson("Comment not updated, expecting Json data"));
    }//from   w ww . j  av a 2  s  .com

    try {
        String text = checkMention(json.findPath("text").asText());
        Long commentId = json.findPath("comment_id").asLong();
        Date postedDate = timeFormat.parse(json.findPath("posted_date").asText());

        Comment comment = commentRepository.findCommentById(commentId);
        comment.setText(text);
        comment.setPostedDate(postedDate);
        Comment commentEntry = commentRepository.save(comment);
        addHashTags(commentEntry);
        saveMention(json.findPath("text").asText(), commentEntry.getCommentId());

        response.put("success", true);
        response.put("text", commentEntry.getText());
    } catch (ParseException pe) {
        pe.printStackTrace();
        System.out.println("Invalid date format");
        return badRequest(failJson("Invalid date format"));
    } catch (PersistenceException pe) {
        pe.printStackTrace();
        System.out.println("Comment not updated");
        return badRequest(failJson("Comment not updated"));
    }

    return ok(response.toString());
}

From source file:com.clustercontrol.hub.session.FluentdTransferFactory.java

/**
 * ?????????/*w w w . j  ava  2  s  . co m*/
 * 
 */
@Override
public Transfer createTansfer(final TransferInfo info, final PropertyBinder binder) throws TransferException {
    // HTTP ?????
    TransferDestProp urlProp = null;
    TransferDestProp connectTimeoutProp = null;
    TransferDestProp requestTimeoutProp = null;
    for (TransferDestProp prop : info.getDestProps()) {
        switch (prop.getName()) {
        case prop_url:
            urlProp = prop;
            break;
        case prop_connect_timeout:
            connectTimeoutProp = prop;
            break;
        case prop_request_timeout:
            requestTimeoutProp = prop;
            break;
        default:
            logger.warn(String.format("createTansfer() : unknown property(%s)", prop.getValue()));
            break;
        }
    }

    if (urlProp == null || urlProp.getValue() == null)
        throw new TransferException(String.format("createTansfer() : Value of \"%s\" must be set.", prop_url));

    if (!urlPattern.matcher(urlProp.getValue()).matches())
        throw new TransferException(
                String.format("createTansfer() : invalid url format. url=%s", urlProp.getValue()));

    final String urlStr = urlProp.getValue();

    Integer timeout;
    try {
        timeout = Integer.valueOf(connectTimeoutProp.getValue());
    } catch (NumberFormatException e) {
        timeout = DEFAULT_CONNECT_TIMEOUT;
        logger.warn(String.format("createTansfer() : can't regognize connectTimeout(%s) as number.",
                connectTimeoutProp.getValue()));
    } catch (NullPointerException e) {
        timeout = DEFAULT_CONNECT_TIMEOUT;
        logger.warn(String.format(
                "createTansfer() : connectTimeout is null, then use default value as connectTimeout(%s).",
                timeout));
    }
    final Integer connectTimeout = timeout;

    try {
        timeout = Integer.valueOf(requestTimeoutProp.getValue());
    } catch (NumberFormatException e) {
        timeout = DEFAULT_REQUEST_TIMEOUT;
        logger.warn(String.format("createTansfer() : can't regognize requestTimeout(%s) as number.",
                requestTimeoutProp.getValue()));
    } catch (NullPointerException e) {
        timeout = DEFAULT_CONNECT_TIMEOUT;
        logger.warn(String.format(
                "createTansfer() : requestTimeout is null, then use default value as requestTimeout(%s).",
                timeout));
    }
    final Integer requestTimeout = timeout;

    // ??
    return new Transfer() {
        private static final int BUFF_SIZE = 1024 * 1024;
        private static final int BODY_MAX_SIZE = 5 * BUFF_SIZE;

        private CloseableHttpClient client = null;

        /*
         * ??
         * 
         */
        @Override
        public TransferNumericData transferNumerics(Iterable<TransferNumericData> numerics,
                TrasferCallback<TransferNumericData> callback) throws TransferException {
            TransferNumericData lastPosition = null;
            for (TransferNumericData numeric : numerics) {
                ObjectNode root = JsonNodeFactory.instance.objectNode();
                root.put("item_name", numeric.key.getItemName());
                root.put("display_name", numeric.key.getDisplayName());
                root.put("monitor_id", numeric.key.getMonitorId());
                root.put("facility_id", numeric.key.getFacilityid());
                root.put("time", numeric.data.getTime());
                root.put("value", numeric.data.getValue());
                root.put("position", numeric.data.getPosition());

                String url = binder.bind(numeric.key, numeric.data, urlStr);
                String data = root.toString();
                try {
                    send(url, data);
                    lastPosition = numeric;

                    if (callback != null)
                        callback.onTransferred(lastPosition);
                } catch (Exception e) {
                    logger.warn(e.getMessage(), e);
                    internalError_monitor(numeric.key.getMonitorId(), data, e, url);
                    break;
                }
            }
            return lastPosition;
        }

        /*
         * ??
         * 
         */
        @Override
        public TransferStringData transferStrings(Iterable<TransferStringData> strings,
                TrasferCallback<TransferStringData> callback) throws TransferException {
            TransferStringData lastPosition = null;
            for (TransferStringData string : strings) {
                ObjectNode root = JsonNodeFactory.instance.objectNode();
                root.put("target_name", string.key.getTargetName());
                root.put("monitor_id", string.key.getMonitorId());
                root.put("facility_id", string.key.getFacilityId());
                root.put("log_format_id", string.data.getLogformatId());
                root.put("time", string.data.getTime());
                root.put("source", string.data.getValue());

                for (CollectDataTag t : string.data.getTagList()) {
                    root.put(t.getKey(), t.getValue());
                }

                root.put("position", string.data.getDataId());

                String url = binder.bind(string.key, string.data, urlStr);
                String data = root.toString();
                try {
                    send(url, data);
                    lastPosition = string;

                    if (callback != null)
                        callback.onTransferred(lastPosition);
                } catch (Exception e) {
                    logger.warn(e.getMessage(), e);
                    internalError_monitor(string.key.getMonitorId(), data, e, url);
                    break;
                }
            }
            return lastPosition;
        }

        /*
         * ??
         * 
         */
        @Override
        public JobSessionEntity transferJobs(Iterable<JobSessionEntity> sessions,
                TrasferCallback<JobSessionEntity> callback) throws TransferException {
            JobSessionEntity lastPosition = null;
            for (JobSessionEntity session : sessions) {
                ObjectNode sessionNode = JsonNodeFactory.instance.objectNode();
                sessionNode.put("ssession_id", session.getSessionId());
                sessionNode.put("job_id", session.getJobId());
                sessionNode.put("jobunit_id", session.getJobunitId());
                sessionNode.put("schedule_date", session.getScheduleDate());
                sessionNode.put("position", session.getPosition());

                ArrayNode jobArray = sessionNode.putArray("jobs");
                for (JobSessionJobEntity job : session.getJobSessionJobEntities()) {
                    ObjectNode jobNode = jobArray.addObject();
                    jobNode.put("job_id", job.getId().getJobId());
                    jobNode.put("jobunit_id", job.getId().getJobunitId());
                    if (job.getScopeText() != null)
                        jobNode.put("scope_text", job.getScopeText());
                    if (job.getStatus() != null)
                        jobNode.put("status", job.getStatus());
                    if (job.getStartDate() != null)
                        jobNode.put("start_date", job.getStartDate());
                    if (job.getEndDate() != null)
                        jobNode.put("end_date", job.getEndDate());
                    if (job.getEndValue() != null)
                        jobNode.put("end_value", job.getEndValue());
                    if (job.getEndStatus() != null)
                        jobNode.put("end_status", job.getEndStatus());
                    if (job.getResult() != null)
                        jobNode.put("result", job.getResult());
                    if (job.getJobInfoEntity() != null)
                        jobNode.put("job_type", job.getJobInfoEntity().getJobType());

                    if (!job.getJobSessionNodeEntities().isEmpty()) {
                        ArrayNode nodeArray = jobNode.putArray("nodes");
                        for (JobSessionNodeEntity node : job.getJobSessionNodeEntities()) {
                            ObjectNode nodeNode = nodeArray.addObject();
                            nodeNode.put("facility_id", node.getId().getFacilityId());
                            nodeNode.put("node_name", node.getNodeName());
                            nodeNode.put("status", node.getStatus());
                            nodeNode.put("start_date", node.getStartDate());
                            nodeNode.put("end_date", node.getEndDate());
                            nodeNode.put("end_value", node.getEndValue());
                            nodeNode.put("message", node.getMessage());
                            nodeNode.put("result", node.getResult());
                            nodeNode.put("start_date", node.getStartDate());
                            nodeNode.put("startup_time", node.getStartupTime());
                            nodeNode.put("instance_id", node.getInstanceId());
                        }
                    }
                }

                String url = binder.bind(session, urlStr);
                String data = sessionNode.toString();
                try {
                    send(url, data);
                    lastPosition = session;

                    if (callback != null)
                        callback.onTransferred(lastPosition);
                } catch (Exception e) {
                    logger.warn(e.getMessage(), e);
                    internalError_session(session.getSessionId(), data, e, url);
                    break;
                }
            }
            return lastPosition;
        }

        /*
         * ??
         * 
         */
        @Override
        public EventLogEntity transferEvents(Iterable<EventLogEntity> events,
                TrasferCallback<EventLogEntity> callback) throws TransferException {
            EventLogEntity lastPosition = null;
            for (EventLogEntity event : events) {
                ObjectNode eventNode = JsonNodeFactory.instance.objectNode();
                eventNode.put("monitor_id", event.getId().getMonitorId());
                eventNode.put("monitor_detail_id", event.getId().getMonitorDetailId());
                eventNode.put("plugin_id", event.getId().getPluginId());
                eventNode.put("generation_date", event.getGenerationDate());
                eventNode.put("facility_id", event.getId().getFacilityId());
                eventNode.put("scope_text", event.getScopeText());
                eventNode.put("application", event.getApplication());
                eventNode.put("message", event.getMessage());
                eventNode.put("message_org", event.getMessageOrg());
                eventNode.put("priority", event.getPriority());
                eventNode.put("confirm_flg", event.getConfirmFlg());
                eventNode.put("confirm_date", event.getCommentDate());
                eventNode.put("confirm_user", event.getCommentUser());
                eventNode.put("duplication_count", event.getDuplicationCount());
                eventNode.put("output_date", event.getId().getOutputDate());
                eventNode.put("inhibited_flg", event.getInhibitedFlg());
                eventNode.put("comment_date", event.getCommentDate());
                eventNode.put("comment_user", event.getCommentUser());
                eventNode.put("comment", event.getComment());
                eventNode.put("position", event.getPosition());

                String url = binder.bind(event, urlStr);
                String data = eventNode.toString();
                try {
                    send(url, data);
                    lastPosition = event;

                    if (callback != null)
                        callback.onTransferred(lastPosition);
                } catch (Exception e) {
                    logger.warn(e.getMessage(), e);
                    internalError_monitor(event.getId().getMonitorId(), data, e, url);
                    break;
                }
            }
            return lastPosition;
        }

        /*
         *  ID ??
         * 
         */
        @Override
        public String getDestTypeId() {
            return transfer_id;
        }

        /*
         * Fluentd ?????? HttpClient ??
         * ?????????
         * 
         */
        private CloseableHttpClient getHttpClient() {
            if (client == null) {
                client = createHttpClient();
            }
            return client;
        }

        /*
         * Fluentd ?????? HttpClient ??
         * 
         */
        private CloseableHttpClient createHttpClient() {
            String proxyHost = null;
            Integer proxyPort = null;
            CredentialsProvider cledentialProvider = null;
            List<String> ignoreHostList = new ArrayList<>();

            try {
                // Hinemos ???
                proxyHost = HinemosPropertyUtil.getHinemosPropertyStr("hub.fluentd.proxy.host", null);
                Long proxyPortLong = HinemosPropertyUtil.getHinemosPropertyNum("hub.fluentd.proxy.port", null);
                if (proxyPortLong != null)
                    proxyPort = proxyPortLong.intValue();
                if (proxyPort == null)
                    proxyPort = 80;
                String proxyUser = HinemosPropertyUtil.getHinemosPropertyStr("hub.fluentd.proxy.user", null);
                String proxyPassword = HinemosPropertyUtil.getHinemosPropertyStr("hub.fluentd.proxy.password",
                        null);

                if (proxyHost != null && proxyPort != null) {
                    logger.debug(
                            "initializing fluentd proxy : proxyHost = " + proxyHost + ", port = " + proxyPort);
                    String ignoreHostStr = HinemosPropertyUtil
                            .getHinemosPropertyStr("hub.fluentd.proxy.ignorehosts", null);
                    if (ignoreHostStr != null) {
                        ignoreHostList = Arrays.asList(ignoreHostStr.split(","));
                    }

                    if (proxyUser != null && proxyPassword != null) {
                        cledentialProvider = new BasicCredentialsProvider();
                        cledentialProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
                                new UsernamePasswordCredentials(proxyUser, proxyPassword));
                    }
                }
            } catch (Throwable t) {
                logger.warn("invalid proxy configuration.", t);
                proxyHost = null;
                proxyPort = null;
                cledentialProvider = null;
                ignoreHostList = Collections.emptyList();
            }

            List<Header> headers = new ArrayList<>();
            HttpClientBuilder builder = HttpClients.custom().setDefaultCredentialsProvider(cledentialProvider)
                    .setDefaultHeaders(headers);

            Builder requestBuilder = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT);
            if (connectTimeout != null)
                requestBuilder.setConnectTimeout(connectTimeout);
            if (connectTimeout != null)
                requestBuilder.setSocketTimeout(requestTimeout);

            builder.setDefaultRequestConfig(requestBuilder.build());

            if (proxyHost != null) {
                Matcher m = urlPattern.matcher(urlStr);
                if (!m.matches())
                    throw new InternalError(String.format("invalid url(%s)", urlStr));

                m.toMatchResult();

                boolean ignore = false;
                String host = m.group("host");
                for (String ignoreHost : ignoreHostList) {
                    if (ignoreHost.equals(host)) {
                        ignore = true;
                        break;
                    }
                }

                if (!ignore) {
                    HttpHost proxy = new HttpHost(proxyHost, proxyPort, "http");
                    builder.setProxy(proxy);
                }
            }

            if (keepAlive) {
                headers.add(new BasicHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE));
            } else {
                headers.add(new BasicHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE));
            }
            return builder.build();
        }

        /*
         * ?? URL ???
         * 
         */
        private void send(String url, String data) throws Exception {
            // URL  ?
            Matcher m = urlPattern.matcher(url);
            if (!m.matches())
                throw new InternalError(String.format("invalid url(%s)", urlStr));
            m.toMatchResult();
            String path = m.group("path");
            if (path != null && !path.isEmpty()) {
                String host = m.group("host");
                String port = m.group("port");

                String[] paths = path.split("/");
                for (int i = 1; i < paths.length; ++i) {
                    paths[i] = URLEncoder.encode(paths[i], "utf-8");
                }
                url = "http://" + host + (port == null || port.isEmpty() ? "" : (":" + port));
                for (int i = 1; i < paths.length; ++i) {
                    url += "/" + paths[i];
                }
            }

            HttpPost requestPost = new HttpPost(url);
            requestPost.addHeader("content-type", "application/json");
            requestPost.setEntity(new StringEntity(data, StandardCharsets.UTF_8));

            logger.debug(String.format("send() : request start. url=%s", url));

            int count = 0;
            int maxTryCount = PropertyConstants.hub_transfer_max_try_count.number();

            while (count < maxTryCount) {
                try {
                    long start = HinemosTime.currentTimeMillis();
                    try (CloseableHttpResponse response = getHttpClient().execute(requestPost)) {
                        long responseTime = HinemosTime.currentTimeMillis() - start;
                        logger.debug(String.format("send() : url=%s, responseTime=%d", url, responseTime));

                        int statusCode = response.getStatusLine().getStatusCode();
                        logger.debug(String.format("send() : url=%s, code=%d", url, statusCode));
                        if (statusCode == HttpStatus.SC_OK) {
                            logger.debug(String.format("send() : url=%s, success=%s", url,
                                    response.getStatusLine().toString()));
                            if (logger.isDebugEnabled()) {
                                ByteArrayOutputStream out = new ByteArrayOutputStream();
                                try (InputStream in = response.getEntity().getContent()) {
                                    byte[] buffer = new byte[BUFF_SIZE];
                                    while (out.size() < BODY_MAX_SIZE) {
                                        int len = in.read(buffer);
                                        if (len < 0) {
                                            break;
                                        }
                                        out.write(buffer, 0, len);
                                    }
                                }
                                String res = new String(out.toByteArray(), "UTF-8");
                                if (!res.isEmpty())
                                    logger.debug(String.format("send() : url=%s, response=%s", url, res));
                            }
                        } else {
                            throw new RuntimeException(
                                    String.format("http status code isn't 200. code=%d, message=%s", statusCode,
                                            response.getStatusLine().toString()));
                        }
                    }

                    logger.debug(String.format("send() : success. url=%s, count=%d", url, count));
                    break;
                } catch (RuntimeException e) {
                    ++count;

                    if (count < maxTryCount) {
                        logger.debug(e.getMessage(), e);
                        logger.debug(String.format(
                                "send() : fail to send, and then wait to retry. url=%s, count=%d", url, count));
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e1) {
                            logger.debug(e.getMessage());
                        }
                    } else {
                        throw new TransferException(
                                String.format("send() : fail to send. url=%s, retry count=%d, error=\"%s\"",
                                        url, count, e.getMessage()));
                    }
                }
            }
        }

        @Override
        public void close() throws Exception {
            if (client != null)
                client.close();
        }

        private void internalError_session(String sessionId, String data, Exception error, String url) {
            internalError_session(sessionId, data,
                    error.getMessage() == null || error.getMessage().isEmpty()
                            ? error.getClass().getSimpleName()
                            : error.getMessage(),
                    url);
        }

        private void internalError_session(String sessionId, String data, String error, String url) {
            AplLogger.put(PriorityConstant.TYPE_WARNING, HinemosModuleConstant.HUB_TRANSFER,
                    MessageConstant.MESSAGE_HUB_DATA_TRANSFER_FAILED, new String[] { info.getTransferId() },
                    String.format("error=%s%ntransferId=%s%ndestTypeId=%s%nsessionId=%s%ndata=%s%nurl=%s",
                            error, info.getTransferId(), info.getDestTypeId(), sessionId, data, url));
        }

        private void internalError_monitor(String sessionId, String data, Exception error, String url) {
            internalError_monitor(sessionId, data,
                    error.getMessage() == null || error.getMessage().isEmpty()
                            ? error.getClass().getSimpleName()
                            : error.getMessage(),
                    url);
        }

        private void internalError_monitor(String monitorId, String data, String error, String url) {
            AplLogger.put(PriorityConstant.TYPE_WARNING, HinemosModuleConstant.HUB_TRANSFER,
                    MessageConstant.MESSAGE_HUB_DATA_TRANSFER_FAILED, new String[] { info.getTransferId() },
                    String.format("error=%s%ntransferId=%s%ndestTypeId=%s%nmonitorId=%s%ndata=%s%nurl=%s",
                            error, info.getTransferId(), info.getDestTypeId(), monitorId, data, url));
        }
    };
}