Search in sources :

Example 1 with InternalRequestException

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;
}
Also used : InternalRequestException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalRequestException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CoapHandler(org.eclipse.californium.core.CoapHandler) Request(org.eclipse.californium.core.coap.Request) CoAPResponseAttributes(nl.teslanet.mule.connectors.coap.api.CoAPResponseAttributes) InternalInvalidOptionValueException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidOptionValueException)

Example 2 with InternalRequestException

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);
}
Also used : InternalClientErrorResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalClientErrorResponseException) InternalClientErrorResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalClientErrorResponseException) ClientErrorResponseException(nl.teslanet.mule.connectors.coap.api.error.ClientErrorResponseException) NoResponseException(nl.teslanet.mule.connectors.coap.api.error.NoResponseException) ResponseException(nl.teslanet.mule.connectors.coap.api.error.ResponseException) ServerErrorResponseException(nl.teslanet.mule.connectors.coap.api.error.ServerErrorResponseException) InternalNoResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalNoResponseException) InternalUnexpectedResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUnexpectedResponseException) InternalResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalResponseException) InternalServerErrorResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalServerErrorResponseException) InternalInvalidRequestCodeException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidRequestCodeException) InternalServerErrorResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalServerErrorResponseException) RequestException(nl.teslanet.mule.connectors.coap.api.error.RequestException) InternalRequestException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalRequestException) ServerErrorResponseException(nl.teslanet.mule.connectors.coap.api.error.ServerErrorResponseException) InternalServerErrorResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalServerErrorResponseException) DiscoveredResource(nl.teslanet.mule.connectors.coap.api.DiscoveredResource) InternalInvalidResponseCodeException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidResponseCodeException) InternalUnexpectedResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUnexpectedResponseException) TreeSet(java.util.TreeSet) UriException(nl.teslanet.mule.connectors.coap.api.error.UriException) InternalUriException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUriException) InternalRequestException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalRequestException) IOException(java.io.IOException) InternalResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalResponseException) InternalNoResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalNoResponseException) WebLink(org.eclipse.californium.core.WebLink) InternalEndpointException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalEndpointException) EndpointException(nl.teslanet.mule.connectors.coap.api.error.EndpointException) ConnectorException(org.eclipse.californium.elements.exception.ConnectorException) NoResponseException(nl.teslanet.mule.connectors.coap.api.error.NoResponseException) InternalNoResponseException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalNoResponseException) InternalUriException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalUriException) InternalInvalidRequestCodeException(nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidRequestCodeException) InvalidRequestCodeException(nl.teslanet.mule.connectors.coap.api.error.InvalidRequestCodeException) Throws(org.mule.runtime.extension.api.annotation.error.Throws)

Aggregations

InternalRequestException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalRequestException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 TreeSet (java.util.TreeSet)1 CoAPResponseAttributes (nl.teslanet.mule.connectors.coap.api.CoAPResponseAttributes)1 DiscoveredResource (nl.teslanet.mule.connectors.coap.api.DiscoveredResource)1 ClientErrorResponseException (nl.teslanet.mule.connectors.coap.api.error.ClientErrorResponseException)1 EndpointException (nl.teslanet.mule.connectors.coap.api.error.EndpointException)1 InvalidRequestCodeException (nl.teslanet.mule.connectors.coap.api.error.InvalidRequestCodeException)1 NoResponseException (nl.teslanet.mule.connectors.coap.api.error.NoResponseException)1 RequestException (nl.teslanet.mule.connectors.coap.api.error.RequestException)1 ResponseException (nl.teslanet.mule.connectors.coap.api.error.ResponseException)1 ServerErrorResponseException (nl.teslanet.mule.connectors.coap.api.error.ServerErrorResponseException)1 UriException (nl.teslanet.mule.connectors.coap.api.error.UriException)1 InternalClientErrorResponseException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalClientErrorResponseException)1 InternalEndpointException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalEndpointException)1 InternalInvalidOptionValueException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidOptionValueException)1 InternalInvalidRequestCodeException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidRequestCodeException)1 InternalInvalidResponseCodeException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidResponseCodeException)1