use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class StaxDataBindingInterceptor method handleMessage.
public void handleMessage(Message message) {
if (isGET(message) && message.getContent(List.class) != null) {
LOG.fine("StaxDataBindingInterceptor skipped in HTTP GET method");
return;
}
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
DataReader<XMLStreamReader> dr = getDataReader(message);
MessageContentsList parameters = new MessageContentsList();
Exchange exchange = message.getExchange();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
// operation anymore, just return
if (!StaxUtils.toNextElement(xmlReader) && bop != null) {
// body may be empty for partial response to decoupled request
return;
}
if (bop == null) {
Endpoint ep = exchange.getEndpoint();
bop = ep.getBinding().getBindingInfo().getOperations().iterator().next();
}
message.getExchange().put(BindingOperationInfo.class, bop);
if (isRequestor(message)) {
parameters.put(bop.getOutput().getMessageParts().get(0), dr.read(xmlReader));
} else {
parameters.put(bop.getInput().getMessageParts().get(0), dr.read(xmlReader));
}
if (!parameters.isEmpty()) {
message.setContent(List.class, parameters);
}
}
use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class ClientImpl method setParameters.
protected void setParameters(Object[] params, Message message) {
MessageContentsList contents = new MessageContentsList(params);
message.setContent(List.class, contents);
}
use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class AbstractInvoker method invoke.
public Object invoke(Exchange exchange, Object o) {
final Object serviceObject = getServiceObject(exchange);
try {
BindingOperationInfo bop = exchange.getBindingOperationInfo();
MethodDispatcher md = (MethodDispatcher) exchange.getService().get(MethodDispatcher.class.getName());
Method m = bop == null ? null : md.getMethod(bop);
if (m == null && bop == null) {
LOG.severe(new Message("MISSING_BINDING_OPERATION", LOG).toString());
throw new Fault(new Message("EXCEPTION_INVOKING_OBJECT", LOG, "No binding operation info", "unknown method", "unknown"));
}
List<Object> params = null;
if (o instanceof List) {
params = CastUtils.cast((List<?>) o);
} else if (o != null) {
params = new MessageContentsList(o);
}
m = adjustMethodAndParams(m, exchange, params, serviceObject.getClass());
// Method m = (Method)bop.getOperationInfo().getProperty(Method.class.getName());
m = matchMethod(m, serviceObject);
return invoke(exchange, serviceObject, m, params);
} finally {
releaseServiceObject(exchange, serviceObject);
}
}
use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class RPCInInterceptor method handleMessage.
public void handleMessage(Message message) {
if (isGET(message)) {
LOG.fine("RPCInInterceptor skipped in HTTP GET method");
return;
}
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
BindingOperationInfo operation = null;
if (!StaxUtils.toNextElement(xmlReader)) {
message.setContent(Exception.class, new RuntimeException("There must be a method name element."));
}
String opName = xmlReader.getLocalName();
if (isRequestor(message) && opName.endsWith("Response")) {
opName = opName.substring(0, opName.length() - 8);
}
if (message.getExchange().getBindingOperationInfo() == null) {
operation = getOperation(message, new QName(xmlReader.getNamespaceURI(), opName));
if (operation == null) {
// it's doc-lit-bare
new BareInInterceptor().handleMessage(message);
return;
}
setMessage(message, operation);
} else {
operation = message.getExchange().getBindingOperationInfo();
}
MessageInfo msg;
DataReader<XMLStreamReader> dr = getDataReader(message, XMLStreamReader.class);
if (!isRequestor(message)) {
msg = operation.getOperationInfo().getInput();
} else {
msg = operation.getOperationInfo().getOutput();
}
message.put(MessageInfo.class, msg);
MessageContentsList parameters = new MessageContentsList();
StaxUtils.nextEvent(xmlReader);
boolean hasNext = true;
Iterator<MessagePartInfo> itr = msg.getMessageParts().iterator();
while (itr.hasNext()) {
MessagePartInfo part = itr.next();
if (hasNext) {
hasNext = StaxUtils.toNextElement(xmlReader);
}
if (hasNext) {
QName qn = xmlReader.getName();
if (qn.equals(SOAP12_RESULT)) {
// just ignore this. The parts should work correctly.
try {
while (xmlReader.getEventType() != XMLStreamConstants.END_ELEMENT) {
xmlReader.next();
}
xmlReader.next();
} catch (XMLStreamException e) {
// ignore
}
StaxUtils.toNextElement(xmlReader);
qn = xmlReader.getName();
}
// WSI-BP states that RPC/Lit part accessors should be completely unqualified
// However, older toolkits (Axis 1.x) are qualifying them. We'll go
// ahead and just match on the localpart. The RPCOutInterceptor
// will always generate WSI-BP compliant messages so it's unknown if
// the non-WSI-BP toolkits will be able to understand the CXF
// generated messages if they are expecting it to be qualified.
Iterator<MessagePartInfo> partItr = msg.getMessageParts().iterator();
while (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart()) && partItr.hasNext()) {
part = partItr.next();
}
// only check the localpart as explained above
if (!qn.getLocalPart().equals(part.getConcreteName().getLocalPart())) {
throw new Fault(new org.apache.cxf.common.i18n.Message("UNKNOWN_RPC_LIT_PART", LOG, qn));
}
try {
parameters.put(part, dr.read(part, xmlReader));
} catch (Fault f) {
if (!isRequestor(message)) {
f.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw f;
}
}
}
message.setContent(List.class, parameters);
}
use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class RPCOutInterceptor method handleMessage.
public void handleMessage(Message message) {
XMLStreamWriter origXmlWriter = null;
try {
NSStack nsStack = new NSStack();
nsStack.push();
BindingOperationInfo operation = message.getExchange().getBindingOperationInfo();
assert operation.getName() != null;
XMLStreamWriter xmlWriter = getXMLStreamWriter(message);
CachingXmlEventWriter cache = null;
// need to cache the events in case validation fails or buffering is enabled
if (shouldBuffer(message)) {
origXmlWriter = xmlWriter;
cache = new CachingXmlEventWriter();
try {
cache.setNamespaceContext(xmlWriter.getNamespaceContext());
} catch (XMLStreamException e) {
// ignorable, will just get extra namespace decls
}
message.setContent(XMLStreamWriter.class, cache);
xmlWriter = cache;
}
List<MessagePartInfo> parts = null;
boolean output = false;
if (!isRequestor(message)) {
if (operation.getOutput() == null) {
return;
}
parts = operation.getOutput().getMessageParts();
output = true;
} else {
parts = operation.getInput().getMessageParts();
output = false;
}
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs == null) {
addOperationNode(nsStack, message, xmlWriter, output, operation);
xmlWriter.writeEndElement();
return;
}
for (MessagePartInfo part : parts) {
if (objs.hasValue(part)) {
Object o = objs.get(part);
if (o == null) {
// WSI-BP R2211 - RPC/Lit parts are not allowed to be xsi:nil
throw new Fault(new org.apache.cxf.common.i18n.Message("BP_2211_RPCLIT_CANNOT_BE_NULL", LOG, part.getConcreteName()));
}
// WSI-BP R2737 -RPC/LIG part name space is empty
// part.setConcreteName(new QName("", part.getConcreteName().getLocalPart()));
}
}
addOperationNode(nsStack, message, xmlWriter, output, operation);
writeParts(message, message.getExchange(), operation, objs, parts);
// Finishing the writing.
xmlWriter.writeEndElement();
if (cache != null) {
try {
for (XMLEvent event : cache.getEvents()) {
StaxUtils.writeEvent(event, origXmlWriter);
}
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
} catch (XMLStreamException e) {
throw new Fault(e);
} finally {
if (origXmlWriter != null) {
message.setContent(XMLStreamWriter.class, origXmlWriter);
}
}
}
Aggregations