use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUnexpectedResponseException in project mule-coap-connector by teslanet-nl.
the class Client method discover.
/**
* Discover resources of server
* @param confirmable when true the request is confirmable
* @param host hostname or ip of server to ping, when null client configuration is used
* @param port portnumber of server to ping, when null client configuration is used
* @param queryString
* @return The set containg the discovered resources.
* @throws InternalUriException When no valid uri could be constructed.
* @throws InternalUnexpectedResponseException When resonse does not contain link format payload.
* @throws ConnectorException
* @throws IOException
* @throws InternalNoResponseException When timeout has occurred.
* @throws InternalClientErrorResponseException When response indicates client error.
* @throws InternalInvalidResponseCodeException When response has invalid code.
* @throws InternalServerErrorResponseException When response indicates server error.
* @throws InternalResponseException When response indicates other error.
* @throws InternalRequestException When request parameters are invalid.
* @throws InternalInvalidRequestCodeException When request code is invalid.
*/
Set<WebLink> discover(DiscoverParams discoverParams) throws InternalUriException, InternalNoResponseException, InternalUnexpectedResponseException, ConnectorException, IOException, InternalClientErrorResponseException, InternalInvalidResponseCodeException, InternalServerErrorResponseException, InternalResponseException, InternalInvalidRequestCodeException, InternalRequestException {
Request request = new CoapRequestBuilderImpl(discoverParams).build();
CoapResponse response = coapClient.advanced(request);
throwExceptionWhenNeeded(response);
// check if Link Format
if (response.getOptions().getContentFormat() != MediaTypeRegistry.APPLICATION_LINK_FORMAT) {
throw new InternalUnexpectedResponseException("no link format received on discover request from { " + request.getURI() + " }");
}
// parse and return
return LinkFormat.parse(response.getResponseText());
}
use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUnexpectedResponseException in project mule-coap-connector by teslanet-nl.
the class ClientOperations method discover.
/**
* The Discover processor retrieves information about CoAP resources of a
* server.
*
* @param client The client to use to issue the request.
* @param discoverParams The attributes of the discover request
* @return The description of resources on the server that have been discovered.
*/
@Throws({ DiscoverErrorProvider.class })
public Set<DiscoveredResource> discover(@Config Client client, @ParameterGroup(name = "Discover address") DiscoverParams discoverParams) {
Set<WebLink> links = null;
try {
links = client.discover(discoverParams);
} catch (IOException | ConnectorException e) {
throw new EndpointException(client + discoverErrorMsg, e);
} catch (InternalUriException e) {
throw new UriException(client + discoverErrorMsg, e);
} catch (InternalUnexpectedResponseException | InternalInvalidResponseCodeException | InternalResponseException e) {
throw new ResponseException(client + discoverErrorMsg, e);
} catch (InternalNoResponseException e) {
throw new NoResponseException(client + discoverErrorMsg, e);
} catch (InternalClientErrorResponseException e) {
throw new ResponseException(client + discoverErrorMsg, e);
} catch (InternalServerErrorResponseException e) {
throw new ServerErrorResponseException(client + discoverErrorMsg, e);
} catch (InternalInvalidRequestCodeException e) {
throw new InvalidRequestCodeException(client + discoverErrorMsg, e);
} catch (InternalRequestException e) {
throw new RequestException(client + discoverErrorMsg, e);
}
TreeSet<DiscoveredResource> resultSet = new TreeSet<DiscoveredResource>();
for (WebLink link : links) {
resultSet.add(new DiscoveredResource(link.getURI(), link.getAttributes().hasObservable(), link.getAttributes().getTitle(), link.getAttributes().getInterfaceDescriptions(), link.getAttributes().getResourceTypes(), link.getAttributes().getMaximumSizeEstimate(), link.getAttributes().getContentTypes()));
}
return Collections.unmodifiableSortedSet(resultSet);
}
Aggregations