* @param proxyXML88 proxy service configuration
* @return the <code>ProxyData</code> object populated with given information
* @throws AxisFault if the given XML cannot be parsed
*/
public ProxyData getDesignView(String proxyXML88) throws AxisFault {
ProxyData pd = new ProxyData();
try {
OMElement elem = new StAXOMBuilder(
new ByteArrayInputStream(proxyXML88.getBytes())).getDocumentElement();
// check whether synapse namespace is present in the configuration.
Iterator itr = elem.getAllDeclaredNamespaces();
OMNamespace ns;
boolean synapseNSPresent = false;
while (itr.hasNext()) {
ns = (OMNamespace)itr.next();
if (XMLConfigConstants.SYNAPSE_NAMESPACE.equals(ns.getNamespaceURI())) {
synapseNSPresent = true;
break;
}
}
if (!synapseNSPresent) {
// Oops! synpase namespace is not present
throw new AxisFault(bundle.getString("synapse.namespace.not.present"));
}
OMAttribute name = elem.getAttribute(new QName("name"));
if (name != null) {
pd.setName(name.getAttributeValue());
}
OMAttribute statistics = elem.getAttribute(new QName(XMLConfigConstants.STATISTICS_ATTRIB_NAME));
if (statistics != null) {
String statisticsValue = statistics.getAttributeValue();
if (statisticsValue != null) {
if (XMLConfigConstants.STATISTICS_ENABLE.equals(statisticsValue)) {
pd.setEnableStatistics(true);
} else if (XMLConfigConstants.STATISTICS_DISABLE.equals(statisticsValue)) {
pd.setEnableStatistics(false);
}
}
}
OMAttribute trans = elem.getAttribute(new QName("transports"));
if (trans != null) {
String transports = trans.getAttributeValue();
if (transports == null || "".equals(transports) ||ProxyService.ALL_TRANSPORTS.equals(transports)) {
// default to all transports using service name as destination
} else {
String [] arr = transports.split(",");
if (arr != null && arr.length != 0) {
pd.setTransports(arr);
}
}
}
OMAttribute pinnedServers = elem.getAttribute(new QName("pinnedServers"));
if (pinnedServers != null) {
String pinnedServersValue = pinnedServers.getAttributeValue();
if (pinnedServersValue == null || "".equals(pinnedServersValue)) {
// default to all servers
} else {
String [] arr = pinnedServersValue.split(",");
if (arr != null && arr.length != 0) {
pd.setPinnedServers(arr);
}
}
}
OMAttribute trace = elem.getAttribute(new QName(XMLConfigConstants.TRACE_ATTRIB_NAME));
if (trace != null) {
String traceValue = trace.getAttributeValue();
if (traceValue != null) {
if (traceValue.equals(XMLConfigConstants.TRACE_ENABLE)) {
pd.setEnableTracing(true);
} else if (traceValue.equals(XMLConfigConstants.TRACE_DISABLE)) {
pd.setEnableTracing(false);
}
}
}
OMAttribute startOnLoad = elem.getAttribute(new QName("startOnLoad"));
String val;
if (startOnLoad != null && (val = startOnLoad.getAttributeValue()) != null && !"".equals(val)) {
pd.setStartOnLoad(Boolean.valueOf(val));
} else {
pd.setStartOnLoad(true);
}
// read definition of the target of this proxy service. The target could be an 'endpoint'
// or a named sequence. If none of these are specified, the messages would be mediated
// by the Synapse main mediator
OMElement target = elem.getFirstChildWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "target"));
if (target != null) {
OMAttribute inSequence = target.getAttribute(new QName("inSequence"));
if (inSequence != null) {
pd.setInSeqKey(inSequence.getAttributeValue());
} else {
OMElement inSequenceElement = target.getFirstChildWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "inSequence"));
if (inSequenceElement != null) {
pd.setInSeqXML(inSequenceElement.toString());
}
}
OMAttribute outSequence = target.getAttribute(new QName("outSequence"));
if (outSequence != null) {
pd.setOutSeqKey(outSequence.getAttributeValue());
} else {
OMElement outSequenceElement = target.getFirstChildWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "outSequence"));
if (outSequenceElement != null) {
pd.setOutSeqXML(outSequenceElement.toString());
}
}
OMAttribute faultSequence = target.getAttribute(new QName("faultSequence"));
if (faultSequence != null) {
pd.setFaultSeqKey(faultSequence.getAttributeValue());
} else {
OMElement faultSequenceElement = target.getFirstChildWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "faultSequence"));
if (faultSequenceElement != null) {
pd.setFaultSeqXML(faultSequenceElement.toString());
}
}
OMAttribute tgtEndpt = target.getAttribute(new QName("endpoint"));
if (tgtEndpt != null) {
pd.setEndpointKey(tgtEndpt.getAttributeValue());
} else {
OMElement endpointElement = target.getFirstChildWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "endpoint"));
if (endpointElement != null) {
pd.setEndpointXML(endpointElement.toString());
}
}
}
Iterator props = elem.getChildrenWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "parameter"));
ArrayList <Entry> params = new ArrayList<Entry>();
Entry entry = null;
while (props.hasNext()) {
Object o = props.next();
if (o instanceof OMElement) {
OMElement prop = (OMElement) o;
OMAttribute pname = prop.getAttribute(new QName("name"));
OMElement propertyValue = prop.getFirstElement();
if (pname != null) {
if (propertyValue != null) {
entry = new Entry();
entry.setKey(pname.getAttributeValue());
entry.setValue(propertyValue.toString());
params.add(entry);
} else {
entry = new Entry();
entry.setKey(pname.getAttributeValue());
entry.setValue(prop.getText().trim());
params.add(entry);
}
}
}
}
pd.setServiceParams(params.toArray(new Entry[params.size()]));
OMElement wsdl = elem.getFirstChildWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "publishWSDL"));
if (wsdl != null) {
OMAttribute wsdlkey = wsdl.getAttribute(
new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
if (wsdlkey != null) {
pd.setWsdlKey(wsdlkey.getAttributeValue());
} else {
OMAttribute wsdlURI = wsdl.getAttribute(
new QName(XMLConfigConstants.NULL_NAMESPACE, "uri"));
if (wsdlURI != null) {
pd.setWsdlURI(wsdlURI.getAttributeValue());
} else {
OMElement wsdl11 = wsdl.getFirstChildWithName(
new QName(WSDLConstants.WSDL1_1_NAMESPACE, "definitions"));
String wsdlDef;
if (wsdl11 != null) {
wsdlDef = wsdl11.toString().replaceAll("\n|\\r|\\f|\\t", "");
wsdlDef = wsdlDef.replaceAll("> +<", "><");
pd.setWsdlDef(wsdlDef);
} else {
OMElement wsdl20 = wsdl.getFirstChildWithName(
new QName(WSDL2Constants.WSDL_NAMESPACE, "description"));
if (wsdl20 != null) {
wsdlDef = wsdl20.toString().replaceAll("\n|\\r|\\f|\\t", "");
wsdlDef = wsdlDef.replaceAll("> +<", "><");
pd.setWsdlDef(wsdlDef);
}
}
}
}
Iterator it = wsdl.getChildrenWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "resource"));
ArrayList <Entry> resources = new ArrayList<Entry>();
Entry resource = null;
while (it.hasNext()) {
OMElement resourceElem = (OMElement)it.next();
OMAttribute location = resourceElem.getAttribute
(new QName(XMLConfigConstants.NULL_NAMESPACE, "location"));
if (location == null) {
// todo handle exception
}
OMAttribute key = resourceElem.getAttribute(
new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
if (key == null) {
// todo handle exception
}
resource = new Entry();
resource.setKey(location.getAttributeValue());
resource.setValue(key.getAttributeValue());
resources.add(resource);
}
pd.setWsdlResources(resources.toArray(new Entry[resources.size()]));
}
OMElement enableSec = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE,
"enableSec"));
if (enableSec != null) {
pd.setEnableSecurity(true);
}
} catch (XMLStreamException e) {
handleException(bundle.getString("unable.to.build.the.design.view.from.the.given.xml"), e);
}