use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class WrappedOutInterceptor method handleMessage.
public void handleMessage(Message message) {
BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
if (bop != null && bop.isUnwrapped()) {
XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
MessageInfo messageInfo;
if (isRequestor(message)) {
messageInfo = bop.getWrappedOperation().getOperationInfo().getInput();
} else {
messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput();
}
QName name = messageInfo.getFirstMessagePart().getConcreteName();
try {
String pfx = null;
Service service = message.getExchange().getService();
if (service.getDataBinding().getDeclaredNamespaceMappings() != null) {
pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI());
}
if (pfx == null) {
pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false);
}
xmlWriter.setPrefix(pfx, name.getNamespaceURI());
xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());
if (StringUtils.isEmpty(pfx)) {
xmlWriter.writeDefaultNamespace(name.getNamespaceURI());
} else {
xmlWriter.writeNamespace(pfx, name.getNamespaceURI());
}
} catch (XMLStreamException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
}
// Add a final interceptor to write end element
message.getInterceptorChain().add(ending);
}
}
use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class CertConstraintsInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
final CertConstraints certConstraints = (CertConstraints) message.getContextualProperty(CertConstraints.class.getName());
if (certConstraints == null) {
return;
}
if (isRequestor(message)) {
try {
String scheme = (String) message.get("http.scheme");
if ("https".equals(scheme)) {
final MessageTrustDecider orig = message.get(MessageTrustDecider.class);
MessageTrustDecider trust = new HttpsMessageTrustDecider(certConstraints, orig);
message.put(MessageTrustDecider.class, trust);
} else {
throw new UntrustedURLConnectionIOException("TLS is not in use");
}
} catch (UntrustedURLConnectionIOException ex) {
throw new Fault(ex);
}
} else {
try {
TLSSessionInfo tlsInfo = message.get(TLSSessionInfo.class);
final Certificate[] certs = tlsInfo.getPeerCertificates();
if (certs == null || certs.length == 0) {
throw new UntrustedURLConnectionIOException("No client certificates were found");
}
X509Certificate[] x509Certs = (X509Certificate[]) certs;
if (!certConstraints.matches(x509Certs[0])) {
throw new UntrustedURLConnectionIOException("The client certificate does not match the defined cert constraints");
}
} catch (UntrustedURLConnectionIOException ex) {
throw new Fault(ex);
}
}
}
use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class AbstractRMInterceptorTest method testHandleMessageSequenceFaultNoBinding.
@Test
public void testHandleMessageSequenceFaultNoBinding() {
RMInterceptor interceptor = new RMInterceptor();
Message message = control.createMock(Message.class);
SequenceFault sf = control.createMock(SequenceFault.class);
interceptor.setSequenceFault(sf);
Exchange ex = control.createMock(Exchange.class);
EasyMock.expect(message.getExchange()).andReturn(ex).anyTimes();
Endpoint e = control.createMock(Endpoint.class);
EasyMock.expect(ex.getEndpoint()).andReturn(e);
EasyMock.expect(e.getBinding()).andReturn(null);
control.replay();
try {
interceptor.handleMessage(message);
fail("Expected Fault not thrown.");
} catch (Fault f) {
assertSame(sf, f.getCause());
}
}
use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class AbstractRMInterceptorTest method testHandleMessageSequenceFault.
@Test
public void testHandleMessageSequenceFault() {
RMInterceptor interceptor = new RMInterceptor();
Message message = control.createMock(Message.class);
SequenceFault sf = control.createMock(SequenceFault.class);
interceptor.setSequenceFault(sf);
Exchange ex = control.createMock(Exchange.class);
EasyMock.expect(message.getExchange()).andReturn(ex).anyTimes();
Endpoint e = control.createMock(Endpoint.class);
EasyMock.expect(ex.getEndpoint()).andReturn(e);
Binding b = control.createMock(Binding.class);
EasyMock.expect(e.getBinding()).andReturn(b);
RMManager mgr = control.createMock(RMManager.class);
interceptor.setManager(mgr);
BindingFaultFactory bff = control.createMock(BindingFaultFactory.class);
EasyMock.expect(mgr.getBindingFaultFactory(b)).andReturn(bff);
Fault fault = control.createMock(Fault.class);
EasyMock.expect(bff.createFault(sf, message)).andReturn(fault);
EasyMock.expect(bff.toString(fault)).andReturn("f");
control.replay();
try {
interceptor.handleMessage(message);
fail("Expected Fault not thrown.");
} catch (Fault f) {
assertSame(f, fault);
}
}
use of org.apache.cxf.interceptor.Fault in project cxf by apache.
the class BareInInterceptor method handleMessage.
public void handleMessage(Message message) {
if (isGET(message) && message.getContent(List.class) != null) {
LOG.fine("BareInInterceptor skipped in HTTP GET method");
return;
}
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
Exchange exchange = message.getExchange();
DataReader<XMLStreamReader> dr = getDataReader(message);
MessageContentsList parameters = new MessageContentsList();
Endpoint ep = exchange.getEndpoint();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
ServiceInfo si = ep.getEndpointInfo().getService();
BindingMessageInfo msgInfo = null;
boolean client = isRequestor(message);
Collection<OperationInfo> ops = null;
if (bop == null) {
ops = new ArrayList<>();
ops.addAll(si.getInterface().getOperations());
if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT && !client) {
// TO DO : check duplicate operation with no input
for (OperationInfo op : ops) {
MessageInfo bmsg = op.getInput();
if (bmsg.getMessagePartsNumber() == 0) {
BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
exchange.put(BindingOperationInfo.class, boi);
exchange.setOneWay(op.isOneWay());
}
}
}
} else {
getMessageInfo(message, bop);
if (client) {
msgInfo = bop.getOutput();
} else {
msgInfo = bop.getInput();
}
}
int paramNum = 0;
while (StaxUtils.toNextElement(xmlReader)) {
QName elName = xmlReader.getName();
final MessagePartInfo p;
if (msgInfo != null && msgInfo.getMessageParts() != null) {
assert msgInfo.getMessageParts().size() > paramNum;
p = msgInfo.getMessageParts().get(paramNum);
} else {
p = findMessagePart(exchange, ops, elName, client, paramNum, message);
}
if (p == null) {
throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", LOG, elName), Fault.FAULT_CODE_CLIENT);
}
final Object o;
try {
o = dr.read(p, xmlReader);
} catch (Fault fault) {
if (!isRequestor(message)) {
fault.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw fault;
}
if (o != null) {
parameters.put(p, o);
}
paramNum++;
}
if (!parameters.isEmpty()) {
message.setContent(List.class, parameters);
}
}
Aggregations