use of org.apache.cxf.service.model.MessagePartInfo in project camel by apache.
the class DefaultCxfBinding method getPayloadBodyElements.
protected static List<Source> getPayloadBodyElements(Message message, Map<String, String> nsMap) {
// take the namespace attribute from soap envelop
Map<String, String> bodyNC = CastUtils.cast((Map<?, ?>) message.get("soap.body.ns.context"));
if (bodyNC != null) {
// if there is no Node and the addNamespaceContext option is enabled, this map is available
nsMap.putAll(bodyNC);
} else {
Document soapEnv = (Document) message.getContent(Node.class);
if (soapEnv != null) {
NamedNodeMap attrs = soapEnv.getFirstChild().getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
Node node = attrs.item(i);
if (!node.getNodeValue().equals(Soap11.SOAP_NAMESPACE) && !node.getNodeValue().equals(Soap12.SOAP_NAMESPACE)) {
nsMap.put(node.getLocalName(), node.getNodeValue());
}
}
}
}
MessageContentsList inObjects = MessageContentsList.getContentsList(message);
if (inObjects == null) {
return new ArrayList<Source>(0);
}
org.apache.cxf.message.Exchange exchange = message.getExchange();
BindingOperationInfo boi = exchange.getBindingOperationInfo();
OperationInfo op = boi.getOperationInfo();
if (boi.isUnwrapped()) {
op = boi.getWrappedOperation().getOperationInfo();
}
List<MessagePartInfo> partInfos = null;
boolean client = Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE));
if (client) {
// it is a response
partInfos = op.getOutput().getMessageParts();
} else {
// it is a request
partInfos = op.getInput().getMessageParts();
}
List<Source> answer = new ArrayList<Source>();
for (MessagePartInfo partInfo : partInfos) {
if (!inObjects.hasValue(partInfo)) {
continue;
}
Object part = inObjects.get(partInfo);
if (part instanceof Holder) {
part = ((Holder<?>) part).value;
}
if (part instanceof Source) {
Element element = null;
if (part instanceof DOMSource) {
element = getFirstElement(((DOMSource) part).getNode());
}
if (element != null) {
addNamespace(element, nsMap);
answer.add(new DOMSource(element));
} else {
answer.add((Source) part);
}
if (LOG.isTraceEnabled()) {
LOG.trace("Extract body element {}", element == null ? "null" : getXMLString(element));
}
} else if (part instanceof Element) {
addNamespace((Element) part, nsMap);
answer.add(new DOMSource((Element) part));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Unhandled part type '{}'", part.getClass());
}
}
}
return answer;
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class StaxDataBinding method initialize.
public void initialize(Service service) {
for (ServiceInfo serviceInfo : service.getServiceInfos()) {
SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();
if (schemaCollection.getXmlSchemas().length > 1) {
// Schemas are already populated.
continue;
}
new ServiceModelVisitor(serviceInfo) {
public void begin(MessagePartInfo part) {
if (part.getTypeQName() != null || part.getElementQName() != null) {
return;
}
part.setTypeQName(Constants.XSD_ANYTYPE);
}
}.walk();
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class AbstractInDatabindingInterceptor method findMessagePart.
/**
* Find the next possible message part in the message. If an operation in
* the list of operations is no longer a viable match, it will be removed
* from the Collection.
*
* @param exchange
* @param operations
* @param name
* @param client
* @param index
*/
protected MessagePartInfo findMessagePart(Exchange exchange, Collection<OperationInfo> operations, QName name, boolean client, int index, Message message) {
Endpoint ep = exchange.getEndpoint();
MessagePartInfo lastChoice = null;
BindingOperationInfo lastBoi = null;
BindingMessageInfo lastMsgInfo = null;
BindingMessageInfo msgInfo = null;
BindingOperationInfo boi = null;
for (Iterator<OperationInfo> itr = operations.iterator(); itr.hasNext(); ) {
OperationInfo op = itr.next();
boi = ep.getEndpointInfo().getBinding().getOperation(op);
if (boi == null) {
continue;
}
if (client) {
msgInfo = boi.getOutput();
} else {
msgInfo = boi.getInput();
}
if (msgInfo == null) {
itr.remove();
continue;
}
Collection<MessagePartInfo> bodyParts = msgInfo.getMessageParts();
if (bodyParts.isEmpty() || bodyParts.size() <= index) {
itr.remove();
continue;
}
MessagePartInfo p = msgInfo.getMessageParts().get(index);
if (name.getNamespaceURI() == null || name.getNamespaceURI().length() == 0) {
// message part has same namespace with the message
name = new QName(p.getMessageInfo().getName().getNamespaceURI(), name.getLocalPart());
}
if (name.equals(p.getConcreteName())) {
exchange.put(BindingOperationInfo.class, boi);
exchange.setOneWay(op.isOneWay());
return p;
}
if (Constants.XSD_ANYTYPE.equals(p.getTypeQName())) {
lastChoice = p;
lastBoi = boi;
lastMsgInfo = msgInfo;
} else {
itr.remove();
}
}
if (lastChoice != null) {
setMessage(message, lastBoi, client, lastBoi.getBinding().getService(), lastMsgInfo.getMessageInfo());
}
return lastChoice;
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class AbstractOutDatabindingInterceptor method writeParts.
protected void writeParts(Message message, Exchange exchange, BindingOperationInfo operation, MessageContentsList objs, List<MessagePartInfo> parts) {
OutputStream out = message.getContent(OutputStream.class);
XMLStreamWriter origXmlWriter = message.getContent(XMLStreamWriter.class);
Service service = exchange.getService();
XMLStreamWriter xmlWriter = origXmlWriter;
CachingXmlEventWriter cache = null;
// configure endpoint and operation level schema validation
setOperationSchemaValidation(message);
// need to cache the events in case validation fails or buffering is enabled
if (shouldBuffer(message)) {
if (!(xmlWriter instanceof CachingXmlEventWriter)) {
cache = new CachingXmlEventWriter();
try {
cache.setNamespaceContext(origXmlWriter.getNamespaceContext());
} catch (XMLStreamException e) {
// ignorable, will just get extra namespace decls
}
xmlWriter = cache;
}
out = null;
}
if (out != null && writeToOutputStream(message, operation.getBinding(), service) && !MessageUtils.getContextualBoolean(message, DISABLE_OUTPUTSTREAM_OPTIMIZATION, false)) {
if (xmlWriter != null) {
try {
xmlWriter.writeCharacters("");
xmlWriter.flush();
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
DataWriter<OutputStream> osWriter = getDataWriter(message, service, OutputStream.class);
for (MessagePartInfo part : parts) {
if (objs.hasValue(part)) {
Object o = objs.get(part);
osWriter.write(o, part, out);
}
}
} else {
DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message, service, XMLStreamWriter.class);
for (MessagePartInfo part : parts) {
if (objs.hasValue(part)) {
NamespaceContext c = null;
if (!part.isElement() && xmlWriter instanceof CachingXmlEventWriter) {
try {
c = xmlWriter.getNamespaceContext();
xmlWriter.setNamespaceContext(new CachingXmlEventWriter.NSContext(null));
} catch (XMLStreamException e) {
// ignore
}
}
Object o = objs.get(part);
dataWriter.write(o, part, xmlWriter);
if (c != null) {
try {
xmlWriter.setNamespaceContext(c);
} catch (XMLStreamException e) {
// ignore
}
}
}
}
}
if (cache != null) {
try {
for (XMLEvent event : cache.getEvents()) {
StaxUtils.writeEvent(event, origXmlWriter);
}
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
}
use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.
the class ServiceModelVisitor method visitOperation.
private void visitOperation(OperationInfo o) {
MessageInfo in = o.getInput();
if (in != null) {
begin(in);
for (MessagePartInfo part : in.getMessageParts()) {
begin(part);
end(part);
}
end(in);
}
MessageInfo out = o.getOutput();
if (out != null) {
begin(out);
for (MessagePartInfo part : out.getMessageParts()) {
begin(part);
end(part);
}
end(out);
}
for (FaultInfo f : o.getFaults()) {
begin(f);
for (MessagePartInfo part : f.getMessageParts()) {
begin(part);
end(part);
}
end(f);
}
if (o.isUnwrappedCapable()) {
OperationInfo uop = o.getUnwrappedOperation();
begin(uop);
visitOperation(o.getUnwrappedOperation());
end(uop);
}
}
Aggregations