use of org.talend.esb.servicelocator.client.SLPropertiesMatcher in project tesb-rt-se by Talend.
the class LocatorRestServiceImpl method lookupEndpoints.
/**
* For the given service return endpoint reference randomly selected from
* list of endpoints currently registered at the service locator server.
*
* @param input
* String encoded name of service
* @param input
* List of encoded additional parameters separated by comma
*
* @return EndpointReferenceListType encapsulate list of endpoint references
* or <code>null</code>
*/
public EndpointReferenceList lookupEndpoints(String arg0, List<String> arg1) {
QName serviceName = null;
try {
serviceName = QName.valueOf(URLDecoder.decode(arg0, "UTF-8"));
} catch (UnsupportedEncodingException e1) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1.getMessage()).build());
}
List<String> names = null;
String adress = null;
SLPropertiesMatcher matcher = null;
try {
matcher = createMatcher(arg1);
} catch (UnsupportedEncodingException e1) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1.getMessage()).build());
}
EndpointReferenceList refs = new EndpointReferenceList();
try {
initLocator();
if (matcher == null) {
names = locatorClient.lookup(serviceName);
} else {
names = locatorClient.lookup(serviceName, matcher);
}
} catch (ServiceLocatorException e) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
} catch (InterruptedException e) {
throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
}
if (names != null && !names.isEmpty()) {
for (int i = 0; i < names.size(); i++) {
adress = names.get(i);
refs.getEndpointReference().add(buildEndpoint(serviceName, adress));
}
} else {
if (LOG.isLoggable(Level.WARNING)) {
LOG.log(Level.WARNING, "lookup Endpoints for " + serviceName + " failed, service is not known.");
}
throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity("Service not found").build());
}
return refs;
}
use of org.talend.esb.servicelocator.client.SLPropertiesMatcher in project tesb-rt-se by Talend.
the class LocatorSoapServiceImpl method createMatcher.
private SLPropertiesMatcher createMatcher(MatcherDataType matcherData) {
SLPropertiesMatcher matcher = null;
if (matcherData != null) {
matcher = new SLPropertiesMatcher();
List<AssertionType> assertions = matcherData.getEntry();
for (AssertionType assertion : assertions) {
matcher.addAssertion(assertion.getKey(), assertion.getValue());
}
}
return matcher;
}
use of org.talend.esb.servicelocator.client.SLPropertiesMatcher in project tesb-rt-se by Talend.
the class LocatorSoapServiceImpl method lookupEndpoint.
/**
* For the given service return endpoint reference randomly selected from
* list of endpoints currently registered at the service locator server.
*
* @param serviceName
* the name of the service for which to get the endpoints, must
* not be <code>null</code>
* @return endpoint references or <code>null</code>
*/
W3CEndpointReference lookupEndpoint(QName serviceName, MatcherDataType matcherData) throws ServiceLocatorFault, InterruptedExceptionFault {
List<String> names = null;
String adress;
try {
initLocator();
SLPropertiesMatcher matcher = createMatcher(matcherData);
if (matcher == null) {
names = locatorClient.lookup(serviceName);
} else {
names = locatorClient.lookup(serviceName, matcher);
}
} catch (ServiceLocatorException e) {
ServiceLocatorFaultDetail serviceFaultDetail = new ServiceLocatorFaultDetail();
serviceFaultDetail.setLocatorFaultDetail(serviceName.toString() + "throws ServiceLocatorFault");
throw new ServiceLocatorFault(e.getMessage(), serviceFaultDetail);
} catch (InterruptedException e) {
InterruptionFaultDetail interruptionFaultDetail = new InterruptionFaultDetail();
interruptionFaultDetail.setInterruptionDetail(serviceName.toString() + "throws InterruptionFault");
throw new InterruptedExceptionFault(e.getMessage(), interruptionFaultDetail);
}
if (names != null && !names.isEmpty()) {
names = getRotatedList(names);
adress = names.get(0);
} else {
if (LOG.isLoggable(Level.WARNING)) {
LOG.log(Level.WARNING, "lookup Endpoint for " + serviceName + " failed, service is not known.");
}
ServiceLocatorFaultDetail serviceFaultDetail = new ServiceLocatorFaultDetail();
serviceFaultDetail.setLocatorFaultDetail("lookup Endpoint for " + serviceName + " failed, service is not known.");
throw new ServiceLocatorFault("Can not find Endpoint", serviceFaultDetail);
}
return buildEndpoint(serviceName, adress);
}
use of org.talend.esb.servicelocator.client.SLPropertiesMatcher in project tesb-rt-se by Talend.
the class LocatorFeatureImpl method initialize.
public void initialize(ConduitSelectorHolder conduitSelectorHolder, Bus bus) {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Initializing locator feature for bus " + bus + " and client configuration" + conduitSelectorHolder);
}
ConduitSelector conduitSelector = conduitSelectorHolder.getConduitSelector();
String selectionStrategy = (String) conduitSelector.getEndpoint().get(KEY_STRATEGY);
Map<String, String> endpointProps = getEndpointLocatorProperties(conduitSelector.getEndpoint());
SLPropertiesMatcher slPropsMatcher = createMatcher(endpointProps);
final ConduitSelectorHolder conduitSelectorHolder1 = conduitSelectorHolder;
clientEnabler.enable(conduitSelectorHolder1, slPropsMatcher, selectionStrategy);
}
use of org.talend.esb.servicelocator.client.SLPropertiesMatcher in project tesb-rt-se by Talend.
the class LocatorFeatureImpl method createMatcher.
private SLPropertiesMatcher createMatcher(Map<String, String> properties) {
SLPropertiesMatcher slPropsMatcher = new SLPropertiesMatcher();
if (properties == null) {
return slPropsMatcher;
}
if (LOG.isLoggable(Level.FINE)) {
StringBuilder sb = new StringBuilder();
for (String prop : properties.keySet()) {
sb.append(prop + " -> ");
sb.append(properties.get(prop) + "\n");
}
}
for (Map.Entry<String, String> entry : properties.entrySet()) {
for (String value : tokenize(entry.getValue())) {
slPropsMatcher.addAssertion(entry.getKey(), value);
}
}
LOG.fine("set matcher = " + slPropsMatcher.toString());
for (StackTraceElement trace : new Throwable().getStackTrace()) {
LOG.fine(trace.toString());
}
return slPropsMatcher;
}
Aggregations