Example usage for java.util Map toString

List of usage examples for java.util Map toString

Introduction

In this page you can find the example usage for java.util Map toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.apache.zeppelin.rest.ZeppelinRestApiTest.java

@Test
public void testSettingsCRUD() throws IOException {
    // Call Create Setting REST API
    String jsonRequest = "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"propvalue\"},\""
            + "interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]}";
    PostMethod post = httpPost("/interpreter/setting/", jsonRequest);
    LOG.info("testSettingCRUD create response\n" + post.getResponseBodyAsString());
    assertThat("test create method:", post, isCreated());

    Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(),
            new TypeToken<Map<String, Object>>() {
            }.getType());/*from  w w  w  . ja va  2  s . c o  m*/
    Map<String, Object> body = (Map<String, Object>) resp.get("body");
    //extract id from body string {id=2AWMQDNX7, name=md2, group=md,
    String newSettingId = body.toString().split(",")[0].split("=")[1];
    post.releaseConnection();

    // Call Update Setting REST API
    jsonRequest = "{\"name\":\"md2\",\"group\":\"md\",\"properties\":{\"propname\":\"Otherpropvalue\"},\""
            + "interpreterGroup\":[{\"class\":\"org.apache.zeppelin.markdown.Markdown\",\"name\":\"md\"}]}";
    PutMethod put = httpPut("/interpreter/setting/" + newSettingId, jsonRequest);
    LOG.info("testSettingCRUD update response\n" + put.getResponseBodyAsString());
    assertThat("test update method:", put, isAllowed());
    put.releaseConnection();

    // Call Delete Setting REST API
    DeleteMethod delete = httpDelete("/interpreter/setting/" + newSettingId);
    LOG.info("testSettingCRUD delete response\n" + delete.getResponseBodyAsString());
    assertThat("Test delete method:", delete, isAllowed());
    delete.releaseConnection();
}

From source file:org.ght.tc.esb.orchestration.process_actions.OrchestrationLog.java

public void execute(ExecutionContext exCtx) throws Exception {
    System.out.println("OrchestrationLog:2");
    Token token = exCtx.getToken();/*  ww  w  .j  av  a  2  s.c o  m*/
    ContextInstance context = token.getProcessInstance().getContextInstance();

    //String theBody   = (String)context.getVariable("theBody",token);
    //System.out.println("OrchestrationLog:theBody:"+theBody);
    Object objBody = context.getVariable("theBodyMoodle", token);
    String theBodyString = null;
    Map theBodyHM = null;
    if (objBody instanceof String) {
        theBodyString = (String) context.getVariable("theBodyMoodle", token);
        System.out.println("OrchestrationLog:theBodyMoodleString:" + theBodyString);
    } else if (objBody instanceof Map) {
        theBodyHM = (Map) context.getVariable("theBodyMoodle", token);
        System.out.println("OrchestrationLog:theBodyMoodleHM:" + theBodyHM.toString());
    } else {
        System.out.println("OrchestrationLog:il messaggio ha un body di un tipo non corretto (String o Map)");
    }
    String incidentAction = (String) context.getVariable("incidentAction", token);
    System.out.println("OrchestrationLog:incidentAction:" + incidentAction);

}

From source file:com.linuxbox.enkive.message.search.AbstractMessageSearchService.java

@Override
public SearchResult search(Map<String, String> fields) throws MessageSearchException {
    try {/*from  w ww .  ja  va2  s . co m*/
        // build an object to hold the search results; search is done
        // further below
        SearchResult result = searchResultBuilder.getSearchResult();
        LOGGER.trace("AbstractMessageSearchService.search function looking for messages w/ following criteria: "
                + fields.toString());

        // do the search
        final Set<String> resultMessageIDs = searchImpl(fields);

        // complete the search result data
        result.setMessageIds(resultMessageIDs);
        result.setTimestamp(new Date());
        result.setStatus(Status.COMPLETE);

        return result;
    } catch (WorkspaceException e) {
        throw new MessageSearchException("Could not create new search result", e);
    }
}

From source file:de.micromata.genome.gwiki.model.GWikiStandardEmailProvider.java

@Override
public void sendEmail(Map<String, String> ctx) {
    try {//from  w w  w  .j ava  2 s  .  co m
        if (ctx.containsKey("MAILTEMPLATE") == true) {
            evaluateMailTemplate(ctx.get("MAILTEMPLATE"), ctx);
        }
        sendEmailImpl(ctx);
        GLog.note(GWikiLogCategory.Wiki, "Send email: " + ctx.get(TO),
                new LogAttribute(GenomeAttributeType.EmailMessage, ctx.toString()));
    } catch (MessagingException ex) {
        ctx.put(SENDEMAILFAILED, ex.getMessage());
        GLog.warn(GWikiLogCategory.Wiki, "Fail to send email: " + ctx.get(TO) + ": " + ex.getMessage(),
                new LogExceptionAttribute(ex),
                new LogAttribute(GenomeAttributeType.EmailMessage, ctx.toString()));
    }
}

From source file:org.codelabor.system.file.web.struts.action.FileUploadAction.java

/**
 * ? ?? .</br>? ??//w w  w. j  a va  2  s  .co  m
 * org.codelabor.system.file.FileConstants.FILE_LIST_KEY?  attribute?
 * ??. Map Id?  ? Map Id
 * org.codelabor.system.file.FileConstants.MAP_ID?  attribute? ??.
 * 
 * @param mapping
 *             
 * @param form
 *             ?
 * @param request
 *            
 * @param response
 *            ?
 * @return  ?
 * @throws Exception
 *             
 */
public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    WebApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(getServlet().getServletContext());
    FileManager fileManager = (FileManager) ctx.getBean("fileManager");
    IdGenService mapIdGenService = (IdGenService) ctx.getBean("sequenceMapIdGenService");

    Map<String, Object> paramMap = RequestUtils.getParameterMap(request);
    logger.debug("paramMap: {}", paramMap.toString());

    String mapId = (String) paramMap.get("mapId");
    String repositoryType = (String) paramMap.get("repositoryType");

    List<FileDTO> fileDTOList = null;

    if (StringUtils.isEmpty(repositoryType)) {
        if (StringUtils.isEmpty(mapId)) {
            fileDTOList = fileManager.selectFileAll();
        } else {
            fileDTOList = fileManager.selectFileByMapId(mapId);
        }
    } else {
        switch (RepositoryType.valueOf(repositoryType)) {
        case DATABASE:
            fileDTOList = fileManager.selectFileByRepositoryType(RepositoryType.DATABASE);
            break;
        case FILE_SYSTEM:
            fileDTOList = fileManager.selectFileByRepositoryType(RepositoryType.FILE_SYSTEM);
            break;
        default:
            logger.error("Invalid repository type: {}", repositoryType);
            throw new InvalidRepositoryTypeException(repositoryType);
        }
    }
    request.setAttribute(FileConstants.MAP_ID, mapIdGenService.getNextStringId());
    request.setAttribute(FileConstants.FILE_LIST_KEY, fileDTOList);
    return mapping.findForward("list");
}

From source file:com.wso2.mobile.mdm.utils.ServerUtilities.java

public static Map<String, String> postData(Context context, String url, Map<String, String> params) {
    // Create a new HttpClient and Post Header
    Map<String, String> response_params = new HashMap<String, String>();
    HttpClient httpclient = getCertifiedHttpClient(context);

    String endpoint = CommonUtilities.SERVER_URL + url;

    SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
    String ipSaved = mainPref.getString("ip", "");

    if (ipSaved != null && ipSaved != "") {
        endpoint = CommonUtilities.SERVER_PROTOCOL + ipSaved + ":" + CommonUtilities.SERVER_PORT
                + CommonUtilities.SERVER_APP_ENDPOINT + url;
    }/*ww  w.  j a v  a 2s.  c om*/
    Log.v(TAG, "Posting '" + params.toString() + "' to " + endpoint);
    StringBuilder bodyBuilder = new StringBuilder();
    Iterator<Entry<String, String>> iterator = params.entrySet().iterator();
    // constructs the POST body using the parameters
    while (iterator.hasNext()) {
        Entry<String, String> param = iterator.next();
        bodyBuilder.append(param.getKey()).append('=').append(param.getValue());
        if (iterator.hasNext()) {
            bodyBuilder.append('&');
        }
    }

    String body = bodyBuilder.toString();
    Log.v(TAG, "Posting '" + body + "' to " + url);
    byte[] postData = body.getBytes();

    HttpPost httppost = new HttpPost(endpoint);
    httppost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
    httppost.setHeader("Accept", "*/*");
    httppost.setHeader("User-Agent", "Mozilla/5.0 ( compatible ), Android");

    try {
        // Add your data
        httppost.setEntity(new ByteArrayEntity(postData));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        response_params.put("response", getResponseBody(response));
        response_params.put("status", String.valueOf(response.getStatusLine().getStatusCode()));
        return response_params;
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}

From source file:com.gnizr.db.dao.Link.java

@Override
public String toString() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", getId());
    map.put("url", getUrl());
    map.put("urlHash", getUrlHash());
    map.put("mimeTypeId", getMimeTypeId());
    map.put("count", getCount());
    return map.toString();
}

From source file:fi.hoski.web.forms.RaceEntryServlet.java

/**
 * Handles the HTTP//from   w  w  w .  j ava2s . c  o  m
 * <code>GET</code> method.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        response.setHeader("Cache-Control", "private");
        JSONObject json = null;
        String ratingSystem = request.getParameter(RaceFleet.RatingSystem);
        if (ratingSystem != null) {
            String classOptions = request.getParameter(CLASSOPTIONS);
            if (classOptions != null) {
                printClassOptions(response, boatInfoFactory.getBoatInfoService(ratingSystem));
                return;
            }
            json = new JSONObject();
            Map<String, Object> biMap = boatInfoFactory.getMap(request.getParameterMap());
            log(biMap.toString());
            if (biMap != null && !biMap.isEmpty()) {
                for (Entry<String, Object> e : biMap.entrySet()) {
                    json.put(e.getKey(), e.getValue());
                }
            }
        } else {
            json = fromCookie(request);
            Entity rcEntity = getAncestor(request);
            if (rcEntity != null) {
                json.put(RaceEntry.FLEET, rcEntity.getProperty(RaceFleet.Fleet));
                String boatClass = (String) rcEntity.getProperty(RaceFleet.Class);
                if (boatClass != null) {
                    json.put(RaceEntry.CLASS, boatClass);
                }
            }
            ratingSystem = json.optString(BoatInfo.FLEET, null);
            String nat = json.optString(BoatInfo.NAT, null);
            String sailNo = json.optString(BoatInfo.SAILNO, null);
            String boatType = json.optString(BoatInfo.CLASS, null);
            Map<String, Object> biMap = boatInfoFactory.getMap(ratingSystem, nat, sailNo, boatType);
            if (biMap != null && !biMap.isEmpty()) {
                for (Entry<String, Object> e : biMap.entrySet()) {
                    json.put(e.getKey(), e.getValue());
                }
            }
        }
        response.setContentType("application/json");
        PrintWriter out = response.getWriter();
        json.write(out);
        out.close();
        log(json.toString());
        String refresh = request.getParameter("refresh");
        if (refresh != null) {
            boatInfoFactory.refresh(refresh);
        }
    } catch (JSONException ex) {
        log(ex.getMessage(), ex);
        throw new ServletException(ex);
    } catch (EntityNotFoundException ex) {
        log(ex.getMessage(), ex);
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:com.couchbase.lite.LiteTestCaseWithDB.java

public static Document createDocumentWithProperties(Database db, Map<String, Object> properties) {
    Document doc = db.createDocument();
    Assert.assertNotNull(doc);//from  w ww . ja  v  a2  s .  c  om
    Assert.assertNull(doc.getCurrentRevisionId());
    Assert.assertNull(doc.getCurrentRevision());
    Assert.assertNotNull("Document has no ID", doc.getId());
    // 'untitled' docs are no longer untitled (8/10/12)
    try {
        doc.putProperties(properties);
    } catch (Exception e) {
        Log.e(TAG, "Error creating document", e);
        assertTrue(
                "can't create new document in db:" + db.getName() + " with properties:" + properties.toString(),
                false);
    }
    Assert.assertNotNull(doc.getId());
    Assert.assertNotNull(doc.getCurrentRevisionId());
    Assert.assertNotNull(doc.getUserProperties());

    // should be same doc instance, since there should only ever be a single Document
    // instance for a given document
    Assert.assertEquals(db.getDocument(doc.getId()), doc);

    Assert.assertEquals(db.getDocument(doc.getId()).getId(), doc.getId());

    return doc;
}