# CoAP Proxy Server

CoAP Proxy Server is Kony implementation of CoAP protocol. It allows CoAP clients to request to perform an HTTP request on their behalf.
The proxy then composes an HTTP request with the given URI and sends it to the appropriate HTTP server. 
The server then returns the HTTP response to the proxy, which the proxy returns to the CoAP client via a CoAP response.

This server is implemented in Java and runs on 1.6 or higher versions. It is based on popular Californium framework which is customized for Kony.

# Configuration
- The file conf/server.properties contains all the launch parameters(-D parameters) to be supplied to the CoAP Proxy server. 
  The start-up script reads all these parameters and supplies them as -D parameters.
  When launching the program directly without using the script, all these parameters have to be supplied manually.
  
  Update the values for all these properties as needed.
  
- Open config.properties in /conf and update the HTTP header name and value. 
  This is the header to be added for every HTTP request initiated by CoAP Proxy Server.
  Also update the URI strip parameter value. This parameter is used strip off any text from the CoAP URI and construct the HTTP URI.
  
# Starting the Server
  Launch startServer.sh/startServer.bat available in /scripts directory.

# Stopping the server
  Launch stopServer.sh/stopServer.bat available in /scripts directory. 
 
# Testing
  Test by initiating a CoAP request from Firefox Copper plugin(https://addons.mozilla.org/en-US/firefox/addon/copper-270430/).
  or by writing CoAP client program(Refer https://github.com/eclipse/californium.core/tree/master/cf-helloworld-client/src/main/java/org/eclipse/californium/examples).
  
  Note: Clients have to set the uri-host option in the CoAP request always and use the early negotiation i.e block wise transfer. 
  		Example code snippet below.
  			URI uri = new URI("coap://localhost:5683/authService/100000002/login");
            CoapClient client = new CoapClient(uri);
            client.setTimeout(timeout);
            client.useEarlyNegotiation(512);
            Request req = Request.newPost();
            req.setPayload("sample payload");
            req.getOptions().setUriHost("localhost");
            CoapResponse response = client.advanced(req);
  
