001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.camel.component.http; 018 019 import java.io.InputStream; 020 import java.util.Map; 021 022 import org.apache.camel.CamelException; 023 import org.apache.camel.util.ObjectHelper; 024 025 public class HttpOperationFailedException extends CamelException { 026 private static final long serialVersionUID = -8721487434390572634L; 027 private final String uri; 028 private final String redirectLocation; 029 private final int statusCode; 030 private final String statusText; 031 private final Map<String, String> responseHeaders; 032 private final String responseBody; 033 034 public HttpOperationFailedException(String uri, int statusCode, String statusText, String location, Map<String, String> responseHeaders, String responseBody) { 035 super("HTTP operation failed invoking " + uri + " with statusCode: " + statusCode + (location != null ? ", redirectLocation: " + location : "")); 036 this.uri = uri; 037 this.statusCode = statusCode; 038 this.statusText = statusText; 039 this.redirectLocation = location; 040 this.responseHeaders = responseHeaders; 041 this.responseBody = responseBody; 042 } 043 044 public String getUri() { 045 return uri; 046 } 047 048 public boolean isRedirectError() { 049 return statusCode >= 300 && statusCode < 400; 050 } 051 052 public boolean hasRedirectLocation() { 053 return ObjectHelper.isNotEmpty(redirectLocation); 054 } 055 056 public String getRedirectLocation() { 057 return redirectLocation; 058 } 059 060 public int getStatusCode() { 061 return statusCode; 062 } 063 064 public String getStatusText() { 065 return statusText; 066 } 067 068 public Map<String, String> getResponseHeaders() { 069 return responseHeaders; 070 } 071 072 public String getResponseBody() { 073 return responseBody; 074 } 075 076 }