use of javax.wsdl.extensions.soap12.SOAP12Fault in project eclipselink by eclipse-ee4j.
the class WSDLGenerator method createMethodDefinition.
private void createMethodDefinition(WSDLFactory factory, ExtensionRegistry registry, Definition def, Operation operation, boolean useSOAP12) throws WSDLException {
Message requestMessage = def.createMessage();
requestMessage.setUndefined(false);
requestMessage.setQName(new QName(serviceNameSpace, operation.getName() + REQUEST_SUFFIX));
Part requestPart = def.createPart();
requestPart.setName(operation.getName() + REQUEST_SUFFIX);
requestPart.setElementName(new QName(serviceNameSpace, operation.getName()));
requestMessage.addPart(requestPart);
def.addMessage(requestMessage);
Message responseMessage = null;
if (operation.hasResponse()) {
responseMessage = def.createMessage();
responseMessage.setUndefined(false);
responseMessage.setQName(new QName(serviceNameSpace, operation.getName() + RESPONSE_SUFFIX));
Part responsePart = def.createPart();
responsePart.setName(operation.getName() + RESPONSE_SUFFIX);
responsePart.setElementName(new QName(serviceNameSpace, operation.getName() + RESPONSE_SUFFIX));
responseMessage.addPart(responsePart);
def.addMessage(responseMessage);
}
PortType portType = def.getPortType(new QName(serviceNameSpace, serviceName + PORT_SUFFIX));
javax.wsdl.Operation op = def.createOperation();
op.setUndefined(false);
op.setName(operation.getName());
Input input = def.createInput();
input.setMessage(requestMessage);
op.setInput(input);
if (operation.hasResponse()) {
Output output = def.createOutput();
output.setMessage(responseMessage);
op.setOutput(output);
}
portType.addOperation(op);
Binding binding = def.getBinding(new QName(serviceNameSpace, serviceName + BINDING_SUFFIX));
BindingOperation bop = def.createBindingOperation();
bop.setName(operation.getName());
ExtensibilityElement so = null;
if (useSOAP12) {
so = registry.createExtension(BindingOperation.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_OPERATION));
((SOAP12Operation) so).setSoapActionURI(serviceNameSpace + ":" + op.getName());
} else {
so = registry.createExtension(BindingOperation.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_OPERATION));
((SOAPOperation) so).setSoapActionURI(serviceNameSpace + ":" + op.getName());
}
bop.addExtensibilityElement(so);
BindingInput bi = def.createBindingInput();
ExtensibilityElement soapInputBody = null;
if (useSOAP12) {
soapInputBody = registry.createExtension(BindingInput.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_BODY));
((SOAP12Body) soapInputBody).setUse(SOAP_USE);
} else {
soapInputBody = registry.createExtension(BindingInput.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_BODY));
((SOAPBody) soapInputBody).setUse(SOAP_USE);
}
bi.addExtensibilityElement(soapInputBody);
bop.setBindingInput(bi);
if (operation.hasResponse()) {
BindingOutput bo = def.createBindingOutput();
ExtensibilityElement soapOutputBody = null;
if (useSOAP12) {
soapOutputBody = registry.createExtension(BindingOutput.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_BODY));
((SOAP12Body) soapOutputBody).setUse(SOAP_USE);
} else {
soapOutputBody = registry.createExtension(BindingOutput.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_BODY));
((SOAPBody) soapOutputBody).setUse(SOAP_USE);
}
bo.addExtensibilityElement(soapOutputBody);
bop.setBindingOutput(bo);
}
if (!(operation instanceof QueryOperation)) {
// non-QueryOperations don't have Responses, but the fault requirements
// mean we have to create 'dummy' WSDL outputs
BindingOutput bo = def.createBindingOutput();
ExtensibilityElement soapOutputBody = null;
if (useSOAP12) {
soapOutputBody = registry.createExtension(BindingOutput.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_BODY));
((SOAP12Body) soapOutputBody).setUse(SOAP_USE);
} else {
soapOutputBody = registry.createExtension(BindingOutput.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_BODY));
((SOAPBody) soapOutputBody).setUse(SOAP_USE);
}
bo.addExtensibilityElement(soapOutputBody);
bop.setBindingOutput(bo);
// add WSDL fault to binding operations
BindingFault bindingFault = def.createBindingFault();
String exceptionName = FAULT_SUFFIX + EXCEPTION_SUFFIX;
bindingFault.setName(exceptionName);
ExtensibilityElement soapFaultBody = null;
if (useSOAP12) {
soapFaultBody = registry.createExtension(BindingFault.class, new QName(SOAP_12_NAMESPACE_URI, TAG_SOAP_FAULT));
((SOAP12Fault) soapFaultBody).setUse(SOAP_USE);
((SOAP12Fault) soapFaultBody).setName(exceptionName);
} else {
soapFaultBody = registry.createExtension(BindingFault.class, new QName(SOAP_11_NAMESPACE_URI, TAG_SOAP_FAULT));
((SOAPFault) soapFaultBody).setUse(SOAP_USE);
((SOAPFault) soapFaultBody).setName(exceptionName);
}
bindingFault.addExtensibilityElement(soapFaultBody);
bop.addBindingFault(bindingFault);
Message emptyResponseMessage = def.getMessage(new QName(serviceNameSpace, EMPTY_RESPONSE));
Output output = def.createOutput();
output.setName(operation.getName() + EMPTY_RESPONSE);
output.setMessage(emptyResponseMessage);
op.setOutput(output);
Message faultMessage = def.getMessage(new QName(serviceNameSpace, FAULT_SUFFIX + TYPE_SUFFIX));
Fault fault = def.createFault();
fault.setMessage(faultMessage);
fault.setName(exceptionName);
op.addFault(fault);
}
binding.addBindingOperation(bop);
}
Aggregations