use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalResourceUriException in project mule-coap-connector by teslanet-nl.
the class Listener method onStart.
@Override
public void onStart(SourceCallback<InputStream, CoAPRequestAttributes> sourceCallback) throws MuleException {
try {
operationalListener = new OperationalListener(pathPattern, new RequestCodeFlags(get, post, put, delete), sourceCallback);
server.addListener(operationalListener);
} catch (InternalResourceUriException | InternalUriPatternException e) {
new DefaultMuleException(this + " start failed.", e);
}
logger.info(this + " started.");
}
use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalResourceUriException in project mule-coap-connector by teslanet-nl.
the class OperationalListener method setUriPattern.
/**
* Set the uri pattern of the resources the listener should process requests
* for.
*
* @param uriPattern the uri pattern to set
* @throws InternalResourceUriException when the uri pattern is not valid
*/
// TODO: make URIpattern class
public void setUriPattern(String uriPattern) throws InternalResourceUriException {
// TODO assure no bad chars
if (uriPattern == null)
throw new InternalResourceUriException("null value is not allowed.");
this.uriPattern = uriPattern.trim();
if (!this.uriPattern.startsWith(Defs.COAP_URI_PATHSEP)) {
this.uriPattern = Defs.COAP_URI_PATHSEP + this.uriPattern;
}
int wildcardIndex = this.uriPattern.indexOf(Defs.COAP_URI_WILDCARD);
if (wildcardIndex >= 0 && wildcardIndex < this.uriPattern.length() - 1)
throw new InternalResourceUriException("invalid uriPattern { " + uriPattern + " }, wildcard needs to be last character.");
if (this.uriPattern.length() < 2)
throw new InternalResourceUriException("invalid uriPattern { " + uriPattern + " }, uri cannot be empty.");
}
use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalResourceUriException in project mule-coap-connector by teslanet-nl.
the class ResourceRegistryTest method testGetResourceNonexistent.
@Test
public void testGetResourceNonexistent() throws InternalResourceUriException, InternalResourceRegistryException {
CoapResource root = new CoapResource("");
ResourceRegistry registry = new ResourceRegistry("test_server", root);
ResourceConfig resourceConfig;
String name1 = "resource1";
String uri1 = "/resource1";
String name2 = "resource2";
String uri2 = "/resource1/resource2";
String name3 = "resource3";
String uri4 = "/resource1/resource4";
resourceConfig = new ResourceConfig();
resourceConfig.setResourceName(name1);
registry.add(null, resourceConfig);
resourceConfig = new ResourceConfig();
resourceConfig.setResourceName(name2);
registry.add(uri1, resourceConfig);
resourceConfig = new ResourceConfig();
resourceConfig.setResourceName(name3);
registry.add(uri2, resourceConfig);
InternalResourceUriException e = assertThrows(InternalResourceUriException.class, () -> {
registry.getResource(uri4).getURI();
});
assertTrue("exception has wrong message", e.getMessage().contains(uri4));
assertTrue("exception has wrong message", e.getMessage().contains("does not exist"));
}
use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalResourceUriException in project mule-coap-connector by teslanet-nl.
the class OperationalListenerTest method testConstructorWithInvalidUriEmpty1.
@Test
public void testConstructorWithInvalidUriEmpty1() throws InternalResourceUriException {
TestSourceCallBack callback = new TestSourceCallBack();
String uri = "";
RequestCodeFlags flags = new RequestCodeFlags(true, true, true, false);
InternalResourceUriException e = assertThrows(InternalResourceUriException.class, () -> {
@SuppressWarnings("unused") OperationalListener listener = new OperationalListener(uri, new RequestCodeFlags(flags), callback);
});
assertEquals("exception has wrong message", "invalid uriPattern { }, uri cannot be empty.", e.getMessage());
}
use of nl.teslanet.mule.connectors.coap.internal.exceptions.InternalResourceUriException in project mule-coap-connector by teslanet-nl.
the class OperationalListenerTest method testConstructorWithInvalidUriMultipleWildcard4.
@Test
public void testConstructorWithInvalidUriMultipleWildcard4() throws InternalResourceUriException {
TestSourceCallBack callback = new TestSourceCallBack();
String uri = "/some_resource/*/child/*";
RequestCodeFlags flags = new RequestCodeFlags(true, true, true, false);
InternalResourceUriException e = assertThrows(InternalResourceUriException.class, () -> {
new OperationalListener(uri, new RequestCodeFlags(flags), callback);
});
assertEquals("exception has wrong message", "invalid uriPattern { /some_resource/*/child/* }, wildcard needs to be last character.", e.getMessage());
}
Aggregations