org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cxf-bundle-minimal Show documentation
Show all versions of cxf-bundle-minimal Show documentation
Apache CXF Minimal Bundle Jar
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.binding.soap.interceptor;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.apache.cxf.binding.soap.HeaderUtil;
import org.apache.cxf.binding.soap.SoapFault;
import org.apache.cxf.binding.soap.SoapHeader;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.SoapVersion;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.headers.Header;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.interceptor.OneWayProcessorInterceptor;
import org.apache.cxf.phase.Phase;
public class MustUnderstandInterceptor extends AbstractSoapInterceptor {
public static final String FAULT = "MustUnderstand.Fault";
private static final Logger LOG = LogUtils.getL7dLogger(MustUnderstandInterceptor.class);
private static final ResourceBundle BUNDLE = LOG.getResourceBundle();
private MustUnderstandEndingInterceptor ending = new MustUnderstandEndingInterceptor();
public MustUnderstandInterceptor() {
super(Phase.PRE_PROTOCOL);
}
public MustUnderstandInterceptor(String phase) {
super(phase);
}
public void handleMessage(SoapMessage soapMessage) {
Set paramHeaders = HeaderUtil.getHeaderQNameInOperationParam(soapMessage);
if (soapMessage.getHeaders().isEmpty() && paramHeaders.isEmpty()) {
return;
}
SoapVersion soapVersion = soapMessage.getVersion();
Set mustUnderstandHeaders = new HashSet();
Set serviceRoles = new HashSet();
Set notUnderstandHeaders = new HashSet();
Set ultimateReceiverHeaders = new HashSet();
Set mustUnderstandQNames = new HashSet();
initServiceSideInfo(mustUnderstandQNames, soapMessage, serviceRoles, paramHeaders);
buildMustUnderstandHeaders(mustUnderstandHeaders, soapMessage,
serviceRoles, ultimateReceiverHeaders);
checkUnderstand(mustUnderstandHeaders, mustUnderstandQNames, notUnderstandHeaders);
if (!notUnderstandHeaders.isEmpty()) {
SoapFault soapFault = new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notUnderstandHeaders),
soapVersion.getMustUnderstand());
if (!isRequestor(soapMessage)) {
soapMessage.put(MustUnderstandInterceptor.FAULT, soapFault);
soapMessage.getInterceptorChain().add(ending);
} else {
throw soapFault;
}
}
if (!ultimateReceiverHeaders.isEmpty() && !isRequestor(soapMessage)) {
checkUltimateReceiverHeaders(ultimateReceiverHeaders, mustUnderstandQNames, soapMessage);
}
}
public void handleFault(SoapMessage message) {
SoapFault soapFault = (SoapFault)message.get(MustUnderstandInterceptor.FAULT);
if (soapFault != null
&& !message.getExchange().isOneWay()
&& soapFault != message.getContent(Exception.class)) {
message.setContent(Exception.class, soapFault);
}
}
private void checkUltimateReceiverHeaders(Set ultimateReceiverHeaders,
Set mustUnderstandQNames,
SoapMessage soapMessage) {
soapMessage.getInterceptorChain()
.add(new UltimateReceiverMustUnderstandInterceptor(mustUnderstandQNames));
Object o = soapMessage.getContextualProperty("endpoint-processes-headers");
if (o == null) {
o = Collections.EMPTY_LIST;
}
Collection