Пример #1
0
  public Object doTransform(Object src, String encoding) throws TransformerException {
    Object msg;
    HttpMethod httpMethod = (HttpMethod) src;
    Header contentType = httpMethod.getResponseHeader(HttpConstants.HEADER_CONTENT_TYPE);
    try {
      if (contentType != null && !contentType.getValue().startsWith("text/")) {
        msg = httpMethod.getResponseBody();
      } else {
        msg = httpMethod.getResponseBodyAsString();
      }
    } catch (IOException e) {
      throw new TransformerException(this, e);
    }
    // Standard headers
    Map headerProps = new HashMap();
    Header[] headers = httpMethod.getRequestHeaders();
    String name;
    for (int i = 0; i < headers.length; i++) {
      name = headers[i].getName();
      if (name.startsWith("X-" + MuleProperties.PROPERTY_PREFIX)) {
        name = name.substring(2);
      }
      headerProps.put(headers[i].getName(), headers[i].getValue());
    }
    // Set Mule Properties

    return new MuleMessage(msg, headerProps);
  }
  protected boolean hasRequestHeader(HttpMethod httpMethod, String name) {
    Header[] headers = httpMethod.getRequestHeaders(name);

    if (headers.length == 0) {
      return false;
    } else {
      return true;
    }
  }
Пример #3
0
 private String getHttpRequestHeader(HttpMethod method) {
   StringBuilder strHeader = new StringBuilder();
   Header[] headers = method.getRequestHeaders();
   for (Header header : headers) {
     String name = header.getName();
     String value = header.getValue();
     strHeader.append(name + "=" + value + ";");
   }
   return strHeader.toString();
 }