use of org.apache.axis2.wsdl.SOAPHeaderMessage in project axis-axis2-java-core by apache.
the class WSDLSerializationUtil method addSOAPHeaderElements.
/**
* Adds a soap header element to a given OMElement
* @param omFactory - An OMFactory
* @param list - The arraylist of soapHeaderMessages
* @param wsoap - The WSDL 2.0 SOAP namespace
* @param element - The element that the header should be added to
* @param nameSpaceMap - The namespaceMap
*/
public static void addSOAPHeaderElements(OMFactory omFactory, ArrayList list, OMNamespace wsoap, OMElement element, Map nameSpaceMap) {
for (int i = 0; i < list.size(); i++) {
SOAPHeaderMessage soapHeaderMessage = (SOAPHeaderMessage) list.get(i);
OMElement soapHeaderElement = omFactory.createOMElement(WSDL2Constants.ATTRIBUTE_HEADER, wsoap);
QName qName = soapHeaderMessage.getElement();
soapHeaderElement.addAttribute(omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_ELEMENT, null, getPrefix(qName.getNamespaceURI(), nameSpaceMap) + ":" + qName.getLocalPart()));
soapHeaderElement.addAttribute(omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_MUST_UNDERSTAND, null, Boolean.toString(soapHeaderMessage.isMustUnderstand())));
soapHeaderElement.addAttribute(omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_REQUIRED, null, Boolean.toString(soapHeaderMessage.isRequired())));
element.addChild(soapHeaderElement);
}
}
use of org.apache.axis2.wsdl.SOAPHeaderMessage in project axis-axis2-java-core by apache.
the class WSDL11ToAxisServiceBuilder method populateBinding.
private void populateBinding(AxisBinding axisBinding, Binding wsdl4jBinding, Definition bindingWSDL, PortType portType, boolean isSetMessageQNames) throws AxisFault {
copyExtensibleElements(wsdl4jBinding.getExtensibilityElements(), bindingWSDL, axisBinding, BINDING);
List wsdl4jBidingOperations = wsdl4jBinding.getBindingOperations();
if (wsdl4jBidingOperations.size() < 1) {
throw new AxisFault("No operation found for the binding");
}
addDocumentation(axisBinding, wsdl4jBinding.getDocumentationElement());
AxisOperation axisOperation;
Operation wsdl4jOperation;
AxisBindingOperation axisBindingOperation;
BindingOperation wsdl4jBindingOperation;
Map httpLocationMap = createHttpLocationTable();
String httpLocation = null;
for (Iterator iterator = wsdl4jBidingOperations.iterator(); iterator.hasNext(); ) {
axisBindingOperation = new AxisBindingOperation();
wsdl4jBindingOperation = (BindingOperation) iterator.next();
wsdl4jOperation = findOperation(portType, wsdl4jBindingOperation);
axisBindingOperation.setName(new QName(bindingWSDL.getTargetNamespace(), wsdl4jBindingOperation.getName()));
addDocumentation(axisBindingOperation, wsdl4jBindingOperation.getDocumentationElement());
axisOperation = axisService.getOperation(new QName(portType.getQName().getNamespaceURI(), wsdl4jOperation.getName()));
axisBindingOperation.setAxisOperation(axisOperation);
// process ExtensibilityElements of the wsdl4jBinding
copyExtensibleElements(wsdl4jBindingOperation.getExtensibilityElements(), wsdl4jDefinition, axisBindingOperation, BINDING_OPERATION);
httpLocation = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_LOCATION);
String httpMethod = (String) axisBindingOperation.getProperty(WSDL2Constants.ATTR_WHTTP_METHOD);
if (httpMethod == null || "".equals(httpMethod)) {
httpMethod = HTTPConstants.HEADER_POST;
}
if (httpLocation != null) {
httpLocationMap.put(WSDLUtil.getConstantFromHTTPLocation(httpLocation, httpMethod), axisBindingOperation.getAxisOperation());
}
BindingInput wsdl4jBindingInput = wsdl4jBindingOperation.getBindingInput();
if (isServerSide) {
if (wsdl4jBindingInput != null && WSDLUtil.isInputPresentForMEP(axisOperation.getMessageExchangePattern())) {
AxisBindingMessage axisBindingInMessage = new AxisBindingMessage();
axisBindingInMessage.setParent(axisBindingOperation);
addDocumentation(axisBindingInMessage, wsdl4jBindingInput.getDocumentationElement());
copyExtensibleElements(wsdl4jBindingInput.getExtensibilityElements(), wsdl4jDefinition, axisBindingInMessage, BINDING_OPERATION_INPUT);
AxisMessage axisInMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
// This is a hack to get AXIS2-2771 working , I had to copy soap headers
// from binding message to AxisMessage
List soapHeaders = (List) axisBindingInMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
if (soapHeaders != null) {
for (int i = 0; i < soapHeaders.size(); i++) {
SOAPHeaderMessage headerMessage = (SOAPHeaderMessage) soapHeaders.get(i);
axisInMessage.addSoapHeader(headerMessage);
}
}
if (isSetMessageQNames) {
BindingOperationEntry boe = find(wrappableBOEs, wsdl4jBindingOperation);
boolean isWrapped = (boe == null) ? false : boe.isWrappedInput();
addQNameReference(axisInMessage, wsdl4jOperation, wsdl4jBindingInput, isWrapped);
}
axisBindingInMessage.setAxisMessage(axisInMessage);
axisBindingInMessage.setName(axisInMessage.getName());
axisBindingInMessage.setDirection(axisInMessage.getDirection());
axisBindingOperation.addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, axisBindingInMessage);
}
} else {
if (wsdl4jBindingInput != null && WSDLUtil.isOutputPresentForMEP(axisOperation.getMessageExchangePattern())) {
AxisBindingMessage axisBindingOutMessage = new AxisBindingMessage();
axisBindingOutMessage.setParent(axisBindingOperation);
addDocumentation(axisBindingOutMessage, wsdl4jBindingInput.getDocumentationElement());
copyExtensibleElements(wsdl4jBindingInput.getExtensibilityElements(), wsdl4jDefinition, axisBindingOutMessage, BINDING_OPERATION_OUTPUT);
AxisMessage axisOutMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
// This is a hack to get AXIS2-2771 working , I had to copy soap headers
// from binding message to AxisMessage
List soapHeaders = (List) axisBindingOutMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
if (soapHeaders != null) {
for (int i = 0; i < soapHeaders.size(); i++) {
SOAPHeaderMessage headerMessage = (SOAPHeaderMessage) soapHeaders.get(i);
axisOutMessage.addSoapHeader(headerMessage);
}
}
if (isSetMessageQNames) {
BindingOperationEntry boe = find(wrappableBOEs, wsdl4jBindingOperation);
boolean isWrapped = (boe == null) ? false : boe.isWrappedInput();
addQNameReference(axisOutMessage, wsdl4jOperation, wsdl4jBindingInput, isWrapped);
}
axisBindingOutMessage.setAxisMessage(axisOutMessage);
axisBindingOutMessage.setName(axisOutMessage.getName());
axisBindingOutMessage.setDirection(axisOutMessage.getDirection());
axisBindingOperation.addChild(WSDLConstants.MESSAGE_LABEL_OUT_VALUE, axisBindingOutMessage);
}
}
BindingOutput wsdl4jBindingOutput = wsdl4jBindingOperation.getBindingOutput();
if (isServerSide) {
if (wsdl4jBindingOutput != null && WSDLUtil.isOutputPresentForMEP(axisOperation.getMessageExchangePattern())) {
AxisBindingMessage axisBindingOutMessage = new AxisBindingMessage();
axisBindingOutMessage.setParent(axisBindingOperation);
addDocumentation(axisBindingOutMessage, wsdl4jBindingOutput.getDocumentationElement());
AxisMessage axisOutMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
copyExtensibleElements(wsdl4jBindingOutput.getExtensibilityElements(), wsdl4jDefinition, axisBindingOutMessage, BINDING_OPERATION_OUTPUT);
// This is a hack to get AXIS2-2771 working , I had to copy soap headers
// from binding message to AxisMessage
List soapHeaders = (List) axisBindingOutMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
if (soapHeaders != null) {
for (int i = 0; i < soapHeaders.size(); i++) {
SOAPHeaderMessage headerMessage = (SOAPHeaderMessage) soapHeaders.get(i);
axisOutMessage.addSoapHeader(headerMessage);
}
}
if (isSetMessageQNames) {
BindingOperationEntry boe = find(wrappableBOEs, wsdl4jBindingOperation);
boolean isWrapped = (boe == null) ? false : boe.isWrappedOutput();
axisOutMessage.setWrapped(isWrapped);
addQNameReference(axisOutMessage, wsdl4jOperation, wsdl4jBindingOutput, isWrapped);
}
axisBindingOutMessage.setAxisMessage(axisOutMessage);
axisBindingOutMessage.setName(axisOutMessage.getName());
axisBindingOutMessage.setDirection(axisOutMessage.getDirection());
axisBindingOperation.addChild(WSDLConstants.MESSAGE_LABEL_OUT_VALUE, axisBindingOutMessage);
}
} else {
if (wsdl4jBindingOutput != null && WSDLUtil.isInputPresentForMEP(axisOperation.getMessageExchangePattern())) {
AxisBindingMessage axisBindingInMessage = new AxisBindingMessage();
axisBindingInMessage.setParent(axisBindingOperation);
addDocumentation(axisBindingInMessage, wsdl4jBindingOutput.getDocumentationElement());
AxisMessage axisInMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
copyExtensibleElements(wsdl4jBindingOutput.getExtensibilityElements(), wsdl4jDefinition, axisBindingInMessage, BINDING_OPERATION_INPUT);
// This is a hack to get AXIS2-2771 working , I had to copy soap headers
// from binding message to AxisMessage
List soapHeaders = (List) axisBindingInMessage.getProperty(WSDL2Constants.ATTR_WSOAP_HEADER);
if (soapHeaders != null) {
for (int i = 0; i < soapHeaders.size(); i++) {
SOAPHeaderMessage headerMessage = (SOAPHeaderMessage) soapHeaders.get(i);
axisInMessage.addSoapHeader(headerMessage);
}
}
if (isSetMessageQNames) {
BindingOperationEntry boe = find(wrappableBOEs, wsdl4jBindingOperation);
boolean isWrapped = (boe == null) ? false : boe.isWrappedOutput();
axisInMessage.setWrapped(isWrapped);
addQNameReference(axisInMessage, wsdl4jOperation, wsdl4jBindingOutput, isWrapped);
}
axisBindingInMessage.setAxisMessage(axisInMessage);
axisBindingInMessage.setName(axisInMessage.getName());
axisBindingInMessage.setDirection(axisInMessage.getDirection());
axisBindingOperation.addChild(WSDLConstants.MESSAGE_LABEL_IN_VALUE, axisBindingInMessage);
}
}
Map bindingFaultsMap = wsdl4jBindingOperation.getBindingFaults();
/* process the binding faults */
for (Iterator bindingFaults = bindingFaultsMap.values().iterator(); bindingFaults.hasNext(); ) {
BindingFault bindingFault = (BindingFault) bindingFaults.next();
if (bindingFault.getName() == null) {
throw new AxisFault("Binding name is null for the binding fault in " + " binding operation ==> " + wsdl4jBindingOperation.getName());
} else {
Fault wsdl4jFault = wsdl4jOperation.getFault(bindingFault.getName());
if (wsdl4jFault == null) {
throw new AxisFault("Can not find the corresponding fault element in " + "wsdl operation " + wsdl4jOperation.getName() + " for the fault" + " name " + bindingFault.getName());
} else {
Message wsdl4jFaultMessge = wsdl4jFault.getMessage();
AxisMessage faultMessage = findFaultMessage(wsdl4jFault.getName(), axisOperation.getFaultMessages());
AxisBindingMessage axisBindingFaultMessage = new AxisBindingMessage();
addDocumentation(axisBindingFaultMessage, wsdl4jFaultMessge.getDocumentationElement());
axisBindingFaultMessage.setFault(true);
axisBindingFaultMessage.setAxisMessage(faultMessage);
axisBindingFaultMessage.setName(faultMessage.getName());
axisBindingFaultMessage.setParent(axisBindingOperation);
axisBindingOperation.addFault(axisBindingFaultMessage);
if (isSetMessageQNames) {
addQNameReference(faultMessage, wsdl4jFault.getMessage());
}
}
}
}
axisBindingOperation.setParent(axisBinding);
axisBinding.addChild(axisBindingOperation.getName(), axisBindingOperation);
}
axisBinding.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, httpLocationMap);
}
use of org.apache.axis2.wsdl.SOAPHeaderMessage in project axis-axis2-java-core by apache.
the class CodeGenerationUtility method engage.
/**
* Configure the code generation based on the supplied parameters and WSDL. This first gets type
* mappings from binding definition, then goes through the operations checking the input and
* output messages. If unwrapping is disabled the message element must be handled directly by a
* mapping. If unwrapping is enabled, this checks that the message element is of the proper form
* (a sequence of other elements, which all have maxOccurs="1"). It then generates an unwrapping
* description and adds it to the code generation configuration, where it'll be picked up and
* included in the XML passed to code generation. This also constructs a type mapping, since
* that's required by the base Axis2 code generation. In the case of unwrapped elements, the
* type mapping includes a synthesized qname for each unwrapped parameter, and the detailed
* information is set on the message information. Sound confusing? Welcome to Axis2 code
* generation.
*
* @param path binding path (<code>null</code> if none)
*/
public void engage(String path) {
// make sure the binding definition file is present, if passed
File file = null;
if (path != null) {
file = new File(path);
if (!file.exists()) {
throw new RuntimeException("jibx binding definition file " + path + " not found");
}
}
try {
// set flag for unwrapping
boolean unwrap = !codeGenConfig.isParametersWrapped();
// initialize the binding information
BindingElement binding = null;
if (file == null) {
// unwrapped can be used without a binding, but wrapped requires one
if (!unwrap) {
throw new RuntimeException("JiBX wrapped support requires a binding definition to be provided using the -E" + JiBXExtension.BINDING_PATH_OPTION + " {file-path} parameter");
}
} else {
// Read the JiBX binding definition into memory. The binding definition
// is only prevalidated so as not to require the user to have all
// the referenced classes in the classpath, though this does make for
// added work in finding the namespaces.
ValidationContext vctx = BindingElement.newValidationContext();
binding = BindingElement.readBinding(new FileInputStream(file), path, vctx);
binding.setBaseUrl(file.toURI().toURL());
vctx.setBindingRoot(binding);
IncludePrevalidationVisitor ipv = new IncludePrevalidationVisitor(vctx);
vctx.tourTree(binding, ipv);
if (vctx.getErrorCount() != 0 || vctx.getFatalCount() != 0) {
ArrayList probs = vctx.getProblems();
System.err.println("Errors in generated binding:");
for (int j = 0; j < probs.size(); j++) {
ValidationProblem prob = (ValidationProblem) probs.get(j);
System.err.print(prob.getSeverity() >= ValidationProblem.ERROR_LEVEL ? "Error: " : "Warning: ");
System.err.println(prob.getDescription());
}
throw new RuntimeException("invalid jibx binding definition file " + path);
}
}
// create table with all built-in format definitions
Map simpleTypeMap = new HashMap();
buildFormat("byte", "byte", "org.jibx.runtime.Utility.serializeByte", "org.jibx.runtime.Utility.parseByte", "0", simpleTypeMap);
buildFormat("unsignedShort", "char", "org.jibx.runtime.Utility.serializeChar", "org.jibx.runtime.Utility.parseChar", "0", simpleTypeMap);
buildFormat("double", "double", "org.jibx.runtime.Utility.serializeDouble", "org.jibx.runtime.Utility.parseDouble", "0.0", simpleTypeMap);
buildFormat("float", "float", "org.jibx.runtime.Utility.serializeFloat", "org.jibx.runtime.Utility.parseFloat", "0.0", simpleTypeMap);
buildFormat("int", "int", "org.jibx.runtime.Utility.serializeInt", "org.jibx.runtime.Utility.parseInt", "0", simpleTypeMap);
buildFormat("long", "long", "org.jibx.runtime.Utility.serializeLong", "org.jibx.runtime.Utility.parseLong", "0", simpleTypeMap);
buildFormat("short", "short", "org.jibx.runtime.Utility.serializeShort", "org.jibx.runtime.Utility.parseShort", "0", simpleTypeMap);
buildFormat("boolean", "boolean", "org.jibx.runtime.Utility.serializeBoolean", "org.jibx.runtime.Utility.parseBoolean", "false", simpleTypeMap);
buildFormat("dateTime", "java.util.Date", "org.jibx.runtime.Utility.serializeDateTime", "org.jibx.runtime.Utility.deserializeDateTime", null, simpleTypeMap);
buildFormat("date", "java.sql.Date", "org.jibx.runtime.Utility.serializeSqlDate", "org.jibx.runtime.Utility.deserializeSqlDate", null, simpleTypeMap);
buildFormat("time", "java.sql.Time", "org.jibx.runtime.Utility.serializeSqlTime", "org.jibx.runtime.Utility.deserializeSqlTime", null, simpleTypeMap);
buildFormat("base64Binary", "byte[]", "org.jibx.runtime.Utility.serializeBase64", "org.jibx.runtime.Utility.deserializeBase64", null, simpleTypeMap);
buildFormat("string", "java.lang.String", null, null, null, simpleTypeMap);
// collect all the top-level mapping and format definitions
Map elementMap = new HashMap();
Map complexTypeMap = new HashMap();
Map bindingMap = new HashMap();
if (binding != null) {
collectTopLevelComponents(binding, "", elementMap, complexTypeMap, simpleTypeMap, bindingMap);
}
// make sure classes will be generated for abstract mappings
if (unwrap && complexTypeMap.size() > 0 && (binding == null || !binding.isForceClasses())) {
throw new RuntimeException("unwrapped binding must use force-classes='true' option in " + path);
}
// force off inappropriate option (set by error in options handling)
codeGenConfig.setPackClasses(false);
// configure handling for all operations of service
codeGenConfig.setTypeMapper(new NamedParameterTypeMapper());
Iterator operations = codeGenConfig.getAxisService().getOperations();
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
int opindex = 0;
Map typeMappedClassMap = new HashMap();
String mappedclass = null;
Set objins = new HashSet();
Set objouts = new HashSet();
Set objfaults = new HashSet();
Map nsMap = new HashMap();
ArrayList wrappers = new ArrayList();
while (operations.hasNext()) {
// get the basic operation information
AxisOperation op = (AxisOperation) operations.next();
String mep = op.getMessageExchangePattern();
AxisMessage inmsg = null;
AxisMessage outmsg = null;
if (WSDLUtil.isInputPresentForMEP(mep)) {
inmsg = op.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
if (inmsg == null) {
throw new RuntimeException("Expected input message not found for operation " + op.getName());
}
ArrayList headers = inmsg.getSoapHeaders();
for (int i = 0; i < headers.size(); i++) {
SOAPHeaderMessage header = (SOAPHeaderMessage) headers.get(i);
String cname = mapMessage(header, elementMap);
objins.add(cname);
if (mappedclass == null && isLookupClass(cname)) {
mappedclass = cname;
}
}
}
if (WSDLUtil.isOutputPresentForMEP(mep)) {
outmsg = op.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
if (outmsg == null) {
throw new RuntimeException("Expected output message not found for operation " + op.getName());
}
ArrayList headers = outmsg.getSoapHeaders();
for (int i = 0; i < headers.size(); i++) {
SOAPHeaderMessage header = (SOAPHeaderMessage) headers.get(i);
String cname = mapMessage(header, elementMap);
objouts.add(cname);
if (mappedclass == null && isLookupClass(cname)) {
mappedclass = cname;
}
}
}
if (unwrap) {
// use unwrapping for both input and output
String receivername = "jibxReceiver" + opindex++;
Element dbmethod = doc.createElement("dbmethod");
dbmethod.setAttribute("receiver-name", receivername);
dbmethod.setAttribute("method-name", op.getName().getLocalPart());
Set nameset = new HashSet(s_reservedWords);
if (inmsg != null) {
Element wrapper = unwrapMessage(inmsg, false, simpleTypeMap, elementMap, complexTypeMap, typeMappedClassMap, bindingMap, nameset, nsMap, doc);
dbmethod.appendChild(wrapper);
wrappers.add(wrapper);
}
if (outmsg != null) {
Element wrapper = unwrapMessage(outmsg, true, simpleTypeMap, elementMap, complexTypeMap, typeMappedClassMap, bindingMap, nameset, nsMap, doc);
dbmethod.appendChild(wrapper);
wrappers.add(wrapper);
}
// save unwrapping information for use in code generation
op.addParameter(new Parameter(Constants.DATABINDING_GENERATED_RECEIVER, receivername));
op.addParameter(new Parameter(Constants.DATABINDING_GENERATED_IMPLEMENTATION, Boolean.TRUE));
op.addParameter(new Parameter(Constants.DATABINDING_OPERATION_DETAILS, dbmethod));
} else {
// concrete mappings, just save the mapped class name(s)
if (inmsg != null) {
String cname = mapMessage(inmsg, elementMap);
objins.add(cname);
if (mappedclass == null && isLookupClass(cname)) {
mappedclass = cname;
}
}
if (outmsg != null) {
String cname = mapMessage(outmsg, elementMap);
objouts.add(cname);
if (mappedclass == null && isLookupClass(cname)) {
mappedclass = cname;
}
}
}
// always handle faults as wrapped
for (Iterator iter = op.getFaultMessages().iterator(); iter.hasNext(); ) {
String cname = mapMessage((AxisMessage) iter.next(), elementMap);
objfaults.add(cname);
if (mappedclass == null && isLookupClass(cname)) {
mappedclass = cname;
}
}
}
// check for default namespace usage within bindings or wrappers
// (meaning we can't declare a conflicting default namespace)
Collection prefixes = nsMap.values();
boolean dfltns = prefixes.contains("");
boolean wrapdflt = false;
if (!dfltns) {
for (int i = 0; i < wrappers.size(); i++) {
Element wrapper = (Element) wrappers.get(i);
if ("true".equals(wrapper.getAttribute("uses-default"))) {
wrapdflt = true;
break;
}
}
}
// find a prefix that we can use where needed for extra namespace
String xtrapref = "";
if (dfltns || wrapdflt) {
xtrapref = "_";
int index = 0;
while (prefixes.contains(xtrapref)) {
xtrapref = "_" + index++;
}
}
// element
for (int i = 0; i < wrappers.size(); i++) {
Element wrapper = (Element) wrappers.get(i);
boolean addns = false;
String ns = wrapper.getAttribute("ns");
String prefix = "";
if ("true".equals(wrapper.getAttribute("need-namespaces"))) {
// check extra definition needed for wrapper namespace
if (!"".equals(ns)) {
if (dfltns || wrapdflt) {
// need a namespace, can't be default, get or set it
prefix = (String) nsMap.get(ns);
if (prefix == null) {
prefix = xtrapref;
addns = true;
}
} else {
// just make the wrapper namespace the default
prefix = "";
addns = true;
}
}
wrapper.setAttribute("prefix", prefix);
// set prefixes for child elements of wrapper
Node node = wrapper.getFirstChild();
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String lname = element.getNodeName();
if ("parameter-element".equals(lname) || "return-element".equals(lname)) {
String childns = element.getAttribute("ns");
if ("".equals(childns)) {
element.setAttribute("prefix", "");
} else if (ns.equals(childns)) {
element.setAttribute("prefix", prefix);
} else {
String childprefix = (String) nsMap.get(childns);
if (childprefix == null) {
throw new RuntimeException("Unable to set namespace " + childns + " for child element");
}
element.setAttribute("prefix", childprefix);
}
}
}
node = node.getNextSibling();
}
} else {
// check extra definition needed for wrapper namespace
if (!"".equals(ns)) {
// just make the wrapper namespace the default
prefix = "";
addns = true;
}
wrapper.setAttribute("prefix", prefix);
// set prefixes for child elements of wrapper
Node node = wrapper.getFirstChild();
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
String lname = element.getNodeName();
if ("parameter-element".equals(lname) || "return-element".equals(lname)) {
String childns = element.getAttribute("ns");
if ("".equals(childns)) {
element.setAttribute("prefix", "");
} else if (ns.equals(childns)) {
element.setAttribute("prefix", prefix);
} else {
throw new RuntimeException("Unable to set namespace " + childns + " for child element");
}
}
}
node = node.getNextSibling();
}
}
if (addns) {
Element addedns = doc.createElement("extra-namespace");
addedns.setAttribute("ns", ns);
addedns.setAttribute("prefix", prefix);
wrapper.appendChild(addedns);
}
}
// add type usage information for binding initialization
List details = new ArrayList();
Element bindinit = doc.createElement("initialize-binding");
if (!typeMappedClassMap.isEmpty()) {
for (Iterator iter = typeMappedClassMap.keySet().iterator(); iter.hasNext(); ) {
QName tname = (QName) iter.next();
String clsindex = ((Integer) typeMappedClassMap.get(tname)).toString();
Element detail = doc.createElement("abstract-type");
detail.setAttribute("ns", tname.getNamespaceURI());
detail.setAttribute("name", tname.getLocalPart());
detail.setAttribute("type-index", clsindex);
bindinit.appendChild(detail);
if (mappedclass == null) {
MappingElementBase mapping = (MappingElementBase) complexTypeMap.get(tname);
mappedclass = mapping.getClassName();
}
}
}
// set binding lookup parameters
if (binding != null && binding.getName() != null && binding.getTargetPackage() != null) {
bindinit.setAttribute("binding-name", binding.getName());
bindinit.setAttribute("binding-package", binding.getTargetPackage());
} else {
if (mappedclass == null) {
mappedclass = "";
}
bindinit.setAttribute("bound-class", mappedclass);
}
// include binding namespaces in initialization data
for (Iterator iter = nsMap.keySet().iterator(); iter.hasNext(); ) {
String ns = (String) iter.next();
String prefix = (String) nsMap.get(ns);
Element detail = doc.createElement("binding-namespace");
detail.setAttribute("ns", ns);
detail.setAttribute("prefix", prefix);
bindinit.appendChild(detail);
}
details.add(bindinit);
// add details for all objects used as inputs/outputs/faults
for (Iterator iter = objins.iterator(); iter.hasNext(); ) {
String classname = (String) iter.next();
Element detail = doc.createElement("object-input");
detail.setAttribute("type", classname);
details.add(detail);
}
for (Iterator iter = objouts.iterator(); iter.hasNext(); ) {
String classname = (String) iter.next();
Element detail = doc.createElement("object-output");
detail.setAttribute("type", classname);
details.add(detail);
}
for (Iterator iter = objfaults.iterator(); iter.hasNext(); ) {
String classname = (String) iter.next();
Element detail = doc.createElement("object-fault");
detail.setAttribute("type", classname);
details.add(detail);
}
codeGenConfig.getAxisService().addParameter(new Parameter(Constants.DATABINDING_SERVICE_DETAILS, details));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (JiBXException e) {
throw new RuntimeException(e);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (AxisFault e) {
throw new RuntimeException(e);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
use of org.apache.axis2.wsdl.SOAPHeaderMessage in project axis-axis2-java-core by apache.
the class AxisServiceBasedMultiLanguageEmitter method addHeaderOperationsToFault.
/**
* populate the header parameters to faults
*
* @param soapHeaderParameterQNameList
* @param axisOperation
*/
protected void addHeaderOperationsToFault(List soapHeaderParameterQNameList, AxisOperation axisOperation) {
ArrayList headerparamList = new ArrayList();
ArrayList faultMessages = axisOperation.getFaultMessages();
Iterator iter = faultMessages.iterator();
while (iter.hasNext()) {
AxisMessage axisFaultMessage = (AxisMessage) iter.next();
headerparamList.addAll((ArrayList) getBindingPropertyFromMessageFault(WSDL2Constants.ATTR_WSOAP_HEADER, axisOperation.getName(), axisFaultMessage.getName()));
}
if (headerparamList != null) {
for (Iterator iterator = headerparamList.iterator(); iterator.hasNext(); ) {
SOAPHeaderMessage header = (SOAPHeaderMessage) iterator.next();
soapHeaderParameterQNameList.add(header.getElement());
}
}
}
use of org.apache.axis2.wsdl.SOAPHeaderMessage in project axis-axis2-java-core by apache.
the class AxisServiceBasedMultiLanguageEmitter method addHeaderOperations.
/**
* populate the header parameters
*
* @param soapHeaderParameterQNameList
* @param bindingOperation
* @param input
*/
protected void addHeaderOperations(List soapHeaderParameterQNameList, AxisBindingOperation bindingOperation, boolean input) {
AxisOperation axisOperation = bindingOperation.getAxisOperation();
ArrayList headerparamList = new ArrayList();
String MEP = axisOperation.getMessageExchangePattern();
if (input) {
if (WSDLUtil.isInputPresentForMEP(MEP)) {
headerparamList = (ArrayList) getBindingPropertyFromMessage(WSDL2Constants.ATTR_WSOAP_HEADER, bindingOperation.getName(), WSDLConstants.MESSAGE_LABEL_IN_VALUE);
}
} else {
if (WSDLUtil.isOutputPresentForMEP(MEP)) {
headerparamList = (ArrayList) getBindingPropertyFromMessage(WSDL2Constants.ATTR_WSOAP_HEADER, bindingOperation.getName(), WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
}
}
if (headerparamList != null) {
for (Iterator iterator = headerparamList.iterator(); iterator.hasNext(); ) {
SOAPHeaderMessage header = (SOAPHeaderMessage) iterator.next();
soapHeaderParameterQNameList.add(header);
}
}
}
Aggregations