Example usage for java.lang String toString

List of usage examples for java.lang String toString

Introduction

In this page you can find the example usage for java.lang String toString.

Prototype

public String toString() 

Source Link

Document

This object (which is already a string!) is itself returned.

Usage

From source file:nz.net.orcon.kanban.controllers.FilterController.java

@PreAuthorize("hasPermission(#boardId, 'BOARD', 'ADMIN')")
@RequestMapping(value = "", method = RequestMethod.POST)
public @ResponseBody Filter createFilter(@PathVariable String boardId, @RequestBody Filter filter)
        throws Exception {
    if (filter.getPath() != null) {
        logger.warn("Attempt to update filter using POST");
        throw new Exception("Attempt to Update Filter using POST. Use PUT instead");
    }/*ww  w .j av a  2  s. c o  m*/

    ObjectContentManager ocm = ocmFactory.getOcm();
    try {
        listTools.ensurePresence(String.format(URI.BOARD_URI, boardId), "filters", ocm.getSession());
        String newId = IdentifierTools.getIdFromNamedModelClass(filter);
        filter.setPath(String.format(URI.FILTER_URI, boardId, newId.toString()));
        ocm.insert(filter);
        ocm.save();
        this.cacheInvalidationManager.invalidate(BoardController.BOARD, boardId);
    } finally {
        ocm.logout();
    }
    return filter;
}

From source file:com.cdancy.artifactory.rest.features.ArtifactApiMockTest.java

public void testRetrieveArtifactWithProperties() throws Exception {
    MockWebServer server = mockArtifactoryJavaWebServer();

    String payload = payloadFromResource("/retrieve-artifact.txt");
    server.enqueue(new MockResponse().setBody(payload).setHeader("X-Artifactory-Filename", "jar-1.0.txt")
            .setHeader("X-Checksum-Md5", randomString()).setResponseCode(200));

    ArtifactoryApi jcloudsApi = api(server.getUrl("/"));
    ArtifactApi api = jcloudsApi.artifactApi();
    File inputStream = null;/*from   ww  w.java  2 s.  c o m*/
    try {
        Map<String, List<String>> properties = new HashMap<>();
        properties.put("hello", Lists.newArrayList("world"));

        inputStream = api.retrieveArtifact("libs-release-local", "my/jar/1.0/jar-1.0.txt", properties);
        assertTrue(inputStream.exists());

        String content = FileUtils.readFileToString(inputStream);

        assertTrue(content.toString().equals(payload));
        assertSent(server, "GET", "/libs-release-local/my/jar/1.0/jar-1.0.txt;hello=world",
                MediaType.APPLICATION_OCTET_STREAM);
    } finally {
        if (inputStream != null && inputStream.exists()) {
            FileUtils.deleteQuietly(inputStream.getParentFile());
        }

        jcloudsApi.close();
        server.shutdown();
    }
}

From source file:com.esri.geoevent.solutions.adapter.geomessage.DefenseOutboundAdapter.java

@SuppressWarnings("incomplete-switch")
@Override//  www.  j a  va  2s  .  c  om
public synchronized void receive(GeoEvent geoEvent) {

    ByteBuffer byteBuffer = ByteBuffer.allocate(10 * 1024);
    Integer wkid = -1;
    String message = "";

    message += "<geomessage v=\"1.0\">\n\r";
    message += "<_type>";
    message += messageType;
    message += "</_type>\n\r";
    message += "<_action>";
    message += "update";
    message += "</_action>\n\r";
    String messageid = UUID.randomUUID().toString();
    message += "<_id>";
    message += "{" + messageid + "}";
    message += "</_id>\n\r";
    MapGeometry geom = geoEvent.getGeometry();
    if (geom.getGeometry().getType() == com.esri.core.geometry.Geometry.Type.Point) {
        Point p = (Point) geom.getGeometry();
        message += "<_control_points>";
        message += ((Double) p.getX()).toString();
        message += ",";
        message += ((Double) p.getY()).toString();
        message += "</_control_points>\n\r";
        wkid = ((Integer) geom.getSpatialReference().getID());
    }

    if (wkid > 0) {
        String wkidValue = wkid.toString();
        message += "<_wkid>";
        message += wkidValue.toString();
        message += "</_wkid>\n\r";
    }
    GeoEventDefinition definition = geoEvent.getGeoEventDefinition();
    for (FieldDefinition fieldDefinition : definition.getFieldDefinitions()) {

        String attributeName = fieldDefinition.getName();
        Object value = geoEvent.getField(attributeName);

        if (value == null || value.equals("null")) {
            continue;
        }
        FieldType t = fieldDefinition.getType();
        if (t != FieldType.Geometry) {
            message += "<" + attributeName + ">";

            switch (t) {
            case String:
                // if(((String)value).isEmpty())
                // continue;
                message += value;
                break;
            case Date:
                Date date = (Date) value;
                message += (formatter.format(date));
                break;
            case Double:
                Double doubleValue = (Double) value;
                message += doubleValue.toString();
                break;
            case Float:
                Float floatValue = (Float) value;
                message += floatValue.toString();
                break;

            case Integer:
                Integer intValue = (Integer) value;
                message += intValue.toString();
                break;
            case Long:
                Long longValue = (Long) value;
                message += longValue.toString();
                break;
            case Short:
                Short shortValue = (Short) value;
                message += shortValue.toString();
                break;
            case Boolean:
                Boolean booleanValue = (Boolean) value;
                message += booleanValue.toString();
                break;

            }
            message += "</" + attributeName + ">\n\r";
        } else {
            if (definition.getIndexOf(attributeName) == definition.getIndexOf("GEOMETRY")) {
                continue;
            } else {
                String json = GeometryEngine.geometryToJson(wkid, (Geometry) value);
                message += "<" + attributeName + ">";
                message += json;
                message += "</" + attributeName + ">\n\r";
            }
            break;
        }

    }
    message += "</geomessage>";
    // stringBuffer.append("</geomessages>");
    message += "\r\n";

    ByteBuffer buf = charset.encode(message);
    if (buf.position() > 0)
        buf.flip();

    try {
        byteBuffer.put(buf);
    } catch (BufferOverflowException ex) {
        LOG.error(
                "Csv Outbound Adapter does not have enough room in the buffer to hold the outgoing data.  Either the receiving transport object is too slow to process the data, or the data message is too big.");
    }
    byteBuffer.flip();
    super.receive(byteBuffer, geoEvent.getTrackId(), geoEvent);
    byteBuffer.clear();
}

From source file:gov.va.vinci.leo.listener.SimpleCsvListenerTest.java

@Test
public void testSimple() throws IOException {
    File f = File.createTempFile("testSimple", "txt");
    SimpleCsvListener listener = new SimpleCsvListener(f, Token.class.getCanonicalName(),
            WordToken.class.getCanonicalName());
    listener.entityProcessComplete(cas, null);
    String b = FileUtils.readFileToString(f).trim();
    assertEquals("\"DocumentId\"\t\"Start\"\t\"End\"\t\"Type\"\t\"CoveredText\"\n"
            + "\t\"1\"\t\"5\"\t\"gov.va.vinci.leo.whitespace.types.Token\"\t\"1234\"", b.toString());
}

From source file:hu.bme.mit.trainbenchmark.generator.sql.SQLGenerator.java

@Override
protected Object createVertex(final int id, final String type, final Map<String, Object> attributes,
        final Map<String, Object> outgoingEdges, final Map<String, Object> incomingEdges) throws IOException {
    final StringBuilder columns = new StringBuilder();
    final StringBuilder values = new StringBuilder();

    columns.append("\"" + ID + "\"");
    values.append(id);/* www  .j a  v a2  s  .  c o  m*/

    structuralFeaturesToSQL(attributes, columns, values);
    structuralFeaturesToSQL(outgoingEdges, columns, values);
    structuralFeaturesToSQL(incomingEdges, columns, values);

    if (ancestors.containsKey(type)) {
        final String ancestorType = ancestors.get(type);
        write(String.format("INSERT INTO \"%s\" (%s) VALUES (%s);", ancestorType, ID, id));
        write(String.format("INSERT INTO \"%s\" (%s) VALUES (%s);", type, columns.toString(),
                values.toString()));
    } else {
        final String insertQuery = String.format("INSERT INTO \"%s\" (%s) VALUES (%s);", type,
                columns.toString(), values.toString());
        write(insertQuery.toString());
    }

    return id;
}

From source file:jp.co.brilliantservice.android.ric.command.HttpController.java

private void doPost(List<Buffer> buffers) {

    StringBuilder b = new StringBuilder();

    for (int i = 0; i < buffers.size(); ++i) {
        Buffer e = buffers.get(i);
        if (i > 0)
            b.append('Z');
        for (int j = e.offset; j < e.count; ++j) {
            b.append(String.format("%02X", e.buffer[j]));
        }//from   w  w w  .  j av a  2 s.c om
    }

    final String command = b.toString();

    context.runOnUiThread(new Runnable() {

        public void run() {
            Toast toast = Toast.makeText(context, command.toString(), Toast.LENGTH_SHORT);
            toast.show();
        }
    });

    Runnable task = new Runnable() {

        public void run() {
            DefaultHttpClient client = new DefaultHttpClient();
            HttpPost req = new HttpPost(server);
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            Log.i("RIC", command);
            nvps.add(new BasicNameValuePair("c", command));
            try {
                req.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
            } catch (UnsupportedEncodingException e1) {
            }

            try {
                final HttpResponse res = client.execute(req);
                context.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast toast = Toast.makeText(context, res.getStatusLine().toString(),
                                Toast.LENGTH_SHORT);
                        toast.show();
                    }
                });
            } catch (final Exception e) {
                context.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast toast = Toast.makeText(context, e.getLocalizedMessage(), Toast.LENGTH_SHORT);
                        toast.show();
                    }
                });
                return;
            }
        }
    };

    exec.execute(task);
}

From source file:com.openshift.internal.restclient.ResourceFactory.java

private IResource create(ModelNode node, String version, String kind, boolean strict) {
    try {//from w w  w. j av  a 2 s  .c  om
        node.get(APIVERSION).set(version);
        node.get(KIND).set(kind.toString());
        Map<String, String[]> properyKeyMap = ResourcePropertiesRegistry.getInstance().get(version, kind);
        if (IMPL_MAP.containsKey(kind)) {
            Constructor<? extends IResource> constructor = IMPL_MAP.get(kind).getConstructor(ModelNode.class,
                    IClient.class, Map.class);
            return constructor.newInstance(node, client, properyKeyMap);
        }
        if (kind.endsWith("List")) {
            return new com.openshift.internal.restclient.model.List(node, client, properyKeyMap);
        }
        return new KubernetesResource(node, client, properyKeyMap);
    } catch (UnsupportedVersionException e) {
        throw e;
    } catch (Exception e) {
        throw new ResourceFactoryException(e, "Unable to create %s resource kind %s from %s", version, kind,
                node);
    }
}

From source file:com.androgogic.AikauLoginController.java

/**
 * /*from w  w  w . j a v  a2  s .  c o  m*/
 * @param request
 * @param response
 * @throws Exception
 */
protected void beforeSuccess(HttpServletRequest request, HttpServletResponse response) throws Exception {
    try {
        final HttpSession session = request.getSession();

        // Get the authenticated user name and use it to retrieve all of the groups that the user is a member of...
        String username = (String) request.getParameter(PARAM_USERNAME);
        if (username == null) {
            username = (String) session.getAttribute(UserFactory.SESSION_ATTRIBUTE_KEY_USER_ID);
        }

        if (username != null && session.getAttribute(SESSION_ATTRIBUTE_KEY_USER_GROUPS) == null) {
            Connector conn = FrameworkUtil.getConnector(session, username,
                    AlfrescoUserFactory.ALFRESCO_ENDPOINT_ID);
            ConnectorContext c = new ConnectorContext(HttpMethod.GET);
            c.setContentType("application/json");
            Response res = conn.call("/api/people/" + URLEncoder.encode(username) + "?groups=true", c);
            if (Status.STATUS_OK == res.getStatus().getCode()) {
                // Assuming we get a successful response then we need to parse the response as JSON and then
                // retrieve the group data from it...
                // 
                // Step 1: Get a String of the response...
                String resStr = res.getResponse();

                // Step 2: Parse the JSON...
                JSONParser jp = new JSONParser();
                Object userData = jp.parse(resStr.toString());

                // Step 3: Iterate through the JSON object getting all the groups that the user is a member of...
                StringBuilder groups = new StringBuilder(512);
                if (userData instanceof JSONObject) {
                    Object groupsArray = ((JSONObject) userData).get("groups");
                    if (groupsArray instanceof org.json.simple.JSONArray) {
                        for (Object groupData : (org.json.simple.JSONArray) groupsArray) {
                            if (groupData instanceof JSONObject) {
                                Object groupName = ((JSONObject) groupData).get("itemName");
                                if (groupName != null) {
                                    groups.append(groupName.toString()).append(',');
                                }
                            }
                        }
                    }
                }

                // Step 4: Trim off any trailing commas...
                if (groups.length() != 0) {
                    groups.delete(groups.length() - 1, groups.length());
                }

                // Step 5: Store the groups on the session...
                session.setAttribute(SESSION_ATTRIBUTE_KEY_USER_GROUPS, groups.toString());
            } else {
                session.setAttribute(SESSION_ATTRIBUTE_KEY_USER_GROUPS, "");
            }
        }
    } catch (ConnectorServiceException e1) {
        throw new Exception("Error creating remote connector to request user group data.");
    }
}

From source file:net.hillsdon.reviki.webtests.WebTestSupport.java

protected void assertURL(final String expected, final String actual) {
    assertEquals(removeSessionId(expected.toString()), removeSessionId(actual.toString()));
}

From source file:com.pwc.sns.testsupport.WireMockTestClient.java

private int postJsonAndReturnStatus(String url, String json) {
    HttpPost post = new HttpPost(url);
    try {/*from ww  w.  ja v a  2s .  c o  m*/
        if (json != null) {
            post.setEntity(new StringEntity(json, ContentType.create(JSON.toString(), "utf-8")));
        }
        HttpResponse httpResponse = new DefaultHttpClient().execute(post);
        return httpResponse.getStatusLine().getStatusCode();
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}