Search in sources :

Example 1 with EndpointReferenceList

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

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

the class LocatorRestServiceTest method lookUpEndpoints.

@Test
public void lookUpEndpoints() throws ServiceLocatorException, InterruptedException {
    names.clear();
    names.add(ENDPOINTURL);
    expect(sl.lookup(SERVICE_NAME)).andStubReturn(names);
    expect(sl.getEndpoint(SERVICE_NAME, ENDPOINTURL)).andStubReturn(endpoint);
    expect(endpoint.getProperties()).andStubReturn(SLPropertiesImpl.EMPTY_PROPERTIES);
    replayAll();
    W3CEndpointReference expectedRef;
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    // builder.serviceName(SERVICE_NAME);
    builder.address(ENDPOINTURL);
    expectedRef = builder.build();
    EndpointReferenceList erlt = lps.lookupEndpoints(SERVICE_NAME.toString(), new ArrayList<String>());
    if (erlt.getEndpointReference().get(0).equals(expectedRef))
        fail();
}
Also used : W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) EndpointReferenceList(org.talend.schemas.esb.locator.rest._2011._11.EndpointReferenceList) Test(org.junit.Test)

Example 3 with EndpointReferenceList

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

the class RESTClient method lookupEndpointsExample.

private void lookupEndpointsExample(LocatorService client, String service) throws IOException {
    System.out.println("------------------------------");
    System.out.println("LookupEndpoints");
    try {
        EndpointReferenceList endpointReferenceList = client.lookupEndpoints(URLEncoder.encode(service, "UTF-8"), null);
        if (endpointReferenceList.getEndpointReference().size() > 0) {
            for (W3CEndpointReference w3cEndpointReference : endpointReferenceList.getEndpointReference()) {
                System.out.println(w3cEndpointReference.toString());
            }
        }
    } catch (WebApplicationException ex) {
        System.out.println(ex.getMessage());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) EndpointReferenceList(org.talend.schemas.esb.locator.rest._2011._11.EndpointReferenceList)

Example 4 with EndpointReferenceList

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

the class RESTClient method lookupEndpointsExample.

private void lookupEndpointsExample(String service) throws UnsupportedEncodingException {
    System.out.println("------------------------------");
    System.out.println("LookupEndpoints for service ".concat(service));
    WebClient wc = WebClient.create(LOOKUP_ADDRESS.concat("/").concat(URLEncoder.encode(service, "UTF-8")));
    wc.accept(MediaType.APPLICATION_XML);
    try {
        EndpointReferenceList erlt = wc.get(EndpointReferenceList.class);
        System.out.println("Found ".concat(String.valueOf(erlt.getEndpointReference().size())).concat(" endpoints"));
        if (erlt.getEndpointReference().size() > 0) {
            for (W3CEndpointReference w3cEndpointReference : erlt.getEndpointReference()) {
                System.out.println(w3cEndpointReference.toString());
            }
        }
    } catch (WebApplicationException ex) {
        System.out.println(ex.getMessage());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) EndpointReferenceList(org.talend.schemas.esb.locator.rest._2011._11.EndpointReferenceList) WebClient(org.apache.cxf.jaxrs.client.WebClient)

Aggregations

EndpointReferenceList (org.talend.schemas.esb.locator.rest._2011._11.EndpointReferenceList)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 W3CEndpointReference (javax.xml.ws.wsaddressing.W3CEndpointReference)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 QName (javax.xml.namespace.QName)1 W3CEndpointReferenceBuilder (javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1 Test (org.junit.Test)1 Endpoint (org.talend.esb.servicelocator.client.Endpoint)1 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)1 SLPropertiesMatcher (org.talend.esb.servicelocator.client.SLPropertiesMatcher)1 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)1 SimpleEndpoint (org.talend.esb.servicelocator.client.SimpleEndpoint)1