// Add the namespace to the lead context
org.xmlpull.infoset.XmlElement types = wsdl.getTypes();
// get the ns of schema from existing element
XmlNamespace schemaNs = BUILDER.newNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
addCrosscutImportsIfNecessary(wsdl);
org.xmlpull.infoset.XmlElement schema = BUILDER.newFragment(schemaNs, SCHEMA);
types.addElement(0, schema);
org.xmlpull.infoset.XmlElement importElement = BUILDER.newFragment(schema.getNamespace(), IMPORT);
importElement.setAttributeValue(NAMESPACE, LEAD_CONTEXT_HEADER_NS);
importElement.setAttributeValue(SCHEMA_LOCATION, SCHEMA_LOCATION_URI);
schema.addElement(0, importElement);
wsdl.xml().declareNamespace(BUILDER.newNamespace(LC, LEAD_CONTEXT_HEADER_NS));
Iterator<WsdlPortType> iterator = wsdl.portTypes().iterator();
while (iterator.hasNext()) {
WsdlPortType portType = iterator.next();
Iterator<WsdlPortTypeOperation> operations = portType.operations().iterator();
while (operations.hasNext()) {
WsdlPortTypeOperation operation = operations.next();
WsdlMessagePart leadHeaderPart = new WsdlMessagePart(LEAD_HEADER);
leadHeaderPart.setName(LEAD_HEADER);
// we hand set this element to xml because when you use the
// API it doent add the namespace correctly
leadHeaderPart.xml().setAttributeValue(ELEMENT, LC_CONTEXT);
wsdl.getMessage(operation.getInput().getMessage().getLocalPart()).addPart(leadHeaderPart);
}
}
Iterator<WsdlBinding> bindingItr = wsdl.bindings().iterator();
while (bindingItr.hasNext()) {
WsdlBinding wsdlBinding = (WsdlBinding) bindingItr.next();
Iterator<WsdlBindingOperation> operationsItr = wsdlBinding.operations().iterator();
while (operationsItr.hasNext()) {
WsdlBindingOperation wsdlBindingOperation = (WsdlBindingOperation) operationsItr.next();
org.xmlpull.infoset.XmlElement input = wsdlBindingOperation.xml().element(INPUT);
org.xmlpull.infoset.XmlElement body = input.element(BODY);
if (body == null) {
// This is a HTTP binding so continue with the next
continue;
}
body.setAttributeValue(PARTS, INPUT);
XmlNamespace ns = body.getNamespace();
org.xmlpull.infoset.XmlElement header = input.newElement(ns, HEADER);
header.setAttributeValue(PART, LEAD_HEADER);
header.setAttributeValue(USE, LITERAL);
String inputMessage = findInputMessage(wsdlBindingOperation, wsdl);