Search in sources :

Example 1 with RegisterEndpointRequest

use of org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest 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 2 with RegisterEndpointRequest

use of org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest in project tesb-rt-se by Talend.

the class LocatorRestServiceTest method registerEndpointWithProps.

@Test
public void registerEndpointWithProps() throws ServiceLocatorException, InterruptedException {
    sl.register(endpoint(), EasyMock.eq(true));
    EasyMock.expectLastCall();
    replayAll();
    RegisterEndpointRequest req = new RegisterEndpointRequest();
    EntryType entryType = new EntryType();
    entryType.setKey("test");
    entryType.getValue().add("test");
    req.getEntryType().add(entryType);
    req.setEndpointURL(ENDPOINTURL);
    req.setServiceName(SERVICE_NAME.toString());
    lps.registerEndpoint(req);
}
Also used : RegisterEndpointRequest(org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest) EntryType(org.talend.schemas.esb.locator.rest._2011._11.EntryType) Test(org.junit.Test)

Example 3 with RegisterEndpointRequest

use of org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest in project tesb-rt-se by Talend.

the class LocatorRestServiceTest method registerEndpointExpectedInterruptedException.

@Test(expected = WebApplicationException.class)
public void registerEndpointExpectedInterruptedException() throws ServiceLocatorException, InterruptedException {
    sl.register(endpoint(), EasyMock.eq(true));
    EasyMock.expectLastCall().andStubThrow(new InterruptedException("test"));
    replayAll();
    RegisterEndpointRequest req = new RegisterEndpointRequest();
    EntryType entryType = new EntryType();
    entryType.setKey("test");
    entryType.getValue().add("test");
    req.getEntryType().add(entryType);
    req.setEndpointURL(ENDPOINTURL);
    req.setServiceName(SERVICE_NAME.toString());
    lps.registerEndpoint(req);
}
Also used : RegisterEndpointRequest(org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest) EntryType(org.talend.schemas.esb.locator.rest._2011._11.EntryType) Test(org.junit.Test)

Example 4 with RegisterEndpointRequest

use of org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest in project tesb-rt-se by Talend.

the class RESTClient method registerEndpointExample.

private void registerEndpointExample(String service, String endpoint, String key, String value) {
    System.out.println("------------------------------");
    System.out.println("Register service endpoint");
    System.out.println("ServiceName: ".concat(service));
    System.out.println("EndpointURL: ".concat(endpoint));
    System.out.println("Property: " + key + "=" + value);
    WebClient wc = WebClient.create(BASE_ADDRESS);
    EntryType et = new EntryType();
    et.setKey(key);
    et.getValue().add(value);
    RegisterEndpointRequest registerEndpointRequest = new RegisterEndpointRequest();
    registerEndpointRequest.setEndpointURL(endpoint);
    registerEndpointRequest.setBinding(BindingType.JAXRS);
    registerEndpointRequest.setTransport(TransportType.HTTPS);
    registerEndpointRequest.setServiceName(service);
    registerEndpointRequest.getEntryType().add(et);
    try {
        wc.post(registerEndpointRequest);
        System.out.println("Endpoint registered successfully");
    } catch (WebApplicationException ex) {
        System.err.println(ex.getMessage());
    }
}
Also used : RegisterEndpointRequest(org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest) EntryType(org.talend.schemas.esb.locator.rest._2011._11.EntryType) WebApplicationException(javax.ws.rs.WebApplicationException) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 5 with RegisterEndpointRequest

use of org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest in project tesb-rt-se by Talend.

the class LocatorRestServiceTest method registerEndpoint.

@Test
public void registerEndpoint() throws ServiceLocatorException, InterruptedException {
    sl.register(endpoint(), EasyMock.eq(true));
    EasyMock.expectLastCall();
    replayAll();
    RegisterEndpointRequest req = new RegisterEndpointRequest();
    req.setEndpointURL(ENDPOINTURL);
    req.setServiceName(SERVICE_NAME.toString());
    lps.registerEndpoint(req);
}
Also used : RegisterEndpointRequest(org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest) Test(org.junit.Test)

Aggregations

RegisterEndpointRequest (org.talend.schemas.esb.locator.rest._2011._11.RegisterEndpointRequest)7 Test (org.junit.Test)5 EntryType (org.talend.schemas.esb.locator.rest._2011._11.EntryType)5 WebApplicationException (javax.ws.rs.WebApplicationException)3 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)2 QName (javax.xml.namespace.QName)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 BindingType (org.talend.esb.servicelocator.client.BindingType)1 Endpoint (org.talend.esb.servicelocator.client.Endpoint)1 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)1 SLPropertiesImpl (org.talend.esb.servicelocator.client.SLPropertiesImpl)1 SimpleEndpoint (org.talend.esb.servicelocator.client.SimpleEndpoint)1 TransportType (org.talend.esb.servicelocator.client.TransportType)1