org.restlet.Response.setEntity()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.restlet.Response.setEntity方法的一些代码示例,展示了Response.setEntity的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.setEntity方法的具体详情如下:
包路径:org.restlet.Response
类名称:Response
方法名:setEntity

Response.setEntity介绍

暂无

代码示例

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
  public void handle(Request request, Response response) {
    response.setEntity("Hello.", MediaType.TEXT_PLAIN);
  }
};

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
  public void handle(Request request, Response response) {
    response.setEntity("Bye", MediaType.TEXT_PLAIN);
  }
};

代码示例来源:origin: icclab/cyclops

public Response prepareResponse(Response response, boolean withEnvelope) {
  if (response == null || status == null || description == null) return null;
  // fill status with description and make sure entity is of type JSON
  response.setStatus(status, description);
  Gson gson = new Gson();
  if (!withEnvelope && result != null) response.setEntity(gson.toJson(result), MEDIA_TYPE);
  else response.setEntity(gson.toJson(this), MEDIA_TYPE);
  return response;
}

代码示例来源:origin: icclab/cyclops

public Response prepareResponse(Response response, boolean withEnvelope) {
  if (response == null || status == null || description == null) return null;
  // fill status with description and make sure entity is of type JSON
  response.setStatus(status, description);
  Gson gson = new Gson();
  if (!withEnvelope && result != null) response.setEntity(gson.toJson(result), MEDIA_TYPE);
  else response.setEntity(gson.toJson(this), MEDIA_TYPE);
  return response;
}

代码示例来源:origin: icclab/cyclops

public Response prepareResponse(Response response, boolean withEnvelope) {
  if (response == null || status == null || description == null) return null;
  // fill status with description and make sure entity is of type JSON
  response.setStatus(status, description);
  Gson gson = new Gson();
  if (!withEnvelope && result != null) response.setEntity(gson.toJson(result), MEDIA_TYPE);
  else response.setEntity(gson.toJson(this), MEDIA_TYPE);
  return response;
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Sets a textual entity.
 * 
 * @param value
 *            The represented string.
 * @param mediaType
 *            The representation's media type.
 */
@Override
public void setEntity(String value, MediaType mediaType) {
  getWrappedResponse().setEntity(value, mediaType);
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Sets the entity representation.
 * 
 * @param entity
 *            The entity representation.
 */
@Override
public void setEntity(Representation entity) {
  getWrappedResponse().setEntity(entity);
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
  public void handle(Request request, Response response) {
    // Print the user name of the requested orders
    String message = "Orders of user \""
        + request.getAttributes().get("user") + "\"";
    response.setEntity(message, MediaType.TEXT_PLAIN);
  }
};

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
  public void handle(Request request, Response response) {
    // Print the requested URI path
    String message = "Account of user \""
        + request.getAttributes().get("user") + "\"";
    response.setEntity(message, MediaType.TEXT_PLAIN);
  }
};

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
  public void handle(Request request, Response response) {
    // Print the user name of the requested orders
    String message = "Order \""
        + request.getAttributes().get("order")
        + "\" for user \""
        + request.getAttributes().get("user") + "\"";
    response.setEntity(message, MediaType.TEXT_PLAIN);
  }
};

代码示例来源:origin: org.restlet.osgi/org.restlet.ext.oauth

private int sendErrorPage(Response response, Exception ex) {
  response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ex.getMessage());
  response.setEntity(getErrorPage(ex));
  return STOP;
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
public void challenge(Response response, boolean stale) {
  // Load the FreeMarker template
  Representation ftl = new ClientResource(
      LocalReference.createClapReference(getClass().getPackage())
          + "/Login.ftl").get();
  // Wraps the bean with a FreeMarker representation
  response.setEntity(new TemplateRepresentation(ftl, response
      .getRequest().getResourceRef(), MediaType.TEXT_HTML));
  response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
public void challenge(Response response, boolean stale) {
  // Load the FreeMarker template
  Representation ftl = new ClientResource(
      LocalReference.createClapReference(getClass().getPackage())
          + "/Login.ftl").get();
  // Wraps the bean with a FreeMarker representation
  response.setEntity(new TemplateRepresentation(ftl, response
      .getRequest().getResourceRef(), MediaType.TEXT_HTML));
  response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.xml

@Override
protected void afterHandle(Request request, Response response) {
  if ((getMode() == MODE_RESPONSE) && canTransform(response.getEntity())) {
    response.setEntity(transform(response.getEntity()));
  }
}

代码示例来源:origin: org.restlet.osgi/org.restlet.ext.oauth

@Override
protected void doCatch(Throwable t) {
  final OAuthException oex = OAuthException.toOAuthException(t);
  // XXX: Generally, we only communicate with TokenVerifier. So we don't
  // need HTTP 400 code.
  // getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
  getResponse().setStatus(Status.SUCCESS_OK);
  getResponse().setEntity(responseErrorRepresentation(oex));
}

代码示例来源:origin: org.restlet.gae/org.restlet.ext.freemarker

@Override
protected void afterHandle(Request request, Response response) {
  if (response.isEntityAvailable()
      && response.getEntity().getEncodings()
          .contains(Encoding.FREEMARKER)) {
    TemplateRepresentation representation = new TemplateRepresentation(
        response.getEntity(), this.configuration, response
            .getEntity().getMediaType());
    representation.setDataModel(createDataModel(request, response));
    response.setEntity(representation);
  }
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
public void handle(Request request, Response response) {
  String entity = "Method       : " + request.getMethod()
      + "\nResource URI : " + request.getResourceRef()
      + "\nIP address   : " + request.getClientInfo().getAddress()
      + "\nAgent name   : " + request.getClientInfo().getAgentName()
      + "\nAgent version: "
      + request.getClientInfo().getAgentVersion();
  response.setEntity(entity, MediaType.TEXT_PLAIN);
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
public void handle(Request request, Response response) {
  String entity = "Method       : " + request.getMethod()
      + "\nResource URI : " + request.getResourceRef()
      + "\nIP address   : " + request.getClientInfo().getAddress()
      + "\nAgent name   : " + request.getClientInfo().getAgentName()
      + "\nAgent version: "
      + request.getClientInfo().getAgentVersion();
  response.setEntity(entity, MediaType.TEXT_PLAIN);
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
  public void handle(Request request, Response response) {
    String entity = "Method       : " + request.getMethod()
        + "\nResource URI : " + request.getResourceRef()
        + "\nIP address   : "
        + request.getClientInfo().getAddress()
        + "\nAgent name   : "
        + request.getClientInfo().getAgentName()
        + "\nAgent version: "
        + request.getClientInfo().getAgentVersion();
    response.setEntity(entity, MediaType.TEXT_PLAIN);
  }
};

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
  public void handle(Request request, Response response) {
    String entity = "Method       : " + request.getMethod()
        + "\nResource URI : " + request.getResourceRef()
        + "\nIP address   : "
        + request.getClientInfo().getAddress()
        + "\nAgent name   : "
        + request.getClientInfo().getAgentName()
        + "\nAgent version: "
        + request.getClientInfo().getAgentVersion();
    response.setEntity(entity, MediaType.TEXT_PLAIN);
  }
};

相关文章