@Override public List<URI> resolveAll(EndpointAddress address, Message message, EndpointAddressResolverMetadata metadata) throws EndpointAddressResolutionException { return Stream.of(address.getEndpoint().split(";")) .map(url -> safeResolve(message, url, metadata)) .collect(Collectors.toList()); }
public SubscriptionBuilder withEndpoint(String endpoint) { this.endpoint = EndpointAddress.of(endpoint); return this; }
public EndpointProtocolNotSupportedException(EndpointAddress endpoint) { super(String.format("Protocol %s not supported in endpoint %s", endpoint.getProtocol(), endpoint.toString())); }
public BasicAuthProvider(EndpointAddress endpoint) { String credentials = endpoint.getUsername() + ":" + endpoint.getPassword(); String encodedCredentials = Base64.encodeBase64String(credentials.getBytes(StandardCharsets.UTF_8)); this.token = "Basic " + encodedCredentials; }
@Override public MessageSender create(Subscription subscription) { EndpointAddress endpoint = subscription.getEndpoint(); URI uri = endpoint.getUri(); ConnectionFactory connectionFactory = getConnectionFactory(uri); JMSContext jmsContext = connectionFactory.createContext( endpoint.getUsername(), endpoint.getPassword() ); return new JmsMessageSender(jmsContext, extractTopicName(uri), metadataAppender); }
public URI interpolate(EndpointAddress endpoint, Message message) throws InterpolationException { UriTemplate template = templateCache.getUnchecked(endpoint.getEndpoint()); String[] variables = template.getVariables(); if (variables.length > 0) { Map<String, Object> values = Maps.newHashMap(); String payload = new String(message.getData(), Charsets.UTF_8); for (String variable : variables) { JsonPath path = variableCompiler.getUnchecked(variable); try { values.put(variable, path.read(payload)); } catch (InvalidPathException e) { throw new InterpolationException(String.format("Missing variable on path %s", path.getPath()), e); } } try { return URI.create(template.expand(values)); } catch (VariableExpansionException e) { throw new InterpolationException("Cannot expand template", e); } } return endpoint.getUri(); }
@Test public void willReturnURIAsIsIfNoTemplate() throws InterpolationException { // given EndpointAddress endpoint = EndpointAddress.of("http://some.endpoint.com/"); // when URI interpolated = new MessageBodyInterpolator().interpolate(endpoint, SAMPLE_MSG); // then assertThat(interpolated).isEqualTo(endpoint.getUri()); }
public MessageSender create(Subscription subscription) { EndpointAddress endpoint = subscription.getEndpoint(); ProtocolMessageSenderProvider provider = protocolProviders.get(endpoint.getProtocol()); if (provider == null) { throw new EndpointProtocolNotSupportedException(endpoint); } return provider.create(subscription); }
@Override public Subscription anonymize() { if (getEndpoint().containsCredentials() || hasOAuthPolicy()) { return new Subscription( topicName, name, endpoint.anonymize(), state, description, deliveryType == DeliveryType.BATCH ? batchSubscriptionPolicy : serialSubscriptionPolicy, trackingEnabled, trackingMode, owner, supportTeam, monitoringDetails, contentType, deliveryType, filters, mode, headers, endpointAddressResolverMetadata, oAuthPolicy != null ? oAuthPolicy.anonymize() : null, http2Enabled ); } return this; }
public EndpointAddress anonymize() { if(containsCredentials) { return new EndpointAddress(protocol, endpoint, username); } return this; } }
static URI resolve(EndpointAddress address) throws EndpointAddressResolutionException { try { return address.getUri(); } catch (Exception ex) { throw new EndpointAddressResolutionException(address, ex); } } }
public Optional<HttpAuthorizationProvider> create(Subscription subscription) { if(subscription.getEndpoint().containsCredentials()) { return Optional.of(new BasicAuthProvider(subscription.getEndpoint())); } else if (subscription.hasOAuthPolicy()) { return Optional.of(new OAuthHttpAuthorizationProvider(subscription.getQualifiedName(), accessTokens)); } return Optional.empty(); }
public String toString() { return address.toString(); } }
public void updateSubscription(Subscription newSubscription) { boolean endpointUpdated = !this.subscription.getEndpoint().equals(newSubscription.getEndpoint()); boolean subscriptionPolicyUpdated = !Objects.equals( this.subscription.getSerialSubscriptionPolicy(), newSubscription.getSerialSubscriptionPolicy() ); boolean endpointAddressResolverMetadataChanged = !Objects.equals( this.subscription.getEndpointAddressResolverMetadata(), newSubscription.getEndpointAddressResolverMetadata() ); boolean oAuthPolicyChanged = !Objects.equals( this.subscription.getOAuthPolicy(), newSubscription.getOAuthPolicy() ); this.subscription = newSubscription; this.requestTimeoutMs = newSubscription.getSerialSubscriptionPolicy().getRequestTimeout(); boolean httpClientChanged = this.subscription.isHttp2Enabled() != newSubscription.isHttp2Enabled(); if (endpointUpdated || subscriptionPolicyUpdated || endpointAddressResolverMetadataChanged || oAuthPolicyChanged || httpClientChanged) { this.messageSender = messageSenderFactory.create(newSubscription); } }
public URI interpolate(EndpointAddress endpoint, Message message) throws InterpolationException { UriTemplate template = templateCache.getUnchecked(endpoint.getEndpoint()); String[] variables = template.getVariables(); if (variables.length > 0) { Map<String, Object> values = Maps.newHashMap(); String payload = new String(message.getData(), Charsets.UTF_8); for (String variable : variables) { JsonPath path = variableCompiler.getUnchecked(variable); try { values.put(variable, path.read(payload)); } catch (InvalidPathException e) { throw new InterpolationException(String.format("Missing variable on path %s", path.getPath()), e); } } try { return URI.create(template.expand(values)); } catch (VariableExpansionException e) { throw new InterpolationException("Cannot expand template", e); } } return endpoint.getUri(); }
@Override public MessageSender create(Subscription subscription) { EndpointAddress endpoint = subscription.getEndpoint(); URI uri = endpoint.getUri(); ConnectionFactory connectionFactory = getConnectionFactory(uri); JMSContext jmsContext = connectionFactory.createContext( endpoint.getUsername(), endpoint.getPassword() ); return new JmsMessageSender(jmsContext, extractTopicName(uri), metadataAppender); }
public MessageSender create(Subscription subscription) { EndpointAddress endpoint = subscription.getEndpoint(); ProtocolMessageSenderProvider provider = protocolProviders.get(endpoint.getProtocol()); if (provider == null) { throw new EndpointProtocolNotSupportedException(endpoint); } return provider.create(subscription); }
public BasicAuthProvider(EndpointAddress endpoint) { String credentials = endpoint.getUsername() + ":" + endpoint.getPassword(); String encodedCredentials = Base64.encodeBase64String(credentials.getBytes(StandardCharsets.UTF_8)); this.token = "Basic " + encodedCredentials; }
public static EndpointAddress of(String endpoint) { return new EndpointAddress(endpoint); }
static URI resolve(EndpointAddress address) throws EndpointAddressResolutionException { try { return address.getUri(); } catch (Exception ex) { throw new EndpointAddressResolutionException(address, ex); } } }