/** * Configures a new default secure endpoint. Any old default endpoint is destroyed. * @param endpoint the new default endpoint */ public void setDefaultSecureEndpoint(Endpoint endpoint) { if (this.default_secure_endpoint!=null) { this.default_secure_endpoint.destroy(); } this.default_secure_endpoint = endpoint; if (!this.default_secure_endpoint.isStarted()) { try { default_secure_endpoint.start(); LOGGER.log(Level.INFO, "Started new default secure endpoint " + default_secure_endpoint.getAddress()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not start new default secure endpoint", e); } } }
/** * Sends the request over the specified endpoint to its destination and * expects a response back. * * @param endpoint the endpoint * @return this request */ public Request send(Endpoint endpoint) { validateBeforeSending(); endpoint.sendRequest(this); return this; }
@Before public void setupEndpoints() throws Exception { client = new CoapEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), config); client.addInterceptor(clientInterceptor); client.start(); System.out.println("Client binds to port " + client.getAddress().getPort()); server = createLockstepEndpoint(client.getAddress()); }
/** * Sets the endpoint this client is supposed to use. * * @param endpoint the endpoint * @return the CoAP client */ public CoapClient setEndpoint(Endpoint endpoint) { this.endpoint = endpoint; if (!endpoint.isStarted()) { try { endpoint.start(); LOGGER.log(Level.INFO, "Started set client endpoint {0}", endpoint.getAddress()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not set and start client endpoint", e); } } return this; }
private synchronized void createDefaultEndpoint() { if (default_endpoint != null) return; default_endpoint = new CoapEndpoint(); try { default_endpoint.start(); LOGGER.log(Level.INFO, "Created implicit default endpoint " + default_endpoint.getAddress()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not create default endpoint", e); } }
@Override protected final int getActualPort() { int port = Constants.PORT_UNCONFIGURED; final Endpoint endpoint = secureEndpoint; if (endpoint != null) { port = endpoint.getAddress().getPort(); } return port; }
@Before public void setupEndpoints() throws Exception { testResource = new TestResource("test"); exchangeStore = new InMemoryMessageExchangeStore(CONFIG); // bind to loopback address using an ephemeral port CoapEndpoint udpEndpoint = new CoapEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), CONFIG, exchangeStore); server = new CoapServer(); server.addEndpoint(udpEndpoint); server.add(testResource); server.getEndpoints().get(0).addInterceptor(serverInterceptor); server.start(); InetSocketAddress serverAddress = server.getEndpoints().get(0).getAddress(); System.out.println("Server binds to port " + serverAddress.getPort()); client = createLockstepEndpoint(serverAddress); }
ep.addInterceptor(new MessageTracer()); ep.addInterceptor(new OriginTracer());
/** * Reset default endpoints. Destroy all default endpoints. */ public static void reset() { EndpointManager it = getEndpointManager(); if (it.default_endpoint != null) { it.default_endpoint.destroy(); it.default_endpoint = null; } if (it.default_secure_endpoint != null) { it.default_secure_endpoint.destroy(); it.default_secure_endpoint = null; } }
@Before public void createClient() throws IOException { clientEndpoint = new CoapEndpoint(config); clientEndpoint.start(); }
private void cancel(Observation observation) { Token token = new Token(observation.getId()); if (secureEndpoint != null) secureEndpoint.cancelObservation(token); if (nonSecureEndpoint != null) nonSecureEndpoint.cancelObservation(token); for (ObservationListener listener : listeners) { listener.cancelled(observation); } }
@Override protected final int getActualInsecurePort() { int port = Constants.PORT_UNCONFIGURED; final Endpoint endpoint = insecureEndpoint; if (endpoint != null) { port = endpoint.getAddress().getPort(); } return port; }
private synchronized void createDefaultEndpoint() { if (default_endpoint != null) return; default_endpoint = new CoapEndpoint(); try { default_endpoint.start(); LOGGER.log(Level.INFO, "Created implicit default endpoint {0}", default_endpoint.getAddress()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not create default endpoint", e); } }
@BeforeClass public static void start() { System.out.println(System.lineSeparator() + "Start " + ObserveServerSideTest.class.getSimpleName()); Logger ul = Logger.getLogger(UDPConnector.class.getName()); ul.setLevel(Level.OFF); CONFIG = network.createTestConfig() .setInt(NetworkConfig.Keys.ACK_TIMEOUT, ACK_TIMEOUT) .setFloat(NetworkConfig.Keys.ACK_RANDOM_FACTOR, 1f) .setFloat(NetworkConfig.Keys.ACK_TIMEOUT_SCALE, 1f) .setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 32) .setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 32); testObsResource = new TestObserveResource(RESOURCE_PATH); server = new CoapServer(); server.addEndpoint(new CoapEndpoint(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), CONFIG)); server.add(testObsResource); server.getEndpoints().get(0).addInterceptor(serverInterceptor); server.start(); serverAddress = server.getEndpoints().get(0).getAddress(); System.out.println("Server binds to port " + serverAddress.getPort()); }
/** * Sets the endpoint this client is supposed to use. * * @param endpoint the endpoint * @return the CoAP client */ public CoapClient setEndpoint(Endpoint endpoint) { this.endpoint = endpoint; if (!endpoint.isStarted()) { try { endpoint.start(); LOGGER.log(Level.INFO, "Started set client endpoint " + endpoint.getAddress()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not set and start client endpoint", e); } } return this; }
EndpointManager.getEndpointManager().getDefaultEndpoint().addInterceptor(new MessageTracer());
/** * Reset default endpoints. Destroy all default endpoints and clear their * set. */ public static void reset() { EndpointManager it = getEndpointManager(); if (it.default_endpoint != null) { it.default_endpoint.destroy(); it.default_endpoint = null; } if (it.default_secure_endpoint != null) { it.default_secure_endpoint.destroy(); it.default_secure_endpoint = null; } if (it.default_tcp_endpoint != null) { it.default_tcp_endpoint.destroy(); it.default_tcp_endpoint = null; } if (it.default_secure_tpc_endpoint != null) { it.default_secure_tpc_endpoint.destroy(); it.default_secure_tpc_endpoint = null; } }
dtlsEndpoint.start(); EndpointManager.getEndpointManager().setDefaultSecureEndpoint(dtlsEndpoint);
/** * Sends this request over the specified endpoint to its destination and * expects a response back. * * @param endpoint the endpoint * @return this request * @throws NullPointerException if this request has no destination set. */ public Request send(Endpoint endpoint) { validateBeforeSending(); endpoint.sendRequest(this); return this; }
/** * Configures a new default endpoint. Any old default endpoint is destroyed. * @param endpoint the new default endpoint */ public void setDefaultEndpoint(Endpoint endpoint) { if (this.default_endpoint!=null) { this.default_endpoint.destroy(); } LOGGER.config(endpoint.getAddress()+" becomes default endpoint"); this.default_endpoint = endpoint; if (!this.default_endpoint.isStarted()) { try { default_endpoint.start(); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Could not start new default endpoint", e); } } }