Package br.com.caelum.restfulie

Examples of br.com.caelum.restfulie.RestfulieException


    try {
      Map<String, String> headers = details.getHeaders();

      HttpURLConnection connection = prepareConnectionWith(headers, uri);
      if (!headers.containsKey("Content-type")) {
        throw new RestfulieException(
            "You should set a content type prior to sending some payload.");
      }
      connection.setDoOutput(true);
      connection.setRequestMethod(verb);
      OutputStream output = connection.getOutputStream();
      Writer writer = new OutputStreamWriter(output);
      String type = headers.get("Content-type");
      handlerFor(type).marshal(payload, writer, client);
      writer.flush();
      return responseFor(connection, new IdentityContentProcessor(), details);
    } catch (IOException e) {
      throw new RestfulieException("Unable to execute " + uri, e);
    }
  }
View Full Code Here


      connection.setRequestMethod(verb);
      JavaNetResponse response = responseFor(connection,
          new HttpURLConnectionContentProcessor(connection), request);
      return response;
    } catch (IOException e) {
      throw new RestfulieException("Unable to execute " + uri, e);
    }
  }
View Full Code Here

  public String getContent() {
    try {
      return processor.read();
    } catch (IOException e) {
      throw new RestfulieException("Unable to parse response content", e);
    }
  }
View Full Code Here

  public URI getLocation() {
    try {
      return new URI(headers.getMain("Location"));
    } catch (URISyntaxException e) {
      throw new RestfulieException("Invalid URI received as a response", e);
    }
  }
View Full Code Here

  public String getStatusLine() {
    try {
      return connection.getResponseMessage();
    } catch (IOException e) {
      throw new RestfulieException("Invalid Status line", e);
    }
  }
View Full Code Here

    for (MediaType type : types) {
      if (type.answersTo(searching)) {
        return type;
      }
    }
    throw new RestfulieException("Unsupported media type '" + searching + "'");
  }
View Full Code Here

    }

    final Map<String, String> headers = details.getHeaders();

    if (!headers.containsKey("Content-type")) {
      throw new RestfulieException(
          "You should set a content type prior to sending some payload.");
    }


    StringWriter writer = new StringWriter();
    String type = headers.get("Content-type");
    try {
      type = type.split(";")[0];
      handlerFor(type).marshal(payload, writer, client);
      writer.flush();
     
      HttpEntityEnclosingRequestBase verb = (HttpEntityEnclosingRequestBase) verbFor(method, uri);
      add(verb, headers);
      String string = writer.getBuffer().toString();
      verb.setEntity(new StringEntity(string));
      return execute(details, verb);
    } catch (IOException e) {
      throw new RestfulieException("Unable to marshal entity.", e);
    }

  }
View Full Code Here

    } else if(method.equals("OPTIONS")) {
      return new HttpOptions(uri);
    } else if(method.equals("HEAD")) {
      return new HttpHead(uri);
    }
    throw new RestfulieException("You can not " + method + " to " + uri + ", there is no such verb in the apache http API.");
  }
View Full Code Here

        lastExecuted.discard();
      }
      HttpResponse response = http.execute(method, getContext());
      return responseFor(response, details);
    } catch (ClientProtocolException e) {
      throw new RestfulieException(
          "Unable to execute " + method.getURI(), e);
    } catch (IOException e) {
      throw new RestfulieException(
          "Unable to execute " + method.getURI(), e);
    }
  }
View Full Code Here

        return EntityUtils.toString(entity);
      } else {
        return "";
      }
    } catch (IOException ex) {
      throw new RestfulieException("Unable to parse response content", ex);
    }
  }
View Full Code Here

TOP

Related Classes of br.com.caelum.restfulie.RestfulieException

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.