Search in sources :

Example 1 with SLPropertiesImpl

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

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

the class LocatorRestServiceTest method lookUpEndpointWithReturnProps.

@Test
public void lookUpEndpointWithReturnProps() throws ServiceLocatorException, InterruptedException {
    names.clear();
    names.add(ENDPOINTURL);
    SLPropertiesImpl slPropertiesImpl = new SLPropertiesImpl();
    List<String> list = new ArrayList<String>();
    slPropertiesImpl.addProperty("test", list);
    expect(sl.lookup(SERVICE_NAME)).andStubReturn(names);
    expect(sl.getEndpoint(SERVICE_NAME, ENDPOINTURL)).andStubReturn(endpoint);
    expect(endpoint.getProperties()).andStubReturn(slPropertiesImpl);
    replayAll();
    W3CEndpointReference endpointRef, expectedRef;
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    // builder.serviceName(SERVICE_NAME);
    builder.address(ENDPOINTURL);
    EndpointTransformerImpl transformer = new EndpointTransformerImpl();
    DOMResult result = new DOMResult();
    transformer.writePropertiesTo(slPropertiesImpl, result);
    Document docResult = (Document) result.getNode();
    builder.metadata(docResult.getDocumentElement());
    expectedRef = builder.build();
    endpointRef = lps.lookupEndpoint(SERVICE_NAME.toString(), new ArrayList<String>());
    assertTrue(endpointRef.toString().equals(expectedRef.toString()));
}
Also used : W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) EndpointTransformerImpl(org.talend.esb.servicelocator.client.internal.EndpointTransformerImpl) DOMResult(javax.xml.transform.dom.DOMResult) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) ArrayList(java.util.ArrayList) SLPropertiesImpl(org.talend.esb.servicelocator.client.SLPropertiesImpl) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 3 with SLPropertiesImpl

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

the class SLPropertiesConverterTest method slProperties2JAXBSlPropertiesType.

@Test
public void slProperties2JAXBSlPropertiesType() throws Exception {
    SLPropertiesImpl props = new SLPropertiesImpl();
    props.addProperty(KEY_1, VALUE_1, VALUE_2);
    props.addProperty(KEY_2, VALUE_2, VALUE_3);
    ServiceLocatorPropertiesType jaxbProperties = SLPropertiesConverter.toServiceLocatorPropertiesType(props);
    List<EntryType> entries = jaxbProperties.getEntry();
    List<String> values = entries.get(0).getValue();
    assertEquals(VALUE_1, values.get(0));
}
Also used : EntryType(org.talend.esb.servicelocator.client.internal.endpoint.EntryType) ServiceLocatorPropertiesType(org.talend.esb.servicelocator.client.internal.endpoint.ServiceLocatorPropertiesType) SLPropertiesImpl(org.talend.esb.servicelocator.client.SLPropertiesImpl) Test(org.junit.Test)

Example 4 with SLPropertiesImpl

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

the class LocatorSoapServiceImpl method registerEndpoint.

/**
 * Register the endpoint for given service.
 *
 * @param input
 *            RegisterEndpointRequestType encapsulate name of service and
 *            endpointURL. Must not be <code>null</code>
 */
@Override
public void registerEndpoint(QName serviceName, String endpointURL, org.talend.schemas.esb.locator._2011._11.BindingType binding, org.talend.schemas.esb.locator._2011._11.TransportType transport, SLPropertiesType properties) throws ServiceLocatorFault, InterruptedExceptionFault {
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Registering endpoint " + endpointURL + " for service " + serviceName + "...");
    }
    try {
        initLocator();
        BindingType bindingType = binding == null ? BindingType.SOAP11 : BindingType.valueOf(binding.value());
        TransportType transportType = transport == null ? TransportType.HTTP : TransportType.valueOf(transport.value());
        SLPropertiesImpl slProps = null;
        if (properties != null) {
            slProps = new SLPropertiesImpl();
            List<EntryType> entries = properties.getEntry();
            for (EntryType entry : entries) {
                slProps.addProperty(entry.getKey(), entry.getValue());
            }
        }
        SimpleEndpoint eprProvider = new SimpleEndpoint(serviceName, endpointURL, bindingType, transportType, slProps);
        locatorClient.register(eprProvider, true);
    } 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);
    }
}
Also used : EntryType(org.talend.schemas.esb.locator._2011._11.EntryType) SimpleEndpoint(org.talend.esb.servicelocator.client.SimpleEndpoint) InterruptionFaultDetail(org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail) 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) 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 5 with SLPropertiesImpl

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

the class LocatorSoapServiceTest method lookUpEndpointWithReturnProps.

@Test
public void lookUpEndpointWithReturnProps() throws InterruptedExceptionFault, ServiceLocatorFault, ServiceLocatorException, InterruptedException {
    names.clear();
    names.add(ENDPOINTURL);
    SLPropertiesImpl slPropertiesImpl = new SLPropertiesImpl();
    List<String> list = new ArrayList<String>();
    slPropertiesImpl.addProperty("test", list);
    expect(sl.lookup(SERVICE_NAME)).andStubReturn(names);
    expect(sl.getEndpoint(SERVICE_NAME, ENDPOINTURL)).andStubReturn(endpoint);
    expect(endpoint.getProperties()).andStubReturn(slPropertiesImpl);
    replayAll();
    W3CEndpointReference endpointRef, expectedRef;
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    // builder.serviceName(SERVICE_NAME);
    builder.address(ENDPOINTURL);
    EndpointTransformerImpl transformer = new EndpointTransformerImpl();
    DOMResult result = new DOMResult();
    transformer.writePropertiesTo(slPropertiesImpl, result);
    Document docResult = (Document) result.getNode();
    builder.metadata(docResult.getDocumentElement());
    expectedRef = builder.build();
    endpointRef = lps.lookupEndpoint(SERVICE_NAME, null);
    assertTrue(endpointRef.toString().equals(expectedRef.toString()));
}
Also used : W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) EndpointTransformerImpl(org.talend.esb.servicelocator.client.internal.EndpointTransformerImpl) DOMResult(javax.xml.transform.dom.DOMResult) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) ArrayList(java.util.ArrayList) SLPropertiesImpl(org.talend.esb.servicelocator.client.SLPropertiesImpl) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

SLPropertiesImpl (org.talend.esb.servicelocator.client.SLPropertiesImpl)6 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 DOMResult (javax.xml.transform.dom.DOMResult)2 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)2 W3CEndpointReferenceBuilder (javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)2 BindingType (org.talend.esb.servicelocator.client.BindingType)2 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)2 SimpleEndpoint (org.talend.esb.servicelocator.client.SimpleEndpoint)2 TransportType (org.talend.esb.servicelocator.client.TransportType)2 EndpointTransformerImpl (org.talend.esb.servicelocator.client.internal.EndpointTransformerImpl)2 EntryType (org.talend.esb.servicelocator.client.internal.endpoint.EntryType)2 Document (org.w3c.dom.Document)2 WebApplicationException (javax.ws.rs.WebApplicationException)1 QName (javax.xml.namespace.QName)1 Endpoint (org.talend.esb.servicelocator.client.Endpoint)1 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)1 ServiceLocatorPropertiesType (org.talend.esb.servicelocator.client.internal.endpoint.ServiceLocatorPropertiesType)1 EntryType (org.talend.schemas.esb.locator._2011._11.EntryType)1 InterruptionFaultDetail (org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail)1