use of org.apache.cxf.binding.soap.model.SoapHeaderInfo in project camel by apache.
the class CxfProducer method checkParameterSize.
private void checkParameterSize(CxfEndpoint endpoint, Exchange exchange, Object[] parameters) {
BindingOperationInfo boi = getBindingOperationInfo(exchange);
if (boi == null) {
throw new RuntimeCamelException("Can't find the binding operation information from camel exchange");
}
if (!endpoint.isWrapped()) {
if (boi.isUnwrappedCapable()) {
boi = boi.getUnwrappedOperation();
}
}
int experctMessagePartsSize = boi.getInput().getMessageParts().size();
if (parameters.length < experctMessagePartsSize) {
throw new IllegalArgumentException("Get the wrong parameter size to invoke the out service, Expect size " + experctMessagePartsSize + ", Parameter size " + parameters.length + ". Please check if the message body matches the CXFEndpoint POJO Dataformat request.");
}
if (parameters.length > experctMessagePartsSize) {
// need to check the holder parameters
int holdersSize = 0;
for (Object parameter : parameters) {
if (parameter instanceof Holder) {
holdersSize++;
}
}
// need to check the soap header information
int soapHeadersSize = 0;
BindingMessageInfo bmi = boi.getInput();
if (bmi != null) {
List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
if (headers != null) {
soapHeadersSize = headers.size();
}
}
if (holdersSize + experctMessagePartsSize + soapHeadersSize < parameters.length) {
throw new IllegalArgumentException("Get the wrong parameter size to invoke the out service, Expect size " + (experctMessagePartsSize + holdersSize + soapHeadersSize) + ", Parameter size " + parameters.length + ". Please check if the message body matches the CXFEndpoint POJO Dataformat request.");
}
}
}
use of org.apache.cxf.binding.soap.model.SoapHeaderInfo in project cxf by apache.
the class SoapHeaderInterceptor method handleMessage.
public void handleMessage(Message m) throws Fault {
SoapMessage message = (SoapMessage) m;
SoapVersion soapVersion = message.getVersion();
Exchange exchange = message.getExchange();
MessageContentsList parameters = MessageContentsList.getContentsList(message);
if (null == parameters) {
parameters = new MessageContentsList();
}
BindingOperationInfo bop = exchange.getBindingOperationInfo();
if (null == bop) {
return;
}
if (bop.isUnwrapped()) {
bop = bop.getWrappedOperation();
}
boolean client = isRequestor(message);
BindingMessageInfo bmi = client ? bop.getOutput() : bop.getInput();
if (bmi == null) {
// one way operation.
return;
}
List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
if (headers == null || headers.isEmpty()) {
return;
}
boolean supportsNode = this.supportsDataReader(message, Node.class);
Service service = ServiceModelUtil.getService(message.getExchange());
for (SoapHeaderInfo header : headers) {
MessagePartInfo mpi = header.getPart();
try {
if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.IN, message)) {
Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0), message.getExchange().getBus());
validateHeader(message, mpi, schema);
}
} catch (Fault f) {
if (!isRequestor(message)) {
f.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw f;
}
if (mpi.getTypeClass() != null) {
Header param = findHeader(message, mpi);
Object object = null;
if (param != null) {
message.getHeaders().remove(param);
if (param.getDataBinding() == null) {
Node source = (Node) param.getObject();
if (source instanceof Element) {
// need to remove these attributes as they
// would cause validation failures
Element el = (Element) source;
el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameMustUnderstand());
el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameRole());
}
if (supportsNode) {
object = getNodeDataReader(message).read(mpi, source);
} else {
W3CDOMStreamReader reader = new W3CDOMStreamReader((Element) source);
try {
// advance into the first tag
reader.nextTag();
} catch (XMLStreamException e) {
// ignore
}
object = getDataReader(message, XMLStreamReader.class).read(mpi, reader);
}
} else {
object = param.getObject();
}
}
parameters.put(mpi, object);
}
}
if (!parameters.isEmpty()) {
message.setContent(List.class, parameters);
}
}
use of org.apache.cxf.binding.soap.model.SoapHeaderInfo 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.model.SoapHeaderInfo in project cxf by apache.
the class SoapOutInterceptor method handleHeaderPart.
private boolean handleHeaderPart(boolean preexistingHeaders, SoapMessage message, String soapPrefix) {
// add MessagePart to soapHeader if necessary
boolean endedHeader = false;
Exchange exchange = message.getExchange();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
if (bop == null) {
return endedHeader;
}
XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
boolean startedHeader = false;
BindingOperationInfo unwrappedOp = bop;
if (bop.isUnwrapped()) {
unwrappedOp = bop.getWrappedOperation();
}
boolean client = isRequestor(message);
BindingMessageInfo bmi = client ? unwrappedOp.getInput() : unwrappedOp.getOutput();
BindingMessageInfo wrappedBmi = client ? bop.getInput() : bop.getOutput();
if (bmi == null) {
return endedHeader;
}
if (wrappedBmi.getMessageInfo().getMessagePartsNumber() > 0) {
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs == null) {
return endedHeader;
}
SoapVersion soapVersion = message.getVersion();
List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
if (headers == null) {
return endedHeader;
}
for (SoapHeaderInfo header : headers) {
MessagePartInfo part = header.getPart();
if (wrappedBmi != bmi) {
part = wrappedBmi.getMessageInfo().addMessagePart(part.getName());
}
if (part.getIndex() >= objs.size()) {
// The optional out of band header is not a part of parameters of the method
continue;
}
Object arg = objs.get(part);
if (arg == null) {
continue;
}
objs.remove(part);
if (!(startedHeader || preexistingHeaders)) {
try {
xtw.writeStartElement(soapPrefix, soapVersion.getHeader().getLocalPart(), soapVersion.getNamespace());
} catch (XMLStreamException e) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
}
startedHeader = true;
}
DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message);
dataWriter.write(arg, header.getPart(), xtw);
}
if (startedHeader || preexistingHeaders) {
try {
xtw.writeEndElement();
endedHeader = true;
} catch (XMLStreamException e) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
}
}
}
return endedHeader;
}
use of org.apache.cxf.binding.soap.model.SoapHeaderInfo in project cxf by apache.
the class SoapBindingFactory method handleMimePart.
private List<MessagePartInfo> handleMimePart(MIMEPart mpart, List<MessagePartInfo> attParts, MessageInfo msg, BindingMessageInfo bmsg, List<MessagePartInfo> bodyParts, List<MessagePartInfo> messageParts) {
if (mpart.getExtensibilityElements().size() < 1) {
throw new RuntimeException("MIMEPart should at least contain one element!");
}
String partName = null;
for (Object content : mpart.getExtensibilityElements()) {
if (content instanceof MIMEContent) {
MIMEContent mc = (MIMEContent) content;
partName = mc.getPart();
if (attParts == null) {
attParts = new LinkedList<MessagePartInfo>();
}
if (StringUtils.isEmpty(partName)) {
throw new RuntimeException("Problem with WSDL: mime content element in operation " + bmsg.getBindingOperation().getName().getLocalPart() + " does not specify a part.");
}
MessagePartInfo mpi = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), partName));
mpi.setProperty(Message.CONTENT_TYPE, mc.getType());
attParts.add(mpi);
// Attachments shouldn't be part of the body message
bmsg.getMessageParts().remove(mpi);
} else if (SOAPBindingUtil.isSOAPBody(content)) {
SoapBody sb = SOAPBindingUtil.getSoapBody(content);
if (sb.getParts() != null && sb.getParts().size() == 1) {
partName = (String) sb.getParts().get(0);
}
// We can have a list of empty part names here.
if (partName != null) {
addSoapBodyPart(msg, bodyParts, partName);
}
} else if (SOAPBindingUtil.isSOAPHeader(content)) {
SoapHeader header = SOAPBindingUtil.getSoapHeader(content);
SoapHeaderInfo headerInfo = new SoapHeaderInfo();
headerInfo.setUse(header.getUse());
if (StringUtils.isEmpty(header.getPart())) {
throw new RuntimeException("Problem with WSDL: soap:header element in operation " + bmsg.getBindingOperation().getName().getLocalPart() + " does not specify a part.");
}
MessagePartInfo mpi = msg.getMessagePart(new QName(msg.getName().getNamespaceURI(), header.getPart()));
if (mpi != null && header.getMessage() != null && !mpi.getMessageInfo().getName().equals(header.getMessage())) {
mpi = null;
// out of band, let's find it
for (MessagePartInfo mpi2 : msg.getOutOfBandParts()) {
if (mpi2.getName().getLocalPart().equals(header.getPart()) && mpi2.getMessageInfo().getName().equals(header.getMessage())) {
mpi = mpi2;
}
}
}
if (mpi != null) {
headerInfo.setPart(mpi);
messageParts.remove(mpi);
bmsg.getMessageParts().remove(mpi);
bmsg.addExtensor(headerInfo);
}
}
}
return attParts;
}
Aggregations