use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.
the class FaultOutInterceptor method getFaultForClass.
/**
* Find the correct Fault part for a particular exception.
*
* @param op
* @param class1
*/
public FaultInfo getFaultForClass(BindingOperationInfo op, Class<?> class1) {
FaultInfo selectedFaultInfo = null;
Class<?> selectedFaultInfoClass = null;
for (BindingFaultInfo bfi : op.getFaults()) {
FaultInfo faultInfo = bfi.getFaultInfo();
Class<?> c = (Class<?>) faultInfo.getProperty(Class.class.getName());
if (c != null && c.isAssignableFrom(class1) && (selectedFaultInfo == null || (selectedFaultInfoClass != null && selectedFaultInfoClass.isAssignableFrom(c)))) {
selectedFaultInfo = faultInfo;
selectedFaultInfoClass = c;
}
}
return selectedFaultInfo;
}
use of org.apache.cxf.service.model.BindingFaultInfo 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.service.model.BindingFaultInfo in project cxf by apache.
the class WSDLServiceBuilder method buildBinding.
public BindingInfo buildBinding(ServiceInfo service, Binding binding) {
BindingInfo bi = null;
StringBuilder ns = new StringBuilder(100);
BindingFactory factory = WSDLServiceUtils.getBindingFactory(binding, bus, ns);
if (factory instanceof WSDLBindingFactory) {
WSDLBindingFactory wFactory = (WSDLBindingFactory) factory;
bi = wFactory.createBindingInfo(service, binding, ns.toString());
copyExtensors(bi, binding.getExtensibilityElements());
copyExtensionAttributes(bi, binding);
}
if (bi == null) {
boolean onlyExtensors = false;
if (factory instanceof AbstractBindingFactory) {
bi = ((AbstractBindingFactory) factory).createBindingInfo(service, ns.toString(), null);
onlyExtensors = true;
} else {
bi = new BindingInfo(service, ns.toString());
}
bi.setName(binding.getQName());
copyExtensors(bi, binding.getExtensibilityElements());
copyExtensionAttributes(bi, binding);
for (BindingOperation bop : cast(binding.getBindingOperations(), BindingOperation.class)) {
if (LOG.isLoggable(Level.FINER)) {
LOG.finer("binding operation name is " + bop.getName());
}
String inName = null;
String outName = null;
if (bop.getBindingInput() != null) {
inName = bop.getBindingInput().getName();
}
if (bop.getBindingOutput() != null) {
outName = bop.getBindingOutput().getName();
}
final BindingOperationInfo bop2;
if (onlyExtensors) {
bop2 = bi.getOperation(new QName(binding.getQName().getNamespaceURI(), bop.getName()));
} else {
bop2 = bi.buildOperation(new QName(binding.getQName().getNamespaceURI(), bop.getName()), inName, outName);
if (bop2 != null) {
bi.addOperation(bop2);
}
}
if (bop2 != null) {
copyExtensors(bop2, bop.getExtensibilityElements());
copyExtensionAttributes(bop2, bop);
if (bop.getBindingInput() != null) {
copyExtensors(bop2.getInput(), bop.getBindingInput().getExtensibilityElements());
copyExtensionAttributes(bop2.getInput(), bop.getBindingInput());
handleHeader(bop2.getInput());
}
if (bop.getBindingOutput() != null) {
copyExtensors(bop2.getOutput(), bop.getBindingOutput().getExtensibilityElements());
copyExtensionAttributes(bop2.getOutput(), bop.getBindingOutput());
handleHeader(bop2.getOutput());
}
for (BindingFault f : cast(bop.getBindingFaults().values(), BindingFault.class)) {
BindingFaultInfo bif = bop2.getFault(new QName(service.getTargetNamespace(), f.getName()));
copyExtensors(bif, bop.getBindingFault(f.getName()).getExtensibilityElements());
copyExtensionAttributes(bif, bop.getBindingFault(f.getName()));
}
}
}
}
service.addBinding(bi);
DescriptionInfo d = service.getDescription();
if (null != d) {
d.getDescribed().add(bi);
}
return bi;
}
use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.
the class ServiceWSDLBuilder method buildBindingFault.
protected void buildBindingFault(Definition def, BindingOperation bindingOperation, Collection<BindingFaultInfo> bindingFaultInfos) {
for (BindingFaultInfo bindingFaultInfo : bindingFaultInfos) {
final BindingFault bindingFault = def.createBindingFault();
addDocumentation(bindingFault, bindingFaultInfo.getDocumentation());
bindingFault.setName(bindingFaultInfo.getFaultInfo().getFaultName().getLocalPart());
bindingOperation.addBindingFault(bindingFault);
addExtensibilityAttributes(def, bindingFault, bindingFaultInfo.getExtensionAttributes());
addExtensibilityElements(def, bindingFault, getWSDL11Extensors(bindingFaultInfo));
}
}
use of org.apache.cxf.service.model.BindingFaultInfo in project cxf by apache.
the class WSDLServiceBuilderTest method assertBindingOperationMessageExtensions.
private void assertBindingOperationMessageExtensions(BindingOperationInfo boi, boolean expectExtensions, boolean hasOutput, QName fault) {
BindingMessageInfo bmi = boi.getInput();
if (expectExtensions) {
// REVISIT: bug in wsdl4j?
// getExtensionAttributes on binding/operation/input element returns an empty map
// assertEquals(1, bmi.getExtensionAttributes().size());
// assertNotNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
assertEquals(1, bmi.getExtensors(UnknownExtensibilityElement.class).size());
assertEquals(EXTENSION_ELEM, bmi.getExtensor(UnknownExtensibilityElement.class).getElementType());
} else {
assertNull(bmi.getExtensionAttributes());
assertNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
assertEquals(0, bmi.getExtensors(UnknownExtensibilityElement.class).size());
assertNull(bmi.getExtensor(UnknownExtensibilityElement.class));
}
if (hasOutput) {
bmi = boi.getOutput();
if (expectExtensions) {
// REVISIT: bug in wsdl4j?
// getExtensionAttributes on binding/operation/output element returns an empty map
// assertEquals(1, bmi.getExtensionAttributes().size());
// assertNotNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
assertEquals(1, bmi.getExtensors(UnknownExtensibilityElement.class).size());
assertEquals(EXTENSION_ELEM, bmi.getExtensor(UnknownExtensibilityElement.class).getElementType());
} else {
assertNull(bmi.getExtensionAttributes());
assertNull(bmi.getExtensionAttribute(EXTENSION_ATTR_STRING));
assertEquals(0, bmi.getExtensors(UnknownExtensibilityElement.class).size());
assertNull(bmi.getExtensor(UnknownExtensibilityElement.class));
}
}
if (null != fault) {
BindingFaultInfo bfi = boi.getFault(fault);
if (expectExtensions) {
assertEquals(1, bfi.getExtensionAttributes().size());
assertNotNull(bfi.getExtensionAttribute(EXTENSION_ATTR_STRING));
assertEquals(1, bfi.getExtensors(UnknownExtensibilityElement.class).size());
assertEquals(EXTENSION_ELEM, bfi.getExtensor(UnknownExtensibilityElement.class).getElementType());
} else {
assertNull(bfi.getExtensionAttributes());
assertNull(bfi.getExtensionAttribute(EXTENSION_ATTR_STRING));
assertNull(bfi.getExtensors(UnknownExtensibilityElement.class));
assertNull(bfi.getExtensor(UnknownExtensibilityElement.class));
}
}
}
Aggregations