use of org.eclipse.californium.elements.UdpEndpointContextMatcher in project californium by eclipse.
the class EndpointContextMatcherFactory method create.
/**
* Create endpoint context matcher related to connector according the
* configuration.
*
* If connector supports "coaps:", RESPONSE_MATCHING is used to determine,
* if {@link StrictDtlsEndpointContextMatcher},
* {@link RelaxedDtlsEndpointContextMatcher}, or
* {@link PrincipalEndpointContextMatcher} is used.
*
* If connector supports "coap:", RESPONSE_MATCHING is used to determine, if
* {@link UdpEndpointContextMatcher} is used with disabled
* ({@link MatcherMode#RELAXED}) or enabled address check (otherwise).
*
* For other protocol flavors the corresponding matcher is used.
*
* @param connector connector to create related endpoint context matcher.
* @param config configuration.
* @return endpoint context matcher
* @since 3.0 (changed parameter to Configuration)
*/
public static EndpointContextMatcher create(Connector connector, Configuration config) {
String protocol = null;
if (null != connector) {
protocol = connector.getProtocol();
if (CoAP.PROTOCOL_TCP.equalsIgnoreCase(protocol)) {
return new TcpEndpointContextMatcher();
} else if (CoAP.PROTOCOL_TLS.equalsIgnoreCase(protocol)) {
return new TlsEndpointContextMatcher();
}
}
MatcherMode mode = config.get(CoapConfig.RESPONSE_MATCHING);
switch(mode) {
case RELAXED:
if (CoAP.PROTOCOL_UDP.equalsIgnoreCase(protocol)) {
return new UdpEndpointContextMatcher(false);
} else {
return new RelaxedDtlsEndpointContextMatcher();
}
case PRINCIPAL:
if (CoAP.PROTOCOL_UDP.equalsIgnoreCase(protocol)) {
return new UdpEndpointContextMatcher(true);
} else {
return new PrincipalEndpointContextMatcher();
}
case PRINCIPAL_IDENTITY:
if (CoAP.PROTOCOL_UDP.equalsIgnoreCase(protocol)) {
return new UdpEndpointContextMatcher(true);
} else {
return new PrincipalEndpointContextMatcher(true);
}
case STRICT:
default:
if (CoAP.PROTOCOL_UDP.equalsIgnoreCase(protocol)) {
return new UdpEndpointContextMatcher(true);
} else {
return new StrictDtlsEndpointContextMatcher();
}
}
}
use of org.eclipse.californium.elements.UdpEndpointContextMatcher in project californium by eclipse.
the class ClientSynchronousTest method testSynchronousPingWithPrincipalIdentity.
@Test
public void testSynchronousPingWithPrincipalIdentity() throws Exception {
final AtomicBoolean sent = new AtomicBoolean();
CoapEndpoint.Builder builder = new CoapEndpoint.Builder();
builder.setEndpointContextMatcher(new UdpEndpointContextMatcher(true) {
final AtomicBoolean first = new AtomicBoolean();
@Override
public Object getEndpointIdentity(EndpointContext context) {
if (first.compareAndSet(false, true)) {
// emulates first access, when no principal is available
throw new IllegalArgumentException("first access during test");
}
return "TEST";
}
});
builder.setInetSocketAddress(TestTools.LOCALHOST_EPHEMERAL);
CoapEndpoint clientEndpoint = builder.build();
cleanup.add(clientEndpoint);
clientEndpoint.addInterceptor(new MessageInterceptorAdapter() {
@Override
public void sendRequest(Request request) {
sent.set(true);
}
});
String uri = TestTools.getUri(serverEndpoint, TARGET);
CoapClient client = new CoapClient(uri).useExecutor();
cleanup.add(client);
client.setEndpoint(clientEndpoint);
// Check that we get the right content when calling get()
boolean ping = client.ping();
assertTrue(ping);
assertTrue("Ping not sent using provided endpoint", sent.get());
client.shutdown();
}
use of org.eclipse.californium.elements.UdpEndpointContextMatcher in project californium by eclipse.
the class CoapStackTest method parameters.
@Parameterized.Parameters
public static List<Object[]> parameters() {
Outbox udpOutbox = mock(Outbox.class);
Outbox tcpOutbox = mock(Outbox.class);
SystemConfig.register();
TcpConfig.register();
CoapConfig.register();
Configuration config = Configuration.createStandardWithoutFile();
List<Object[]> parameters = new ArrayList<>();
parameters.add(new Object[] { new CoapTcpStack("tcp-test ", config, new TcpEndpointContextMatcher(), tcpOutbox), tcpOutbox });
parameters.add(new Object[] { new CoapUdpStack("udp-test ", config, new UdpEndpointContextMatcher(true), udpOutbox), udpOutbox });
return parameters;
}
Aggregations