blob: aef4ce970b40f17c73236e1a68347969ce7857a0 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../.resources/report.css" type="text/css"/><link rel="shortcut icon" href="../.resources/report.gif" type="image/gif"/><title>TrustException.java</title><link rel="stylesheet" href="../.resources/prettify.css" type="text/css"/><script type="text/javascript" src="../.resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../.sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Coverage Report</a> &gt; <a href="index.source.html" class="el_package">org.apache.rahas</a> &gt; <span class="el_source">TrustException.java</span></div><h1>TrustException.java</h1><pre class="source lang-java linenums">/*
* Copyright 2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
* 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 &quot;AS IS&quot; 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.apache.rahas;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class TrustException extends Exception {
private static final long serialVersionUID = -445341784514373965L;
public final static String INVALID_REQUEST = &quot;InvalidRequest&quot;;
public final static String FAILED_AUTHENTICATION = &quot;FailedAuthentication&quot;;
public final static String REQUEST_FAILED = &quot;RequestFailed&quot;;
public final static String INVALID_SECURITY_TOKEN = &quot;InvalidSecurityToken&quot;;
public final static String AUTHENTICATION_BAD_ELEMENTS = &quot;AuthenticationBadElements&quot;;
public final static String BAD_REQUEST = &quot;BadRequest&quot;;
public final static String EXPIRED_DATA = &quot;ExpiredData&quot;;
public final static String INVALID_TIME_RANGE = &quot;InvalidTimeRange&quot;;
public final static String INVALID_SCOPE = &quot;InvalidScope&quot;;
public final static String RENEW_NEEDED = &quot;RenewNeeded&quot;;
public final static String UNABLE_TO_RENEW = &quot;UnableToRenew&quot;;
private static ResourceBundle resources;
private String faultCode;
private String faultString;
static {
try {
<span class="fc" id="L47"> resources = ResourceBundle.getBundle(&quot;org.apache.rahas.errors&quot;);</span>
<span class="nc" id="L48"> } catch (MissingResourceException e) {</span>
<span class="nc" id="L49"> throw new RuntimeException(e.getMessage());</span>
<span class="fc" id="L50"> }</span>
<span class="fc" id="L51"> }</span>
public TrustException(String faultCode, Object[] args) {
<span class="fc" id="L54"> super(getMessage(faultCode, args));</span>
<span class="fc" id="L55"> this.faultCode = getFaultCode(faultCode);</span>
<span class="fc" id="L56"> this.faultString = getMessage(faultCode, args);</span>
<span class="fc" id="L57"> }</span>
/**
* Construct the fault properly code for the standard faults
* @param faultCode2
* @return
*/
private String getFaultCode(String code) {
<span class="pc bpc" id="L65" title="11 of 22 branches missed."> if(AUTHENTICATION_BAD_ELEMENTS.equals(code) ||</span>
BAD_REQUEST.equals(code) ||
EXPIRED_DATA.equals(code) ||
FAILED_AUTHENTICATION.equals(code) ||
INVALID_REQUEST.equals(code) ||
INVALID_SCOPE.equals(code) ||
INVALID_SECURITY_TOKEN.equals(code) ||
INVALID_TIME_RANGE.equals(code) ||
RENEW_NEEDED.equals(code) ||
REQUEST_FAILED.equals(code) ||
UNABLE_TO_RENEW.equals(code)) {
<span class="nc" id="L76"> return RahasConstants.WST_PREFIX + &quot;:&quot; + code;</span>
} else {
<span class="fc" id="L78"> return code;</span>
}
}
public TrustException(String faultCode) {
<span class="fc" id="L83"> this(faultCode, (Object[])null);</span>
<span class="fc" id="L84"> }</span>
public TrustException(String faultCode, Object[] args, Throwable e) {
<span class="nc" id="L87"> super(getMessage(faultCode, args),e);</span>
<span class="nc" id="L88"> this.faultCode = faultCode;</span>
<span class="nc" id="L89"> this.faultString = getMessage(faultCode, args);</span>
<span class="nc" id="L90"> }</span>
public TrustException(String faultCode, Throwable e) {
<span class="nc" id="L93"> this(faultCode, null, e);</span>
<span class="nc" id="L94"> }</span>
/**
* get the message from resource bundle.
*
* @return the message translated from the property (message) file.
*/
protected static String getMessage(String faultCode, Object[] args) {
<span class="fc" id="L102"> String msg = null;</span>
try {
<span class="fc" id="L104"> msg = MessageFormat.format(resources.getString(faultCode), args);</span>
<span class="nc" id="L105"> } catch (MissingResourceException e) {</span>
<span class="nc" id="L106"> throw new RuntimeException(&quot;Undefined '&quot; + faultCode + &quot;' resource property&quot;);</span>
<span class="fc" id="L107"> }</span>
<span class="pc bpc" id="L108" title="1 of 2 branches missed."> if(msg != null) {</span>
<span class="fc" id="L109"> return msg;</span>
} else {
<span class="nc" id="L111"> return faultCode;</span>
}
}
/**
* @return Returns the faultCode.
*/
protected String getFaultCode() {
<span class="nc" id="L119"> return faultCode;</span>
}
/**
* @return Returns the faultString.
*/
protected String getFaultString() {
<span class="nc" id="L126"> return faultString;</span>
}
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.5.201505241946</span></div></body></html>