use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class DomainExpressionBuilderRegistryTest method testNoBuilder.
@Test
public void testNoBuilder() {
DomainExpressionBuilderRegistry reg = new DomainExpressionBuilderRegistry();
assertEquals(DomainExpressionBuilderRegistry.class, reg.getRegistrationType());
Element e = control.createMock(Element.class);
EasyMock.expect(e.getNamespaceURI()).andReturn("http://a.b.c");
EasyMock.expect(e.getLocalName()).andReturn("x");
control.replay();
try {
reg.build(e);
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
// expected
}
control.verify();
}
use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class Wsdl11AttachmentPolicyProviderTest method testResolveExternal.
@Test
public void testResolveExternal() {
// service has one extension of type PolicyReference, reference is external
Policy p = app.getElementPolicy(services[17]);
verifyAssertionsOnly(p, 2);
// referenced document does not contain policy with the required if
try {
app.getElementPolicy(endpoints[17]);
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
// expected
}
// referenced document cannot be found
try {
app.getElementPolicy(endpoints[17].getBinding());
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
// expected
}
}
use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class ExternalAttachmentProvider method readDocument.
void readDocument() {
if (null != attachments) {
return;
}
// read the document and build the attachments
attachments = new ArrayList<>();
Document doc = null;
try {
InputStream is = location.getInputStream();
if (null == is) {
throw new PolicyException(new org.apache.cxf.common.i18n.Message("COULD_NOT_OPEN_ATTACHMENT_DOC_EXC", BUNDLE, location));
}
doc = StaxUtils.read(is);
} catch (Exception ex) {
throw new PolicyException(ex);
}
for (Element ae : PolicyConstants.findAllPolicyElementsOfLocalName(doc, Constants.ELEM_POLICY_ATTACHMENT)) {
PolicyAttachment attachment = new PolicyAttachment();
for (Node nd = ae.getFirstChild(); nd != null; nd = nd.getNextSibling()) {
if (Node.ELEMENT_NODE != nd.getNodeType()) {
continue;
}
QName qn = new QName(nd.getNamespaceURI(), nd.getLocalName());
if (Constants.isAppliesToElem(qn)) {
Collection<DomainExpression> des = readDomainExpressions((Element) nd);
if (des.isEmpty()) {
// forget about this attachment
continue;
}
attachment.setDomainExpressions(des);
} else if (Constants.isPolicyElement(qn)) {
Policy p = builder.getPolicy(nd);
if (null != attachment.getPolicy()) {
p = p.merge(attachment.getPolicy());
}
attachment.setPolicy(p);
// cache the element so it can be used when generating the wsdl
attachment.setElement((Element) nd);
} else if (Constants.isPolicyRef(qn)) {
PolicyReference ref = builder.getPolicyReference(nd);
if (null != ref) {
Policy p = resolveReference(ref, doc);
if (null != attachment.getPolicy()) {
p = p.merge(attachment.getPolicy());
}
attachment.setPolicy(p);
}
}
// TODO: wsse:Security child element
}
if (null == attachment.getPolicy() || null == attachment.getDomainExpressions()) {
continue;
}
attachments.add(attachment);
}
}
use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class AbstractCommonBindingHandler method unassertPolicy.
protected void unassertPolicy(Assertion assertion, Exception reason) {
if (assertion == null) {
return;
}
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
}
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
Collection<AssertionInfo> ais = aim.get(assertion.getName());
if (ais != null) {
for (AssertionInfo ai : ais) {
if (ai.getAssertion() == assertion) {
ai.setNotAsserted(reason.getMessage());
}
}
}
if (!assertion.isOptional()) {
throw new PolicyException(new Message(reason.getMessage(), LOG), reason);
}
}
use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class AbstractCommonBindingHandler method unassertPolicy.
protected void unassertPolicy(Assertion assertion, String reason) {
if (assertion == null) {
return;
}
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Not asserting " + assertion.getName() + ": " + reason);
}
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
Collection<AssertionInfo> ais = aim.get(assertion.getName());
if (ais != null) {
for (AssertionInfo ai : ais) {
if (ai.getAssertion() == assertion) {
ai.setNotAsserted(reason);
}
}
}
if (!assertion.isOptional()) {
throw new PolicyException(new Message(reason, LOG));
}
}
Aggregations