use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault in project cxf by apache.
the class SoapBindingFactory method createSoapBinding.
private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException {
boolean isSoap12 = bi.getSoapVersion() instanceof Soap12;
Bus bs = getBus();
WSDLManager m = bs.getExtension(WSDLManager.class);
ExtensionRegistry extensionRegistry = m.getExtensionRegistry();
SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12);
soapBinding.setStyle(bi.getStyle());
soapBinding.setTransportURI(bi.getTransportURI());
bi.addExtensor(soapBinding);
for (BindingOperationInfo b : bi.getOperations()) {
for (BindingFaultInfo faultInfo : b.getFaults()) {
SoapFault soapFault = SOAPBindingUtil.createSoapFault(extensionRegistry, isSoap12);
soapFault.setUse("literal");
soapFault.setName(faultInfo.getFaultInfo().getFaultName().getLocalPart());
faultInfo.addExtensor(soapFault);
}
SoapOperationInfo soi = b.getExtensor(SoapOperationInfo.class);
SoapOperation soapOperation = SOAPBindingUtil.createSoapOperation(extensionRegistry, isSoap12);
soapOperation.setSoapActionURI(soi.getAction());
soapOperation.setStyle(soi.getStyle());
boolean isRpc = "rpc".equals(soapOperation.getStyle());
b.addExtensor(soapOperation);
if (b.getInput() != null) {
List<String> bodyParts = null;
List<SoapHeaderInfo> headerInfos = b.getInput().getExtensors(SoapHeaderInfo.class);
if (headerInfos != null && !headerInfos.isEmpty()) {
bodyParts = new ArrayList<>();
for (MessagePartInfo part : b.getInput().getMessageParts()) {
bodyParts.add(part.getName().getLocalPart());
}
for (SoapHeaderInfo headerInfo : headerInfos) {
SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingInput.class, isSoap12);
soapHeader.setMessage(b.getInput().getMessageInfo().getName());
soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
soapHeader.setUse("literal");
bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
headerInfo.getPart().setProperty(HEADER, true);
b.getInput().addExtensor(soapHeader);
}
}
SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingInput.class, isSoap12);
body.setUse("literal");
if (isRpc) {
body.setNamespaceURI(b.getName().getNamespaceURI());
}
if (bodyParts != null) {
body.setParts(bodyParts);
}
b.getInput().addExtensor(body);
}
if (b.getOutput() != null) {
List<String> bodyParts = null;
List<SoapHeaderInfo> headerInfos = b.getOutput().getExtensors(SoapHeaderInfo.class);
if (headerInfos != null && !headerInfos.isEmpty()) {
bodyParts = new ArrayList<>();
for (MessagePartInfo part : b.getOutput().getMessageParts()) {
bodyParts.add(part.getName().getLocalPart());
}
for (SoapHeaderInfo headerInfo : headerInfos) {
SoapHeader soapHeader = SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingOutput.class, isSoap12);
soapHeader.setMessage(b.getOutput().getMessageInfo().getName());
soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
soapHeader.setUse("literal");
bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
b.getOutput().addExtensor(soapHeader);
}
}
SoapBody body = SOAPBindingUtil.createSoapBody(extensionRegistry, BindingOutput.class, isSoap12);
body.setUse("literal");
if (isRpc) {
body.setNamespaceURI(b.getName().getNamespaceURI());
}
if (bodyParts != null) {
body.setParts(bodyParts);
}
b.getOutput().addExtensor(body);
}
}
}
use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault in project cxf by apache.
the class WSIBPValidator method checkR2717AndR2726.
private boolean checkR2717AndR2726(final BindingOperation bop) {
if (null == bop) {
return true;
}
SoapBody inSoapBody = SOAPBindingUtil.getBindingInputSOAPBody(bop);
SoapBody outSoapBody = SOAPBindingUtil.getBindingOutputSOAPBody(bop);
if (inSoapBody != null && StringUtils.isEmpty(inSoapBody.getNamespaceURI()) || outSoapBody != null && StringUtils.isEmpty(outSoapBody.getNamespaceURI())) {
addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2717") + "soapBody in the input/output of the binding operation '" + bop.getName() + "' MUST have namespace attribute");
return false;
}
SoapHeader inSoapHeader = SOAPBindingUtil.getBindingInputSOAPHeader(bop);
SoapHeader outSoapHeader = SOAPBindingUtil.getBindingOutputSOAPHeader(bop);
if (inSoapHeader != null && !StringUtils.isEmpty(inSoapHeader.getNamespaceURI()) || outSoapHeader != null && !StringUtils.isEmpty(outSoapHeader.getNamespaceURI())) {
addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2726") + "Operation '" + bop.getName() + "' soapHeader MUST NOT have namespace attribute");
return false;
}
List<SoapFault> soapFaults = SOAPBindingUtil.getBindingOperationSoapFaults(bop);
for (SoapFault fault : soapFaults) {
if (!StringUtils.isEmpty(fault.getNamespaceURI())) {
addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2726") + "Operation '" + bop.getName() + "' soapFault MUST NOT have namespace attribute");
return false;
}
}
return true;
}
use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault in project cxf by apache.
the class WSDLToSoapProcessor method setSoapFaultExtElement.
private void setSoapFaultExtElement(BindingFault bf) throws ToolException {
if (extReg == null) {
extReg = wsdlFactory.newPopulatedExtensionRegistry();
}
final SoapFault soapFault;
try {
soapFault = SOAPBindingUtil.createSoapFault(extReg, isSOAP12());
} catch (WSDLException wse) {
Message msg = new Message("FAIL_TO_CREATE_SOAPBINDING", LOG);
throw new ToolException(msg, wse);
}
soapFault.setName(bf.getName());
soapFault.setUse((String) env.get(ToolConstants.CFG_USE));
if (WSDLConstants.RPC.equalsIgnoreCase((String) env.get(ToolConstants.CFG_STYLE)) && env.optionSet(ToolConstants.CFG_NAMESPACE)) {
soapFault.setNamespaceURI((String) env.get(ToolConstants.CFG_NAMESPACE));
}
bf.addExtensibilityElement(soapFault);
}
use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault in project cxf by apache.
the class WSIBPValidator method checkR2716.
private boolean checkR2716(final BindingOperation bop) {
SoapBody inSoapBody = SOAPBindingUtil.getBindingInputSOAPBody(bop);
SoapBody outSoapBody = SOAPBindingUtil.getBindingOutputSOAPBody(bop);
if (inSoapBody != null && !StringUtils.isEmpty(inSoapBody.getNamespaceURI()) || outSoapBody != null && !StringUtils.isEmpty(outSoapBody.getNamespaceURI())) {
addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2716") + "Operation '" + bop.getName() + "' soapBody MUST NOT have namespace attribute");
return false;
}
SoapHeader inSoapHeader = SOAPBindingUtil.getBindingInputSOAPHeader(bop);
SoapHeader outSoapHeader = SOAPBindingUtil.getBindingOutputSOAPHeader(bop);
if (inSoapHeader != null && !StringUtils.isEmpty(inSoapHeader.getNamespaceURI()) || outSoapHeader != null && !StringUtils.isEmpty(outSoapHeader.getNamespaceURI())) {
addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2716") + "Operation '" + bop.getName() + "' soapHeader MUST NOT have namespace attribute");
return false;
}
List<SoapFault> soapFaults = SOAPBindingUtil.getBindingOperationSoapFaults(bop);
for (SoapFault fault : soapFaults) {
if (!StringUtils.isEmpty(fault.getNamespaceURI())) {
addErrorMessage(getErrorPrefix("WSI-BP-1.0 R2716") + "Operation '" + bop.getName() + "' soapFault MUST NOT have namespace attribute");
return false;
}
}
return true;
}
use of org.apache.cxf.binding.soap.wsdl.extensions.SoapFault in project cxf by apache.
the class WSDLToSoapProcessorTest method testDocLitWithFault.
@Test
public void testDocLitWithFault() throws Exception {
String[] args = new String[] { "-i", "Greeter", "-d", output.getCanonicalPath(), getLocation("/misctools_wsdl/hello_world_doc_lit.wsdl") };
WSDLToSoap.main(args);
File outputFile = new File(output, "hello_world_doc_lit-soapbinding.wsdl");
assertTrue("New wsdl file is not generated", outputFile.exists());
WSDLToSoapProcessor processor = new WSDLToSoapProcessor();
processor.setEnvironment(env);
try {
processor.parseWSDL(outputFile.getAbsolutePath());
Binding binding = processor.getWSDLDefinition().getBinding(new QName(processor.getWSDLDefinition().getTargetNamespace(), "Greeter_Binding"));
if (binding == null) {
fail("Element wsdl:binding Greeter_Binding Missed!");
}
boolean found = false;
for (Object obj : binding.getExtensibilityElements()) {
SoapBinding soapBinding = SOAPBindingUtil.getSoapBinding(obj);
if (soapBinding != null && soapBinding.getStyle().equalsIgnoreCase("document")) {
found = true;
break;
}
}
if (!found) {
fail("Element soap:binding Missed!");
}
BindingOperation bo = binding.getBindingOperation("pingMe", null, null);
if (bo == null) {
fail("Element <wsdl:operation name=\"pingMe\"> Missed!");
}
found = false;
for (Object obj : bo.getExtensibilityElements()) {
SoapOperation soapOperation = SOAPBindingUtil.getSoapOperation(obj);
if (soapOperation != null && soapOperation.getStyle().equalsIgnoreCase("document")) {
found = true;
break;
}
}
if (!found) {
fail("Element soap:operation Missed!");
}
BindingFault fault = bo.getBindingFault("pingMeFault");
if (fault == null) {
fail("Element <wsdl:fault name=\"pingMeFault\"> Missed!");
}
found = false;
for (Object obj : fault.getExtensibilityElements()) {
if (SOAPBindingUtil.isSOAPFault(obj)) {
found = true;
break;
}
}
if (!found) {
fail("Element soap:fault Missed!");
}
List<SoapFault> faults = SOAPBindingUtil.getBindingOperationSoapFaults(bo);
assertEquals(1, faults.size());
assertEquals("pingMeFault", faults.get(0).getName());
} catch (ToolException e) {
fail("Exception Encountered when parsing wsdl, error: " + e.getMessage());
}
}
Aggregations