Package org.restlet.representation

Examples of org.restlet.representation.AppendableRepresentation


* @author Jerome Louvel
*/
public class AppendableRepresentationTestCase extends RestletTestCase {

    public void testAppendable() throws Exception {
        AppendableRepresentation ar = new AppendableRepresentation();
        ar.append("abcd");
        ar.append("efgh");
        assertEquals("abcdefgh", ar.getText());
    }
View Full Code Here


    private final int port = TEST_PORT;

    private final int port2 = port + 1;

    public void testComponentXMLConfig() throws Exception {
        AppendableRepresentation config = new AppendableRepresentation();
        config.append("<?xml version=\"1.0\"?>");
        config.append("<component>");
        config
                .append("<server protocol=\"HTTP\" port=\"" + this.port
                        + "\" />");
        config.append("<server protocol=\"HTTP\" port=\"" + this.port2
                + "\" />");
        config.append("<defaultHost hostPort=\"" + this.port2 + "\">");
        config
                .append("<attach uriPattern=\"/abcd\" targetClass=\"org.restlet.test.component.HelloWorldApplication\" /> ");
        config.append("</defaultHost>");
        config.append("<host hostPort=\"" + this.port + "\">");
        config
                .append("<attach uriPattern=\"/efgh\" targetClass=\"org.restlet.test.component.HelloWorldApplication\" /> ");
        config.append("</host>");

        config.append("</component>");

        final Component component = new Component(config);
        component.start();

        final Client client = new Client(Protocol.HTTP);
View Full Code Here

   * @param e
   * @return
   */
  private Representation handleExceptionRestReturn(String message,
      Exception e) {
    AppendableRepresentation error = buildErrorRepresentation(e,
        message);
    logger.log(Level.WARNING, message, e);
    return error;
  }
View Full Code Here

   * @param message
   * @return
   */
  private AppendableRepresentation buildErrorRepresentation(Exception e,
      String message) {
    AppendableRepresentation error = new AppendableRepresentation(message);
    ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
    e.printStackTrace(new PrintStream(errorStream));
    try {
      error.append("\n\nerror stack\n\n");
      error.append(errorStream.toString());
    } catch(Exception x) {
      logger.log(Level.SEVERE, "unable to append anything to error representation", x);
    }
    return error;
  }
View Full Code Here

   * @param e
   * @return
   */
  private Representation handleExceptionRestReturn(String message,
      Exception e) {
    AppendableRepresentation error = buildErrorRepresentation(e,
        message);
    logger.log(Level.WARNING, message, e);
    return error;
  }
View Full Code Here

   * @param message
   * @return
   */
  private AppendableRepresentation buildErrorRepresentation(Exception e,
      String message) {
    AppendableRepresentation error = new AppendableRepresentation(message);
    ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
    e.printStackTrace(new PrintStream(errorStream));
    try {
      error.append("\n\nerror stack\n\n");
      error.append(errorStream.toString());
    } catch(Exception x) {
      logger.log(Level.SEVERE, "unable to append anything to error representation", x);
    }
    return error;
  }
View Full Code Here

TOP

Related Classes of org.restlet.representation.AppendableRepresentation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.