use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalRequestException in project mule-coap-connector by teslanet-nl.
the class Client method doRequest.
// TODO add custom timeout
/**
* Issue a request on a CoAP resource residing on a server.
* @param builder Builder containing request parameters.
* @param options The request options.
* @param handlerBuilder Builder containing the name of the handle when the response is handled asynchronously
* @return The result of the request including payload and attributes.
* @throws InternalInvalidHandlerNameException When the handlerName is not null but does not reference an existing handler.
* @throws InternalRequestException When the Request could not be issued.
* @throws InternalResponseException When the received response appears to be invalid and cannot be processed.
* @throws InternalEndpointException When CoAP communication failed.
* @throws InternalInvalidRequestCodeException When the request code has invalid value.
* @throws InternalNoResponseException When timeout has occurred.
* @throws InternalClientErrorResponseException When response indicates client error.
* @throws InternalInvalidResponseCodeException When response indicates other error.
* @throws InternalServerErrorResponseException When response indicates server error.
* @throws InternalUriException When given request uri parameters are invalid.
*/
Result<InputStream, CoAPResponseAttributes> doRequest(RequestParams builder, RequestOptions options, ResponseHandlerParams handlerBuilder) throws InternalInvalidHandlerNameException, InternalRequestException, InternalResponseException, InternalEndpointException, InternalInvalidRequestCodeException, InternalNoResponseException, InternalClientErrorResponseException, InternalInvalidResponseCodeException, InternalServerErrorResponseException, InternalUriException {
Result<InputStream, CoAPResponseAttributes> result = null;
CoapHandler handler = null;
Request request = new CoapRequestBuilderImpl(builder).build();
try {
MessageUtils.copyOptions(options, request.getOptions(), transformationService);
} catch (InternalInvalidOptionValueException e) {
throw new InternalRequestException("cannot process request options", e);
}
if (handlerBuilder != null) {
// asynchronous request
SourceCallback<InputStream, CoAPResponseAttributes> callback;
callback = getHandler(handlerBuilder.getResponseHandler());
handler = createCoapHandler(handlerBuilder.getResponseHandler(), request.getURI(), builder.getRequestCode(), callback);
coapClient.advanced(handler, request);
// nothing to return
} else {
// send out synchronous request
result = executeSynchronous(builder.getRequestCode(), request);
}
return result;
}
use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalRequestException 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