Package er.rest

Examples of er.rest.ERXRestRequestNode


   * @param filter
   *            the filter to apply to the objects
   * @return a WOResponse in the given format
   */
  public WOActionResults response(ERXRestFormat format, EOClassDescription entity, NSArray<?> values, ERXKeyFilter filter) {
    ERXRestRequestNode responseNode;
    try {
      responseNode = ERXRestRequestNode.requestNodeWithObjectAndFilter(entity, values, filter, restContext());
    }
    catch (ObjectNotAvailableException e) {
      return errorResponse(e, WOMessage.HTTP_STATUS_NOT_FOUND);
View Full Code Here


   * @param filter
   *            the filter to apply
   * @return a WOResponse in the given format
   */
  public WOActionResults response(ERXRestFormat format, Object value, ERXKeyFilter filter) {
    ERXRestRequestNode responseNode;
    try {
      responseNode = ERXRestRequestNode.requestNodeWithObjectAndFilter(value, filter, restContext());
    }
    catch (ObjectNotAvailableException e) {
      return errorResponse(e, WOMessage.HTTP_STATUS_NOT_FOUND);
View Full Code Here

    String arrayJSON = ERXRestFormat.json().toString(list);
    System.out.println("Client.main: array as JSON " + arrayJSON);

    ClientCompany newCompany = new ClientCompany();
    newCompany.setName("Peters Pickles");
    ERXRestRequestNode node = client.createObjectWithPath(newCompany, ERXKeyFilter.filterWithAllRecursive(), "Company.json", ERXRestFormat.json());
    System.out.println("Client.main: The newly created company is: " + node.toString(ERXRestFormat.json(), new ERXRestContext()));
  }
View Full Code Here

  }

  /* Extract the requestNode from the given method using the given format.
   */
  protected ERXRestRequestNode requestNodeWithMethod(HttpMethodBase method, ERXRestFormat format) throws IOException {
    ERXRestRequestNode responseNode = format.parser().parseRestRequest(new ERXStringRestRequest(method.getResponseBodyAsString()), format.delegate(), _context);
    return responseNode;
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  public <T> T objectWithPath(String path, String entityName) throws HttpException, IOException {
    HttpClient client = httpClient();
    GetMethod fetchObjectMethod = new GetMethod(new ERXMutableURL(_baseURL).appendPath(path).toExternalForm());
    client.executeMethod(fetchObjectMethod);
    ERXRestRequestNode node = requestNodeWithMethod(fetchObjectMethod);
    return (T) _objectWithRequestNode(node, entityName);
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  public <T> T objectWithPath(String path) throws HttpException, IOException {
    HttpClient client = httpClient();
    GetMethod fetchObjectMethod = new GetMethod(new ERXMutableURL(_baseURL).appendPath(path).toExternalForm());
    client.executeMethod(fetchObjectMethod);
    ERXRestRequestNode node = requestNodeWithMethod(fetchObjectMethod);
    String type = node.type();
    return (T) _objectWithRequestNode(node, type);
  }
View Full Code Here

  public ERXRestRequestNode update(Object obj, ERXKeyFilter filter, String entityName, String id, String action, ERXRestFormat format) throws HttpException, IOException {
    return updateObjectWithPath(obj, filter, path(entityName, id, action, format), format);
  }

  public ERXRestRequestNode updateObjectWithPath(Object obj, ERXKeyFilter filter, String path, ERXRestFormat format) throws HttpException, IOException {
    ERXRestRequestNode node = ERXRestRequestNode.requestNodeWithObjectAndFilter(obj, filter, _context);
    ERXStringBufferRestResponse response = new ERXStringBufferRestResponse();
    format.writer().appendToResponse(node, response, format.delegate(), _context);

    HttpClient client = httpClient();
    PutMethod updateObjectMethod = new PutMethod(new ERXMutableURL(_baseURL).appendPath(path).toExternalForm());
View Full Code Here

  public ERXRestRequestNode create(Object obj, ERXKeyFilter filter, String entityName, String id, String action, ERXRestFormat format) throws HttpException, IOException {
    return createObjectWithPath(obj, filter, path(entityName, id, action, format), format);
  }

  public ERXRestRequestNode createObjectWithPath(Object obj, ERXKeyFilter filter, String path, ERXRestFormat format) throws HttpException, IOException {
    ERXRestRequestNode node = ERXRestRequestNode.requestNodeWithObjectAndFilter(obj, filter, _context);
    ERXStringBufferRestResponse response = new ERXStringBufferRestResponse();
    format.writer().appendToResponse(node, response, format.delegate(), _context);

    HttpClient client = httpClient();
    PostMethod updateObjectMethod = new PostMethod(new ERXMutableURL(_baseURL).appendPath(path).toExternalForm());
View Full Code Here

  public ERXRestRequestNode delete(Object obj, String entityName, String id, String action, ERXRestFormat format) throws HttpException, IOException {
    return deleteObjectWithPath(obj, path(entityName, id, action, format), format);
  }

  public ERXRestRequestNode deleteObjectWithPath(Object obj, String path, ERXRestFormat format) throws HttpException, IOException {
    ERXRestRequestNode node = ERXRestRequestNode.requestNodeWithObjectAndFilter(obj, ERXKeyFilter.filterWithNone(), _context);

    HttpClient client = httpClient();
    DeleteMethod deleteObjectMethod = new DeleteMethod(new ERXMutableURL(_baseURL).appendPath(path).toExternalForm());
    client.executeMethod(deleteObjectMethod);
    return requestNodeWithMethod(deleteObjectMethod);
View Full Code Here

* @author mschrag
*/
public class ERXXmlRestParser implements IERXRestParser {
  protected ERXRestRequestNode createRequestNodeForElement(Element element, boolean rootNode, ERXRestFormat.Delegate delegate, ERXRestContext context) {
    String name = element.getTagName();
    ERXRestRequestNode requestNode = new ERXRestRequestNode(name, rootNode);

    String valueStr = element.getNodeValue();

    NamedNodeMap attributeNodes = element.getAttributes();
    for (int attributeNum = 0; attributeNum < attributeNodes.getLength(); attributeNum++) {
      Node attribute = attributeNodes.item(attributeNum);
      requestNode.setAttributeForKey(attribute.getNodeValue(), attribute.getNodeName());
    }
    NodeList childNodes = element.getChildNodes();
    for (int childNodeNum = 0; childNodeNum < childNodes.getLength(); childNodeNum++) {
      Node childNode = childNodes.item(childNodeNum);
      if (childNode instanceof Element) {
        Element childElement = (Element) childNode;
        ERXRestRequestNode childRequestNode = createRequestNodeForElement(childElement, false, delegate, context);
        if (childRequestNode != null) {
          String childRequestNodeName = childRequestNode.name();
          // MS: this is a huge hack, but it turns out that it's surprinsingly tricky to
          // identify an array in XML ... I'm cheating here and just saying that if the
          // node name is uppercase, it represents a new object and not an attribute ...
          // this will totally break on rails-style lowercase class names, but for now
          // this flag is just a heuristic
          if (childRequestNodeName == null || Character.isUpperCase(childRequestNodeName.charAt(0))) {
            childRequestNode.setRootNode(true);
            requestNode.setArray(true);
          }
          requestNode.addChild(childRequestNode);
        }
      }
View Full Code Here

TOP

Related Classes of er.rest.ERXRestRequestNode

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.