use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class WSS4JFaultCodeTest method testNoSecurity.
/**
* Test for WSS4JInInterceptor when it receives a message with no security header.
*/
@Test
public void testNoSecurity() throws Exception {
Document doc = readDocument("wsse-request-clean.xml");
SoapMessage msg = getSoapMessageForDom(doc);
SOAPMessage saajMsg = msg.getContent(SOAPMessage.class);
doc = saajMsg.getSOAPPart();
byte[] docbytes = getMessageBytes(doc);
StaxUtils.read(new ByteArrayInputStream(docbytes));
WSS4JInInterceptor inHandler = new WSS4JInInterceptor();
SoapMessage inmsg = new SoapMessage(new MessageImpl());
Exchange ex = new ExchangeImpl();
ex.setInMessage(inmsg);
inmsg.setContent(SOAPMessage.class, saajMsg);
inHandler.setProperty(ConfigurationConstants.ACTION, ConfigurationConstants.ENCRYPTION);
inHandler.setProperty(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
inHandler.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
inmsg.put(SecurityConstants.RETURN_SECURITY_ERROR, Boolean.TRUE);
try {
inHandler.handleMessage(inmsg);
fail("Expected failure on an message with no security header");
} catch (SoapFault fault) {
assertTrue(fault.getReason().startsWith("An error was discovered processing the <wsse:Security> header"));
QName faultCode = new QName(WSS4JConstants.WSSE_NS, "InvalidSecurity");
assertEquals(fault.getFaultCode(), faultCode);
}
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class SamlTokenTest method makeInvocation.
private SoapMessage makeInvocation(Map<String, Object> outProperties, List<String> xpaths, Map<String, Object> inProperties, Map<String, String> inMessageProperties) throws Exception {
Document doc = readDocument("wsse-request-clean.xml");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();
SoapMessage msg = getSoapMessageForDom(doc);
for (String key : outProperties.keySet()) {
msg.put(key, outProperties.get(key));
}
handler.handleMessage(msg);
SOAPMessage saajMsg = msg.getContent(SOAPMessage.class);
doc = saajMsg.getSOAPPart();
for (String xpath : xpaths) {
assertValid(xpath, doc);
}
byte[] docbytes = getMessageBytes(doc);
XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(docbytes));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setIgnoringComments(false);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
db.setEntityResolver(new NullResolver());
StaxUtils.read(db, reader, false);
WSS4JInInterceptor inHandler = new WSS4JInInterceptor(inProperties);
SoapMessage inmsg = new SoapMessage(new MessageImpl());
inmsg.put(SecurityConstants.SAML_ROLE_ATTRIBUTENAME, "role");
for (String inMessageProperty : inMessageProperties.keySet()) {
inmsg.put(inMessageProperty, inMessageProperties.get(inMessageProperty));
}
Exchange ex = new ExchangeImpl();
ex.setInMessage(inmsg);
inmsg.setContent(SOAPMessage.class, saajMsg);
inHandler.handleMessage(inmsg);
return inmsg;
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class WadlGeneratorTest method testNoWadl.
@Test
public void testNoWadl() {
WadlGenerator wg = new WadlGenerator();
Message m = new MessageImpl();
m.setExchange(new ExchangeImpl());
assertNull(handleRequest(wg, m));
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class HTTPConduit method updateClientPolicy.
private void updateClientPolicy() {
if (!clientSidePolicyCalced) {
// do no spend time on building Message and Exchange (which basically
// are ConcurrentHashMap instances) if the policy is already available
Message m = new MessageImpl();
m.setExchange(new ExchangeImpl());
m.getExchange().put(EndpointInfo.class, this.endpointInfo);
updateClientPolicy(m);
}
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class WSPolicyFeature method createMessage.
private MessageImpl createMessage(Endpoint e, Bus b) {
MessageImpl m = new MessageImpl();
Exchange ex = new ExchangeImpl();
m.setExchange(ex);
ex.put(Endpoint.class, e);
ex.put(Bus.class, b);
ex.put(Service.class, e.getService());
return m;
}
Aggregations