Search in sources :

Example 16 with ServiceLocatorException

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

the class ServiceLocatorImplTest method connectFailing.

@Test
public void connectFailing() throws Exception {
    expect(backend.connect()).andThrow(new ServiceLocatorException());
    replayAll();
    ServiceLocatorImpl slc = new ServiceLocatorImpl();
    slc.setBackend(backend);
    try {
        slc.connect();
        fail("A ServiceLocatorException should have been thrown.");
    } catch (ServiceLocatorException e) {
        ignore("Expected exception");
    }
    verifyAll();
}
Also used : ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) Test(org.junit.Test)

Example 17 with ServiceLocatorException

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

the class CXFEndpointProvider method writeEndpointReferenceTo.

/* (non-Javadoc)
     * @see org.talend.esb.servicelocator.client.Endpoint#writeEndpointReferenceTo(javax.xml.transform.Result, org.talend.esb.servicelocator.client.Endpoint.PropertiesTransformer)
     */
@Override
public void writeEndpointReferenceTo(Result result, PropertiesTransformer transformer) throws ServiceLocatorException {
    try {
        JAXBElement<EndpointReferenceType> ep = WSA_OBJECT_FACTORY.createEndpointReference(epr);
        createMarshaller().marshal(ep, result);
    } catch (JAXBException e) {
        if (LOG.isLoggable(Level.SEVERE)) {
            LOG.log(Level.SEVERE, "Failed to serialize endpoint data", e);
        }
        throw new ServiceLocatorException("Failed to serialize endpoint data", e);
    }
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) JAXBException(javax.xml.bind.JAXBException)

Example 18 with ServiceLocatorException

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

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

the class LocatorRestServiceImpl method buildEndpoint.

/**
 * Build Endpoint Reference for giving service name and address
 *
 * @param serviceName
 * @param adress
 * @return
 */
private W3CEndpointReference buildEndpoint(QName serviceName, String adress) {
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    // builder.serviceName(serviceName);
    builder.address(adress);
    SLEndpoint endpoint = null;
    try {
        endpoint = locatorClient.getEndpoint(serviceName, adress);
    } 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 (endpoint != null) {
        SLProperties properties = endpoint.getProperties();
        if (properties != null && !properties.getPropertyNames().isEmpty()) {
            EndpointTransformerImpl transformer = new EndpointTransformerImpl();
            DOMResult result = new DOMResult();
            transformer.writePropertiesTo(properties, result);
            Document docResult = (Document) result.getNode();
            builder.metadata(docResult.getDocumentElement());
        }
    }
    return builder.build();
}
Also used : SLProperties(org.talend.esb.servicelocator.client.SLProperties) W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) EndpointTransformerImpl(org.talend.esb.servicelocator.client.internal.EndpointTransformerImpl) DOMResult(javax.xml.transform.dom.DOMResult) WebApplicationException(javax.ws.rs.WebApplicationException) ServiceLocatorException(org.talend.esb.servicelocator.client.ServiceLocatorException) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) Document(org.w3c.dom.Document)

Example 20 with ServiceLocatorException

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

the class LocatorRestServiceTest method lookUpEndpointsExpectedLocatorException.

@Test(expected = WebApplicationException.class)
public void lookUpEndpointsExpectedLocatorException() throws ServiceLocatorException, InterruptedException {
    names.clear();
    names.add(ENDPOINTURL);
    expect(sl.lookup(SERVICE_NAME)).andStubThrow(new ServiceLocatorException("test"));
    replayAll();
    lps.lookupEndpoints(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