use of org.apache.cxf.binding.soap.SoapVersion in project camel by apache.
the class SoapMessageHeaderFilter method filter.
public void filter(Direction direction, List<Header> headers) {
// Treat both in and out direction the same
if (headers == null) {
return;
}
Iterator<Header> iterator = headers.iterator();
while (iterator.hasNext()) {
Header header = iterator.next();
LOG.trace("Processing header: {}", header);
if (!(header instanceof SoapHeader)) {
LOG.trace("Skipped header: {} since it is not a SoapHeader", header);
continue;
}
SoapHeader soapHeader = SoapHeader.class.cast(header);
for (Iterator<SoapVersion> itv = SoapVersionFactory.getInstance().getVersions(); itv.hasNext(); ) {
SoapVersion version = itv.next();
if (soapHeader.getActor() != null && soapHeader.getActor().equals(version.getNextRole())) {
// dropping headers if actor/role equals to {ns}/role|actor/next
// cxf SoapHeader needs to have soap:header@relay attribute,
// then we can check for it here as well
LOG.trace("Filtered header: {}", header);
iterator.remove();
break;
}
}
}
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class MustUnderstandInterceptor method handleMessage.
public void handleMessage(SoapMessage soapMessage) {
Set<QName> paramHeaders = HeaderUtil.getHeaderQNameInOperationParam(soapMessage);
if (soapMessage.getHeaders().isEmpty() && paramHeaders.isEmpty()) {
return;
}
SoapVersion soapVersion = soapMessage.getVersion();
Set<Header> mustUnderstandHeaders = new HashSet<>();
Set<URI> serviceRoles = new HashSet<>();
Set<QName> notUnderstandHeaders = new HashSet<>();
Set<Header> ultimateReceiverHeaders = new HashSet<>();
Set<QName> mustUnderstandQNames = new HashSet<>();
initServiceSideInfo(mustUnderstandQNames, soapMessage, serviceRoles, paramHeaders);
buildMustUnderstandHeaders(mustUnderstandHeaders, soapMessage, serviceRoles, ultimateReceiverHeaders);
checkUnderstand(mustUnderstandHeaders, mustUnderstandQNames, notUnderstandHeaders);
if (!notUnderstandHeaders.isEmpty()) {
if (!isRequestor(soapMessage)) {
soapMessage.put(MustUnderstandInterceptor.UNKNOWNS, notUnderstandHeaders);
soapMessage.getInterceptorChain().add(ending);
} else {
throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notUnderstandHeaders), soapVersion.getMustUnderstand());
}
}
if (!ultimateReceiverHeaders.isEmpty() && !isRequestor(soapMessage)) {
checkUltimateReceiverHeaders(ultimateReceiverHeaders, mustUnderstandQNames, soapMessage);
}
}
use of org.apache.cxf.binding.soap.SoapVersion 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.SoapVersion in project cxf by apache.
the class SoapPreProtocolOutInterceptor method ensureVersion.
/**
* Ensure the SOAP version is set for this message.
*
* @param message the current message
*/
private void ensureVersion(SoapMessage message) {
SoapVersion soapVersion = message.getVersion();
if (soapVersion == null && message.getExchange().getInMessage() instanceof SoapMessage) {
soapVersion = ((SoapMessage) message.getExchange().getInMessage()).getVersion();
message.setVersion(soapVersion);
}
if (soapVersion == null) {
soapVersion = Soap11.getInstance();
message.setVersion(soapVersion);
}
message.put(Message.CONTENT_TYPE, soapVersion.getContentType());
}
use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.
the class EndpointSelectionInterceptor method selectEndpoint.
protected Endpoint selectEndpoint(Message message, Set<Endpoint> eps) {
SoapVersion sv = ((SoapMessage) message).getVersion();
for (Endpoint e : eps) {
EndpointInfo ei = e.getEndpointInfo();
BindingInfo binding = ei.getBinding();
if (binding instanceof SoapBindingInfo && ((SoapBindingInfo) binding).getSoapVersion().equals(sv)) {
return e;
}
}
return null;
}
Aggregations