01: /*
02: * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.wso2.esb.services;
18:
19: import org.apache.axis2.AxisFault;
20: import org.apache.axis2.context.ConfigurationContext;
21: import org.apache.axis2.context.MessageContext;
22: import org.apache.axis2.description.Parameter;
23: import org.apache.axis2.engine.AxisConfiguration;
24: import org.apache.commons.logging.Log;
25: import org.apache.synapse.SynapseConstants;
26: import org.apache.synapse.config.SynapseConfiguration;
27: import org.apache.synapse.core.SynapseEnvironment;
28:
29: /*
30: * Abstract Class that handles Admin stuff
31: */
32:
33: public abstract class AbstractESBAdmin {
34:
35: public static final String LOGGED = "logged";
36:
37: public AxisConfiguration getAxisConfig() {
38: return MessageContext.getCurrentMessageContext()
39: .getConfigurationContext().getAxisConfiguration();
40: }
41:
42: public ConfigurationContext getConfigContext() {
43: return MessageContext.getCurrentMessageContext()
44: .getConfigurationContext();
45: }
46:
47: public SynapseConfiguration getSynapseConfiguration()
48: throws AxisFault {
49: Parameter synapseConfigParam = getAxisConfig().getParameter(
50: SynapseConstants.SYNAPSE_CONFIG);
51: if (synapseConfigParam == null) {
52: throw new AxisFault(
53: "Unable to find the Synapse configuration from"
54: + " the loaded Axis2 configuration");
55: }
56: return (SynapseConfiguration) synapseConfigParam.getValue();
57: }
58:
59: public SynapseEnvironment getSynapseEnvironment() throws AxisFault {
60: Parameter synapseEnvParam = getAxisConfig().getParameter(
61: SynapseConstants.SYNAPSE_ENV);
62: if (synapseEnvParam == null) {
63: throw new AxisFault(
64: "Unable to find the Synapse Environment from"
65: + " the loaded Axis2 configuration");
66: }
67: return (SynapseEnvironment) synapseEnvParam.getValue();
68: }
69:
70: protected void handleFault(Log log, String message, Exception e)
71: throws AxisFault {
72:
73: if (e == null) {
74: AxisFault af = new AxisFault(message);
75: log.error(message, af);
76: throw af;
77:
78: } else {
79: message = message + " :: " + e.getMessage();
80: log.error(message, e);
81: throw new AxisFault(message, e);
82: }
83: }
84: }
|