void setPolicies(Message message) { if (null == engine || !engine.isEnabled()) { return; EndpointInfo ei = endpoint.getEndpointInfo(); EndpointPolicy epi = null == conduit ? engine.getServerEndpointPolicy(applicationEndpoint.getEndpointInfo(), null, message) : engine.getClientEndpointPolicy(applicationEndpoint.getEndpointInfo(), conduit, message); engine.setClientEndpointPolicy(ei, epi); } else { engine.setServerEndpointPolicy(ei, epi); engine.setEffectiveServerRequestPolicy(ei, boi, effectiveInbound); engine.setEffectiveServerResponsePolicy(ei, boi, effectiveOutbound); engine.setEffectiveClientRequestPolicy(ei, boi, effectiveOutbound); engine.setEffectiveClientResponsePolicy(ei, boi, effectiveInbound);
public final void setBus(Bus theBus) { bus = theBus; if (bus != null) { theBus.setExtension(this, PolicyBuilder.class); AssertionBuilderRegistry reg = theBus.getExtension(AssertionBuilderRegistry.class); if (reg != null) { factory = reg; } org.apache.cxf.ws.policy.PolicyEngine e = bus.getExtension(org.apache.cxf.ws.policy.PolicyEngine.class); if (e != null) { this.setPolicyRegistry(e.getRegistry()); } } }
public void initializePolicyEngine(Bus bus) { // this should never be null as features are initialized only // after the bus and all its extensions have been created PolicyEngine pe = bus.getExtension(PolicyEngine.class); synchronized (pe) { pe.setEnabled(enabled); pe.setIgnoreUnknownAssertions(ignoreUnknownAssertions); if (null != alternativeSelector) { pe.setAlternativeSelector(alternativeSelector); } } }
void initialisePolicy(EndpointInfo ei, BindingOperationInfo boi, BindingFaultInfo bfi, PolicyEngine engine, Message m) { policy = engine.getServerEndpointPolicy(ei, (Destination)null, m).getPolicy(); policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedOperationPolicy(boi, m)); if (bfi != null) { policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedFaultPolicy(bfi, m)); } policy = policy.normalize(engine.getRegistry(), true); }
Assertor initialisePolicy(EndpointInfo ei, BindingOperationInfo boi, PolicyEngine engine, boolean requestor, boolean request, Assertor assertor, Message m) { if (boi.isUnwrapped()) { boi = boi.getUnwrappedOperation(); } BindingMessageInfo bmi = request ? boi.getInput() : boi.getOutput(); EndpointPolicy ep; if (requestor) { ep = engine.getClientEndpointPolicy(ei, getAssertorAs(assertor, Conduit.class), m); } else { ep = engine.getServerEndpointPolicy(ei, getAssertorAs(assertor, Destination.class), m); } policy = ep.getPolicy(); if (ep instanceof EndpointPolicyImpl) { assertor = ((EndpointPolicyImpl)ep).getAssertor(); } policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedOperationPolicy(boi, m)); if (null != bmi) { policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedMessagePolicy(bmi, m)); } policy = policy.normalize(engine.getRegistry(), true); return assertor; }
public <T> T getServerEndpointPolicy(Message m, EndpointInfo ei, Destination d, PolicyCalculator<T> policyCalculator) { Collection<Assertion> alternative = getPolicyEngine() .getServerEndpointPolicy(ei, d, m).getChosenAlternative(); List<T> filteredPolicies = new ArrayList<>(); for (Assertion a : alternative) { if (policyCalculator.getDataClassName().equals(a.getName())) { T p = JaxbAssertion.cast(a, policyCalculator.getDataClass()).getData(); filteredPolicies.add(p); } } return getPolicy(filteredPolicies, policyCalculator); }
if (boi == null) { Conduit conduit = exchange.getConduit(msg); EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit, msg); if (ep != null) { interceptors.addAll(ep.getInterceptors(msg)); EffectivePolicy ep = pe.getEffectiveClientResponsePolicy(ei, boi, msg); if (ep != null) { interceptors.addAll(ep.getInterceptors()); EndpointPolicy ep = pe.getServerEndpointPolicy(ei, destination, msg); if (ep != null) { interceptors.addAll(ep.getInterceptors(msg));
@Override public void initialize(Server server, Bus bus) { Endpoint endpoint = server.getEndpoint(); Policy p = initializeEndpointPolicy(endpoint, bus); PolicyEngine pe = bus.getExtension(PolicyEngine.class); EndpointInfo ei = endpoint.getEndpointInfo(); EndpointPolicy ep = pe.getServerEndpointPolicy(ei, null, null); pe.setServerEndpointPolicy(ei, ep.updatePolicy(p, createMessage(endpoint, bus))); // Add policy to the service model (and consequently to the WSDL) // FIXME - ideally this should probably be moved up to where the policies are applied to the // endpoint, rather than this late. As a consequence of its location, you have to declare a // ws policy feature on every endpoint in order to get any policy attachments into the // wsdl. Alternatively add to the WSDLServiceBuilder somehow. ServiceModelPolicyUpdater pu = new ServiceModelPolicyUpdater(ei); for (PolicyProvider pp : ((PolicyEngineImpl) pe).getPolicyProviders()) { if (pp instanceof ExternalAttachmentProvider) { pu.addPolicyAttachments(((ExternalAttachmentProvider) pp).getAttachments()); } } }
public void setupServer(boolean mtomRequired, String address) throws Exception { getStaticBus().getExtension(PolicyEngine.class).setAlternativeSelector( new FirstAlternativeSelector()); JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean(); sf.setServiceBean(new EchoService()); sf.setBus(getStaticBus()); sf.setAddress(address); WSPolicyFeature policyFeature = new WSPolicyFeature(); List<Element> policyElements = new ArrayList<>(); if (mtomRequired) { policyElements.add(StaxUtils.read( getClass().getResourceAsStream("mtom-policy.xml")) .getDocumentElement()); } else { policyElements.add(StaxUtils.read( getClass().getResourceAsStream("mtom-policy-optional.xml")) .getDocumentElement()); } policyFeature.setPolicyElements(policyElements); sf.getFeatures().add(policyFeature); sf.create(); }
@Override public void initialize(Client client, Bus bus) { Endpoint endpoint = client.getEndpoint(); Policy p = initializeEndpointPolicy(endpoint, bus); PolicyEngine pe = bus.getExtension(PolicyEngine.class); EndpointInfo ei = endpoint.getEndpointInfo(); EndpointPolicy ep = pe.getClientEndpointPolicy(ei, null, null); pe.setClientEndpointPolicy(ei, ep.updatePolicy(p, createMessage(endpoint, bus))); }
EndpointInfo ei = e.getEndpointInfo(); if (MessageUtils.isRequestor(message)) { effectivePolicy = pe.getEffectiveClientResponsePolicy(ei, boi, message); } else { effectivePolicy = pe.getEffectiveServerRequestPolicy(ei, boi, message);
EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(ei, boi, conduit, msg); msg.put(EffectivePolicy.class, effectivePolicy); if (effectivePolicy != null) { = CastUtils.cast((List<?>)exchange.get("ws-policy.validated.alternatives")); EffectivePolicy effectivePolicy = pe.getEffectiveServerResponsePolicy(ei, boi, destination, incoming, msg); msg.put(EffectivePolicy.class, effectivePolicy); if (effectivePolicy != null) {
public <T> T getClientEndpointPolicy(Message m, EndpointInfo ei, Conduit c, PolicyCalculator<T> policyCalculator) { Collection<Assertion> alternative = getPolicyEngine().getClientEndpointPolicy(ei, c, m) .getChosenAlternative(); List<T> filteredPolicies = new ArrayList<>(); for (Assertion a : alternative) { if (policyCalculator.getDataClassName().equals(a.getName())) { T p = JaxbAssertion.cast(a, policyCalculator.getDataClass()).getData(); filteredPolicies.add(p); } } return getPolicy(filteredPolicies, policyCalculator); }
Conduit conduit = client.getConduit(); EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(client.getEndpoint().getEndpointInfo(), boi, conduit, PhaseInterceptorChain.getCurrentMessage());
public void handleMessage(Message message) throws Fault { EndpointInfo ei = message.getExchange().getEndpoint().getEndpointInfo(); BindingOperationInfo boi = message.getExchange().getBindingOperationInfo(); LOG.fine("Getting effective server request policy for endpoint " + ei + " and binding operation " + boi); EffectivePolicy ep = bus.getExtension(PolicyEngine.class).getEffectiveServerRequestPolicy(ei, boi, message); for (Iterator<List<Assertion>> it = ep.getPolicy().getAlternatives(); it.hasNext();) { Collection<Assertion> as = it.next(); LOG.fine("Checking alternative with " + as.size() + " assertions."); for (Assertion a : as) { LOG.fine("Assertion: " + a.getClass().getName()); HTTPServerPolicy p = (JaxbAssertion.cast(a, HTTPServerPolicy.class)).getData(); LOG.fine("server policy: " + ServerPolicyCalculator.toString(p)); } } }
.getExtension(PolicyEngine.class).setEnabled(true); getStaticBus().getOutInterceptors().add(new LoggingOutInterceptor());
Assertor initialisePolicy(EndpointInfo ei, BindingOperationInfo boi, PolicyEngine engine, boolean requestor, boolean request, Assertor assertor, Message m) { if (boi.isUnwrapped()) { boi = boi.getUnwrappedOperation(); } BindingMessageInfo bmi = request ? boi.getInput() : boi.getOutput(); EndpointPolicy ep; if (requestor) { ep = engine.getClientEndpointPolicy(ei, getAssertorAs(assertor, Conduit.class), m); } else { ep = engine.getServerEndpointPolicy(ei, getAssertorAs(assertor, Destination.class), m); } policy = ep.getPolicy(); if (ep instanceof EndpointPolicyImpl) { assertor = ((EndpointPolicyImpl)ep).getAssertor(); } policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedOperationPolicy(boi, m)); if (null != bmi) { policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedMessagePolicy(bmi, m)); } policy = policy.normalize(engine.getRegistry(), true); return assertor; }
public <T> T getServerEndpointPolicy(Message m, EndpointInfo ei, Destination d, PolicyCalculator<T> policyCalculator) { Collection<Assertion> alternative = getPolicyEngine() .getServerEndpointPolicy(ei, d, m).getChosenAlternative(); List<T> filteredPolicies = new ArrayList<>(); for (Assertion a : alternative) { if (policyCalculator.getDataClassName().equals(a.getName())) { T p = JaxbAssertion.cast(a, policyCalculator.getDataClass()).getData(); filteredPolicies.add(p); } } return getPolicy(filteredPolicies, policyCalculator); }
void initialisePolicy(EndpointInfo ei, BindingOperationInfo boi, BindingFaultInfo bfi, PolicyEngine engine, Message m) { policy = engine.getServerEndpointPolicy(ei, (Destination)null, m).getPolicy(); policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedOperationPolicy(boi, m)); if (bfi != null) { policy = policy.merge(((PolicyEngineImpl)engine).getAggregatedFaultPolicy(bfi, m)); } policy = policy.normalize(engine.getRegistry(), true); }
if (boi == null) { Conduit conduit = exchange.getConduit(msg); EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit, msg); if (ep != null) { interceptors.addAll(ep.getInterceptors(msg)); EffectivePolicy ep = pe.getEffectiveClientResponsePolicy(ei, boi, msg); if (ep != null) { interceptors.addAll(ep.getInterceptors()); EndpointPolicy ep = pe.getServerEndpointPolicy(ei, destination, msg); if (ep != null) { interceptors.addAll(ep.getInterceptors(msg));