Search in sources :

Example 6 with SLPropertiesMatcher

use of org.talend.esb.servicelocator.client.SLPropertiesMatcher in project tesb-rt-se by Talend.

the class LocatorRestServiceImpl method lookupEndpoint.

/**
 * 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 endpoint references or <code>null</code>
 */
@Override
public W3CEndpointReference lookupEndpoint(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("Error during decoding serviceName").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("Error during decoding serviceName").build());
    }
    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()) {
        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.");
        }
        throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity("lookup Endpoint for " + serviceName + " failed, service is not known.").build());
    }
    return buildEndpoint(serviceName, adress);
}
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)

Example 7 with SLPropertiesMatcher

use of org.talend.esb.servicelocator.client.SLPropertiesMatcher in project tesb-rt-se by Talend.

the class LocatorSoapServiceImpl method lookupEndpoints.

/**
 * For the given service name return list of endpoint references currently
 * registered at the service locator server endpoints.
 *
 * @param serviceName
 *            the name of the service for which to get the endpoints, must
 *            not be <code>null</code>
 * @return EndpointReferenceListType encapsulate list of endpoint references
 *         or <code>null</code>
 */
List<W3CEndpointReference> lookupEndpoints(QName serviceName, MatcherDataType matcherData) throws ServiceLocatorFault, InterruptedExceptionFault {
    SLPropertiesMatcher matcher = createMatcher(matcherData);
    List<String> names = null;
    List<W3CEndpointReference> result = new ArrayList<W3CEndpointReference>();
    String adress;
    try {
        initLocator();
        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()) {
        for (int i = 0; i < names.size(); i++) {
            adress = names.get(i);
            result.add(buildEndpoint(serviceName, adress));
        }
    } else {
        if (LOG.isLoggable(Level.WARNING)) {
            LOG.log(Level.WARNING, "lookup Endpoints 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 result;
}
Also used : ArrayList(java.util.ArrayList) SLPropertiesMatcher(org.talend.esb.servicelocator.client.SLPropertiesMatcher) ServiceLocatorFault(org.talend.services.esb.locator.v1.ServiceLocatorFault) InterruptedExceptionFault(org.talend.services.esb.locator.v1.InterruptedExceptionFault) SimpleEndpoint(org.talend.esb.servicelocator.client.SimpleEndpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) ServiceLocatorFaultDetail(org.talend.schemas.esb.locator._2011._11.ServiceLocatorFaultDetail) InterruptionFaultDetail(org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException)

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