org.openestate.is24.restapi.utils.RequestFailedException Maven / Gradle / Ivy
/*
* Copyright 2014-2017 OpenEstate.org.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openestate.is24.restapi.utils;
import org.apache.commons.lang3.StringUtils;
import org.openestate.is24.restapi.xml.common.Message;
import org.openestate.is24.restapi.xml.common.Messages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Exception for failed Webservice requests.
*
* This exception is thrown, when a request to the Webservice failed. The
* exception holds further informations about the failed request.
*
* @since 0.1
* @author Andreas Rudolph
*/
public class RequestFailedException extends Exception
{
private final static long serialVersionUID = -5913145712963169005L;
private final static Logger LOGGER = LoggerFactory.getLogger( RequestFailedException.class );
/**
* Status code of the failed HTTP request.
*/
public final int statusCode;
/**
* Status message of the failed HTTP request.
*/
public final String statusMessage;
/**
* Unique identifier of the failed HTTP request.
*
* @since 0.2.2
*/
public final String requestRefNumber;
/**
* {@link Messages}, that were received in the body of the HTTP response.
*/
public final Messages responseMessages;
public RequestFailedException( Response response, String message )
{
super( message );
this.statusCode = response.statusCode;
this.statusMessage = StringUtils.trimToNull( response.statusMessage );
this.requestRefNumber = StringUtils.trimToNull( response.requestRefNumber );
Messages messages = null;
String body = StringUtils.trimToNull( response.body );
// parse messages from XML response
if (body!=null && body.startsWith( "
* This values was passed through the L-IS24-RequestRefnum header
* of the HTTP response.
*
* @return
* unique identifier
*
* @since 0.2.2
*/
public String getRequestRefNumber()
{
return requestRefNumber;
}
/**
* Return the {@link Messages}, that were received in the body of the HTTP
* response.
*
* @return
* messages
*
* @since 0.2.2
*/
public Messages getResponseMessages()
{
return responseMessages;
}
/**
* Return the status code of the HTTP response.
*
* @return
* status code
*
* @since 0.2.2
*/
public int getStatusCode()
{
return statusCode;
}
/**
* Return the status message of the HTTP response.
*
* @return
* status message
*
* @since 0.2.2
*/
public String getStatusMessage()
{
return statusMessage;
}
}