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;
}
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();
}
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());
}
}
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());
}
}
Aggregations