У нас есть веб-службы отдыха с использованием spring и cxf. Когда выбрано исключенное исключение, мы получаем правильное локализованное исключение через soap ui.Rest Webservices Исключительная трассировка стека вывода
Но когда выбрано исключение безотказной работы, мы просто получаем трассировку стека, в которой веб-служба не может быть загружена.
@XmlType
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class WebServiceExceptionWrapper extends Exception {
/** Type (class name). */
private String type;
/** Message. */
private String message;
/** Stack trace. */
private StackTraceElement[] stackTrace;
/** Cause. */
private Throwable cause;
/** The localized message. */
private String localeErrorCode;
/**
* Construct a wrapper around an exception.
*
* @param e exception
*/
public WebServiceExceptionWrapper(final Exception e) {
this.type = e.getClass().getName();
this.message = StringEscapeUtils.escapeHtml(e.getLocalizedMessage());
this.stackTrace = e.getStackTrace();
this.cause = e.getCause();
if(e instanceof DetailedException) {
this.localeErrorCode = StringEscapeUtils.escapeHtml(((DetailedException) e).getLocaleErrorCode());
}
}
/**
* Gets the type.
*
* @return the type
*/
@XmlElement(nillable = true)
public String getType() {
return this.type;
}
/**
* Sets the type.
*
* @param type the type to set
*/
public void setType(final String type) {
this.type = type;
}
/**
* Gets the message.
*
* @return the message
*/
@XmlElement(nillable = true)
public String getMessage() {
return this.message;
}
/**
* Sets the message.
*
* @param message the message to set
*/
public void setMessage(final String message) {
this.message = message;
}
/**
* Gets the stackTrace.
*
* @return the stackTrace
*/
@XmlElement(nillable = true)
public StackTraceElement[] getStackTrace() {
return this.stackTrace;
}
/**
* Sets the stackTrace.
*
* @param stackTrace the stackTrace to set
*/
public void setStackTrace(final StackTraceElement[] stackTrace) {
this.stackTrace = stackTrace;
}
/**
* Gets the cause.
*
* @return the cause
*/
@XmlElement(nillable = true)
public Throwable getCause() {
return this.cause;
}
/**
* Sets the cause.
*
* @param cause the cause to set
*/
public void setCause(final Throwable cause) {
this.cause = cause;
}
/**
* @return the localeErrorCode
*/
@XmlElement(nillable = true)
public String getLocaleErrorCode() {
return this.localeErrorCode;
}
/**
* @param localeErrorCode the localeErrorCode to set
*/
public void setLocaleErrorCode(final String localeErrorCode) {
this.localeErrorCode = localeErrorCode;
}
Как я предотвращаю возврат трассировки стека. Мне просто нужен код ответа и ответное сообщение.
но как мы справляемся с w с ошибками? –
Что вы имеете в виду, как мы имеем дело с ошибками? Структура будет обрабатывать все, что вы явно не согласовываете, преобразовывая ее в 500, что, вероятно, является наиболее правильным поведением. – fpmoles