Search in sources :

Example 1 with ServiceLocatorException

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

the class LocatorRestServiceImpl method updateTimetolive.

@Override
public void updateTimetolive(String arg0, String arg1, int timetolive) {
    String endpointURL = null;
    QName serviceName = null;
    try {
        serviceName = QName.valueOf(URLDecoder.decode(arg0, "UTF-8"));
        endpointURL = URLDecoder.decode(arg1, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1.getMessage()).build());
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Updating expiring time to happen in " + timetolive + " seconds on endpoint " + endpointURL + " for service " + serviceName + "...");
    }
    try {
        initLocator();
        locatorClient.updateTimetolive(serviceName, endpointURL, timetolive);
    } catch (ServiceLocatorException e) {
        if (e instanceof EndpointNotFoundException) {
            throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity(e.getMessage()).build());
        }
        if (e instanceof WrongArgumentException) {
            throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build());
        }
        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());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) EndpointNotFoundException(org.talend.esb.servicelocator.client.EndpointNotFoundException) QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WrongArgumentException(org.talend.esb.servicelocator.client.WrongArgumentException)

Example 2 with ServiceLocatorException

use of org.talend.esb.servicelocator.client.ServiceLocatorException 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 3 with ServiceLocatorException

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

the class LocatorRestServiceImpl method unregisterEndpoint.

/**
 * Unregister the endpoint for given service.
 *
 * @param input
 *            String encoded name of service
 * @param input
 *            String encoded name of endpoint
 */
public void unregisterEndpoint(String arg0, String arg1) {
    String endpointURL = null;
    QName serviceName = null;
    try {
        serviceName = QName.valueOf(URLDecoder.decode(arg0, "UTF-8"));
        endpointURL = URLDecoder.decode(arg1, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1.getMessage()).build());
    }
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Unregistering endpoint " + endpointURL + " for service " + serviceName + "...");
    }
    try {
        initLocator();
        locatorClient.unregister(serviceName, endpointURL);
    } 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());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with ServiceLocatorException

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

the class LocatorRestServiceImpl method registerEndpoint.

/**
 * Register the endpoint for given service.
 *
 * @param input
 *            RegisterEndpointRequestType encapsulate name of service and
 *            endpointURL. Must not be <code>null</code>
 */
public void registerEndpoint(RegisterEndpointRequest arg0) {
    String endpointURL = arg0.getEndpointURL();
    QName serviceName = QName.valueOf(arg0.getServiceName());
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Registering endpoint " + endpointURL + " for service " + serviceName + "...");
    }
    try {
        initLocator();
        BindingType bindingType = arg0.getBinding() == null ? BindingType.OTHER : BindingType.valueOf(arg0.getBinding().value());
        TransportType transportType = arg0.getTransport() == null ? TransportType.OTHER : TransportType.valueOf(arg0.getTransport().value());
        SLPropertiesImpl slProps = null;
        if (!arg0.getEntryType().isEmpty()) {
            slProps = new SLPropertiesImpl();
            List<EntryType> entries = arg0.getEntryType();
            for (EntryType entry : entries) {
                slProps.addProperty(entry.getKey(), entry.getValue());
            }
        }
        Endpoint simpleEndpoint = new SimpleEndpoint(serviceName, endpointURL, bindingType, transportType, slProps);
        locatorClient.register(simpleEndpoint, true);
    } catch (ServiceLocatorException e) {
        // throw new ServiceLocatorFault(e.getMessage(), e);
        throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
    } catch (InterruptedException e) {
        // throw new InterruptedExceptionFault(e.getMessage(), e);
        throw new WebApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build());
    }
}
Also used : EntryType(org.talend.schemas.esb.locator.rest._2011._11.EntryType) SimpleEndpoint(org.talend.esb.servicelocator.client.SimpleEndpoint) Endpoint(org.talend.esb.servicelocator.client.Endpoint) SimpleEndpoint(org.talend.esb.servicelocator.client.SimpleEndpoint) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) WebApplicationException(javax.ws.rs.WebApplicationException) QName(javax.xml.namespace.QName) BindingType(org.talend.esb.servicelocator.client.BindingType) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) SLPropertiesImpl(org.talend.esb.servicelocator.client.SLPropertiesImpl) TransportType(org.talend.esb.servicelocator.client.TransportType)

Example 5 with ServiceLocatorException

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

the class LocatorRestServiceTest method lookUpEndpointExpectedLocatorException.

@Test(expected = WebApplicationException.class)
public void lookUpEndpointExpectedLocatorException() throws ServiceLocatorException, InterruptedException {
    names.clear();
    names.add(ENDPOINTURL);
    expect(sl.lookup(SERVICE_NAME)).andStubThrow(new ServiceLocatorException("test"));
    replayAll();
    lps.lookupEndpoint(SERVICE_NAME.toString(), new ArrayList<String>());
}
Also used : ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) Test(org.junit.Test)

Aggregations

ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)35 Test (org.junit.Test)13 QName (javax.xml.namespace.QName)11 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)8 WebApplicationException (javax.ws.rs.WebApplicationException)6 InterruptionFaultDetail (org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail)6 ServiceLocatorFaultDetail (org.talend.schemas.esb.locator._2011._11.ServiceLocatorFaultDetail)6 InterruptedExceptionFault (org.talend.services.esb.locator.v1.InterruptedExceptionFault)6 ServiceLocatorFault (org.talend.services.esb.locator.v1.ServiceLocatorFault)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ServiceLocatorTracker (org.talend.esb.locator.tracker.ServiceLocatorTracker)4 SLPropertiesMatcher (org.talend.esb.servicelocator.client.SLPropertiesMatcher)4 SimpleEndpoint (org.talend.esb.servicelocator.client.SimpleEndpoint)4 JAXBException (javax.xml.bind.JAXBException)3 Endpoint (org.talend.esb.servicelocator.client.Endpoint)3 DOMResult (javax.xml.transform.dom.DOMResult)2 W3CEndpointReferenceBuilder (javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)2 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)2 BindingType (org.talend.esb.servicelocator.client.BindingType)2 SLProperties (org.talend.esb.servicelocator.client.SLProperties)2