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<>();
}
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;
}
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;
}
Aggregations