use of org.apache.cxf.service.model.OperationInfo 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.OperationInfo in project cxf by apache.
the class OperationInfoAuthorizingInterceptorTest method setUp.
@Before
@Override
public void setUp() throws Exception {
Exchange ex = setUpExchange();
Service service = EasyMock.createMock(Service.class);
ex.put(Service.class, service);
MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class);
EasyMock.expect(service.get(MethodDispatcher.class.getName())).andReturn(md).anyTimes();
BindingOperationInfo boi = EasyMock.createMock(BindingOperationInfo.class);
ex.put(BindingOperationInfo.class, boi);
EasyMock.expect(md.getMethod(boi)).andReturn(null);
OperationInfo opinfo = EasyMock.createMock(OperationInfo.class);
EasyMock.expect(opinfo.getName()).andReturn(new QName("urn:test", "echo")).anyTimes();
EasyMock.expect(boi.getOperationInfo()).andReturn(opinfo).anyTimes();
EasyMock.replay(service, md, boi, opinfo);
}
use of org.apache.cxf.service.model.OperationInfo in project cxf by apache.
the class ServiceUtils method getSchemaValidationTypeFromModel.
private static SchemaValidationType getSchemaValidationTypeFromModel(Message message) {
Exchange exchange = message.getExchange();
if (exchange != null) {
BindingOperationInfo boi = exchange.getBindingOperationInfo();
Endpoint endpoint = exchange.getEndpoint();
if (boi != null && endpoint != null) {
SchemaValidationType validationType = null;
OperationInfo opInfo = boi.getOperationInfo();
EndpointInfo ep = endpoint.getEndpointInfo();
if (opInfo != null) {
validationType = getSchemaValidationTypeFromModel(opInfo);
if (validationType == null && ep != null) {
validationType = getSchemaValidationTypeFromModel(ep);
}
}
return validationType;
}
}
// else
return null;
}
use of org.apache.cxf.service.model.OperationInfo 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.OperationInfo in project cxf by apache.
the class OperationInfoAuthorizingInterceptor method handleMessage.
@Override
public void handleMessage(Message message) throws Fault {
OperationInfo opinfo = getTargetOperationInfo(message);
SecurityContext sc = message.get(SecurityContext.class);
if (sc != null && sc.getUserPrincipal() != null) {
if (opinfo.getName() != null && authorize(sc, opinfo.getName().getLocalPart())) {
return;
}
} else if (!isMethodProtected(opinfo.getName().getLocalPart()) && isAllowAnonymousUsers()) {
return;
}
throw new AccessDeniedException("Unauthorized");
}
Aggregations