use of org.apache.cxf.transport.Destination in project cxf by apache.
the class MAPAggregatorImpl method getReplyTo.
private EndpointReferenceType getReplyTo(Message message, EndpointReferenceType originalReplyTo) {
Exchange exchange = message.getExchange();
Endpoint info = exchange.getEndpoint();
if (info == null) {
return originalReplyTo;
}
synchronized (info) {
EndpointInfo ei = info.getEndpointInfo();
Destination dest = ei.getProperty(DECOUPLED_DESTINATION, Destination.class);
if (dest == null) {
dest = createDecoupledDestination(message);
if (dest != null) {
info.getEndpointInfo().setProperty(DECOUPLED_DESTINATION, dest);
}
}
if (dest != null) {
// if the decoupled endpoint context prop is set and the address is relative, return the absolute url.
final String replyTo = dest.getAddress().getAddress().getValue();
if (replyTo.startsWith("/")) {
String debase = (String) message.getContextualProperty(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY);
if (debase != null) {
return EndpointReferenceUtils.getEndpointReference(debase + replyTo);
}
}
return dest.getAddress();
}
}
return originalReplyTo;
}
use of org.apache.cxf.transport.Destination in project cxf by apache.
the class AbstractPolicyInterceptor method getTransportAssertions.
protected void getTransportAssertions(Message message) {
Exchange ex = message.getExchange();
Conduit conduit = ex.getConduit(message);
Assertor assertor = PolicyUtils.createAsserter(conduit);
if (assertor == null) {
Destination destination = ex.getDestination();
assertor = PolicyUtils.createAsserter(destination);
}
if (null != assertor) {
assertor.assertMessage(message);
}
}
use of org.apache.cxf.transport.Destination in project cxf by apache.
the class JettyHTTPDestinationTest method testGetMultiple.
@Test
public void testGetMultiple() throws Exception {
bus = BusFactory.getDefaultBus(true);
transportFactory = new HTTPTransportFactory();
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setName(new QName("bla", "Service"));
EndpointInfo ei = new EndpointInfo(serviceInfo, "");
ei.setName(new QName("bla", "Port"));
ei.setAddress("http://foo");
Destination d1 = transportFactory.getDestination(ei, bus);
Destination d2 = transportFactory.getDestination(ei, bus);
// Second get should not generate a new destination. It should just retrieve the existing one
assertEquals(d1, d2);
d2.shutdown();
Destination d3 = transportFactory.getDestination(ei, bus);
// Now a new destination should have been created
assertNotSame(d1, d3);
}
use of org.apache.cxf.transport.Destination in project cxf by apache.
the class PolicyInInterceptor method handle.
protected void handle(Message msg) {
Exchange exchange = msg.getExchange();
Bus bus = exchange.getBus();
Endpoint e = exchange.getEndpoint();
if (null == e) {
LOG.fine("No endpoint.");
return;
}
EndpointInfo ei = e.getEndpointInfo();
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (null == pe) {
return;
}
List<Interceptor<? extends Message>> interceptors = new ArrayList<Interceptor<? extends Message>>();
Collection<Assertion> assertions = new ArrayList<>();
// 1. Check overridden policy
Policy p = (Policy) msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
if (p != null) {
EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
effectivePolicy.initialise(endpi, pe, true, msg);
msg.put(EffectivePolicy.class, effectivePolicy);
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
interceptors.addAll(effectivePolicy.getInterceptors());
assertions.addAll(effectivePolicy.getChosenAlternative());
} else if (MessageUtils.isRequestor(msg)) {
// 2. Process client policy
BindingOperationInfo boi = exchange.getBindingOperationInfo();
if (boi == null) {
Conduit conduit = exchange.getConduit(msg);
EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit, msg);
if (ep != null) {
interceptors.addAll(ep.getInterceptors(msg));
assertions.addAll(ep.getVocabulary(msg));
}
} else {
// We do not know the underlying message type yet - so we pre-emptively add interceptors
// that can deal with any resposes or faults returned to this client endpoint.
EffectivePolicy ep = pe.getEffectiveClientResponsePolicy(ei, boi, msg);
if (ep != null) {
interceptors.addAll(ep.getInterceptors());
// insert assertions of endpoint's vocabulary into message
if (ep.getPolicy() != null) {
msg.put(AssertionInfoMap.class, new AssertionInfoMap(ep.getPolicy()));
msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
}
}
}
} else {
// 3. Process server policy
Destination destination = exchange.getDestination();
// We do not know the underlying message type yet - so we pre-emptively add interceptors
// that can deal with any messages to this endpoint
EndpointPolicy ep = pe.getServerEndpointPolicy(ei, destination, msg);
if (ep != null) {
interceptors.addAll(ep.getInterceptors(msg));
assertions.addAll(ep.getVocabulary(msg));
}
}
// add interceptors into message chain
for (Interceptor<? extends Message> i : interceptors) {
msg.getInterceptorChain().add(i);
}
// Insert assertions of endpoint's vocabulary into message
if (!assertions.isEmpty()) {
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
msg.getInterceptorChain().add(PolicyVerificationInInterceptor.INSTANCE);
}
}
use of org.apache.cxf.transport.Destination in project cxf by apache.
the class PolicyOutInterceptor method handle.
protected void handle(Message msg) {
Exchange exchange = msg.getExchange();
Bus bus = exchange.getBus();
BindingOperationInfo boi = exchange.getBindingOperationInfo();
if (null == boi) {
LOG.fine("No binding operation info.");
return;
}
Endpoint e = exchange.getEndpoint();
if (null == e) {
LOG.fine("No endpoint.");
return;
}
EndpointInfo ei = e.getEndpointInfo();
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (null == pe) {
return;
}
Collection<Assertion> assertions = new ArrayList<>();
// 1. Check overridden policy
Policy p = (Policy) msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
if (p != null) {
EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
effectivePolicy.initialise(endpi, pe, false, msg);
msg.put(EffectivePolicy.class, effectivePolicy);
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
addInterceptors(effectivePolicy.getInterceptors(), msg);
assertions.addAll(effectivePolicy.getChosenAlternative());
} else if (MessageUtils.isRequestor(msg)) {
// 2. Process client policy
Conduit conduit = exchange.getConduit(msg);
// add the required interceptors
EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(ei, boi, conduit, msg);
msg.put(EffectivePolicy.class, effectivePolicy);
if (effectivePolicy != null) {
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
addInterceptors(effectivePolicy.getInterceptors(), msg);
assertions.addAll(effectivePolicy.getChosenAlternative());
}
} else {
// 3. Process server policy
Destination destination = exchange.getDestination();
List<List<Assertion>> incoming = 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) {
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
addInterceptors(effectivePolicy.getInterceptors(), msg);
assertions.addAll(effectivePolicy.getChosenAlternative());
}
}
// insert assertions of endpoint's fault vocabulary into message
if (null != assertions && !assertions.isEmpty()) {
if (LOG.isLoggable(Level.FINEST)) {
StringBuilder buf = new StringBuilder();
buf.append("Chosen alternative: ");
String nl = SystemPropertyAction.getProperty("line.separator");
buf.append(nl);
for (Assertion a : assertions) {
PolicyUtils.printPolicyComponent(a, buf, 1);
}
LOG.finest(buf.toString());
}
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
msg.getInterceptorChain().add(PolicyVerificationOutInterceptor.INSTANCE);
}
}
Aggregations