use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class PolicyUtilsTest method testAssertServerPolicy.
void testAssertServerPolicy(boolean outbound) {
Message message = control.createMock(Message.class);
HTTPServerPolicy ep = new HTTPServerPolicy();
HTTPServerPolicy mp = new HTTPServerPolicy();
HTTPServerPolicy cmp = new HTTPServerPolicy();
cmp.setReceiveTimeout(60000L);
HTTPServerPolicy icmp = new HTTPServerPolicy();
icmp.setSuppressClientSendErrors(true);
AssertionInfo eai = getServerPolicyAssertionInfo(ep);
AssertionInfo mai = getServerPolicyAssertionInfo(mp);
AssertionInfo cmai = getServerPolicyAssertionInfo(cmp);
AssertionInfo icmai = getServerPolicyAssertionInfo(icmp);
Collection<AssertionInfo> ais = new ArrayList<>();
ais.add(eai);
ais.add(mai);
ais.add(cmai);
ais.add(icmai);
AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
aim.put(new ServerPolicyCalculator().getDataClassName(), ais);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).atLeastOnce();
Exchange ex = control.createMock(Exchange.class);
EasyMock.expect(message.getExchange()).andReturn(ex).atLeastOnce();
EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null).atLeastOnce();
if (!outbound) {
EasyMock.expect(ex.getOutFaultMessage()).andReturn(null).atLeastOnce();
}
control.replay();
new PolicyDataEngineImpl(null).assertMessage(message, ep, new ServerPolicyCalculator());
assertTrue(eai.isAsserted());
assertTrue(mai.isAsserted());
assertTrue(outbound ? cmai.isAsserted() : !cmai.isAsserted());
assertTrue(outbound ? icmai.isAsserted() : !icmai.isAsserted());
control.verify();
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class MAPAggregatorImpl method assertAddressing.
/**
* Asserts all Addressing assertions for the current message, regardless their nested
* Policies.
* @param message the current message
*/
private void assertAddressing(Message message, EndpointReferenceType replyTo, EndpointReferenceType faultTo) {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (null == aim) {
return;
}
if (faultTo == null) {
faultTo = replyTo;
}
boolean anonReply = ContextUtils.isGenericAddress(replyTo);
boolean anonFault = ContextUtils.isGenericAddress(faultTo);
boolean onlyAnonymous = anonReply && anonFault;
boolean hasAnonymous = anonReply || anonFault;
QName[] types = new QName[] { MetadataConstants.ADDRESSING_ASSERTION_QNAME, MetadataConstants.USING_ADDRESSING_2004_QNAME, MetadataConstants.USING_ADDRESSING_2005_QNAME, MetadataConstants.USING_ADDRESSING_2006_QNAME };
for (QName type : types) {
assertAssertion(aim, type);
// ADDRESSING_ASSERTION is normalized, so check only the default namespace
if (type.equals(MetadataConstants.ADDRESSING_ASSERTION_QNAME)) {
if (onlyAnonymous) {
assertAssertion(aim, MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME);
} else if (!hasAnonymous) {
assertAssertion(aim, MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME);
}
}
}
if (!MessageUtils.isRequestor(message) && !MessageUtils.isOutbound(message)) {
// need to throw an appropriate fault for these
Collection<AssertionInfo> aicNonAnon = aim.getAssertionInfo(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME);
Collection<AssertionInfo> aicNonAnon2 = aim.getAssertionInfo(MetadataConstants.NON_ANON_RESPONSES_ASSERTION_QNAME_0705);
Collection<AssertionInfo> aicAnon = aim.getAssertionInfo(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME);
Collection<AssertionInfo> aicAnon2 = aim.getAssertionInfo(MetadataConstants.ANON_RESPONSES_ASSERTION_QNAME_0705);
boolean hasAnon = (aicAnon != null && !aicAnon.isEmpty()) || (aicAnon2 != null && !aicAnon2.isEmpty());
boolean hasNonAnon = (aicNonAnon != null && !aicNonAnon.isEmpty()) || (aicNonAnon2 != null && !aicNonAnon2.isEmpty());
if (hasAnonymous && hasNonAnon && !hasAnon) {
message.put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
if (isSOAP12(message)) {
SoapFault soap12Fault = new SoapFault("Found anonymous address but non-anonymous required", Soap12.getInstance().getSender());
soap12Fault.addSubCode(new QName(Names.WSA_NAMESPACE_NAME, "OnlyNonAnonymousAddressSupported"));
throw soap12Fault;
}
throw new SoapFault("Found anonymous address but non-anonymous required", new QName(Names.WSA_NAMESPACE_NAME, "OnlyNonAnonymousAddressSupported"));
} else if (!onlyAnonymous && !hasNonAnon && hasAnon) {
message.put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
if (isSOAP12(message)) {
SoapFault soap12Fault = new SoapFault("Found non-anonymous address but only anonymous supported", Soap12.getInstance().getSender());
soap12Fault.addSubCode(new QName(Names.WSA_NAMESPACE_NAME, "OnlyAnonymousAddressSupported"));
throw soap12Fault;
}
throw new SoapFault("Found non-anonymous address but only anonymous supported", new QName(Names.WSA_NAMESPACE_NAME, "OnlyAnonymousAddressSupported"));
}
}
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class MTOMPolicyInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
// extract Assertion information
if (aim != null) {
Collection<AssertionInfo> ais = aim.get(MetadataConstants.MTOM_ASSERTION_QNAME);
for (AssertionInfo ai : ais) {
if (MessageUtils.isRequestor(message)) {
// just turn on MTOM
message.put(Message.MTOM_ENABLED, Boolean.TRUE);
ai.setAsserted(true);
} else {
// set mtom enabled and assert the policy if we find an mtom request
String contentType = (String) message.getExchange().getInMessage().get(Message.CONTENT_TYPE);
if (contentType != null && contentType.contains("type=\"application/xop+xml\"")) {
ai.setAsserted(true);
message.put(Message.MTOM_ENABLED, Boolean.TRUE);
}
}
}
}
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class AbstractRMInterceptorTest method testAssertReliability.
@Test
public void testAssertReliability() {
RMInterceptor interceptor = new RMInterceptor();
Message message = control.createMock(Message.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
AssertionInfoMap aim = control.createMock(AssertionInfoMap.class);
Collection<AssertionInfo> ais = new ArrayList<>();
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).times(2);
PolicyAssertion a = control.createMock(PolicyAssertion.class);
AssertionInfo ai = new AssertionInfo(a);
EasyMock.expectLastCall();
control.replay();
interceptor.assertReliability(message);
assertFalse(ai.isAsserted());
aim.put(RM10Constants.RMASSERTION_QNAME, ais);
interceptor.assertReliability(message);
assertFalse(ai.isAsserted());
ais.add(ai);
interceptor.assertReliability(message);
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class NegotiationUtils method getAddressingPolicy.
static Assertion getAddressingPolicy(AssertionInfoMap aim, boolean optional) {
Collection<AssertionInfo> lst = aim.get(MetadataConstants.USING_ADDRESSING_2004_QNAME);
Assertion assertion = null;
if (null != lst && !lst.isEmpty()) {
assertion = lst.iterator().next().getAssertion();
}
if (assertion == null) {
lst = aim.get(MetadataConstants.USING_ADDRESSING_2005_QNAME);
if (null != lst && !lst.isEmpty()) {
assertion = lst.iterator().next().getAssertion();
}
}
if (assertion == null) {
lst = aim.get(MetadataConstants.USING_ADDRESSING_2006_QNAME);
if (null != lst && !lst.isEmpty()) {
assertion = lst.iterator().next().getAssertion();
}
}
if (assertion == null) {
return new PrimitiveAssertion(MetadataConstants.USING_ADDRESSING_2006_QNAME, optional);
} else if (optional) {
return new PrimitiveAssertion(assertion.getName(), optional);
}
return assertion;
}
Aggregations