Search in sources :

Example 1 with SLPropertiesMatcher

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;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SLPropertiesMatcher(org.talend.esb.servicelocator.client.SLPropertiesMatcher) EndpointReferenceList(org.talend.schemas.esb.locator.rest._2011._11.EndpointReferenceList) Endpoint(org.talend.esb.servicelocator.client.Endpoint) SimpleEndpoint(org.talend.esb.servicelocator.client.SimpleEndpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint)

Example 2 with SLPropertiesMatcher

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;
}
Also used : SLPropertiesMatcher(org.talend.esb.servicelocator.client.SLPropertiesMatcher) AssertionType(org.talend.schemas.esb.locator._2011._11.AssertionType)

Example 3 with SLPropertiesMatcher

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);
}
Also used : InterruptionFaultDetail(org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) SLPropertiesMatcher(org.talend.esb.servicelocator.client.SLPropertiesMatcher) ServiceLocatorFault(org.talend.services.esb.locator.v1.ServiceLocatorFault) InterruptedExceptionFault(org.talend.services.esb.locator.v1.InterruptedExceptionFault) ServiceLocatorFaultDetail(org.talend.schemas.esb.locator._2011._11.ServiceLocatorFaultDetail)

Example 4 with SLPropertiesMatcher

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);
}
Also used : ConduitSelectorHolder(org.apache.cxf.endpoint.ConduitSelectorHolder) SLPropertiesMatcher(org.talend.esb.servicelocator.client.SLPropertiesMatcher) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector)

Example 5 with SLPropertiesMatcher

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;
}
Also used : SLPropertiesMatcher(org.talend.esb.servicelocator.client.SLPropertiesMatcher) Map(java.util.Map)

Aggregations

SLPropertiesMatcher (org.talend.esb.servicelocator.client.SLPropertiesMatcher)7 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 QName (javax.xml.namespace.QName)2 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)2 SimpleEndpoint (org.talend.esb.servicelocator.client.SimpleEndpoint)2 InterruptionFaultDetail (org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail)2 ServiceLocatorFaultDetail (org.talend.schemas.esb.locator._2011._11.ServiceLocatorFaultDetail)2 InterruptedExceptionFault (org.talend.services.esb.locator.v1.InterruptedExceptionFault)2 ServiceLocatorFault (org.talend.services.esb.locator.v1.ServiceLocatorFault)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)1 ConduitSelector (org.apache.cxf.endpoint.ConduitSelector)1 ConduitSelectorHolder (org.apache.cxf.endpoint.ConduitSelectorHolder)1 Endpoint (org.talend.esb.servicelocator.client.Endpoint)1 AssertionType (org.talend.schemas.esb.locator._2011._11.AssertionType)1 EndpointReferenceList (org.talend.schemas.esb.locator.rest._2011._11.EndpointReferenceList)1