<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Creating a REST API in Software Defined Networking</title>
    <link>https://community.hpe.com/t5/software-defined-networking/creating-a-rest-api/m-p/6764776#M1757</link>
    <description>&lt;P&gt;I've been trying to create a REST API to adjust some values during runtime of my app and I can't seem to get it to work with the interface provided on https://&amp;lt;CONTROLLER_ADDRESS&amp;gt;:8443/api/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The REST API contains of two requests: a GET request to get the current values and a PUT request to set them.&lt;/P&gt;&lt;P&gt;The code compiles fine, I get a SocketTimeOutException or a NullPointer when I activate it and restart the controller.&lt;/P&gt;&lt;P&gt;I'm pretty sure I followed everything the documentation states.&lt;/P&gt;&lt;P&gt;I added a Class to "*-rs/src/main/java/com.*.*.rs" called "MetricResource.java":&lt;/P&gt;&lt;PRE&gt;@Path("metrics")
public class MetricResource extends ControllerResource {
    /**
     * Changes the metrics.
     * &amp;lt;p&amp;gt;
     * Normal Response Code(s): ok (200)
     * &amp;lt;p&amp;gt;
     * Error Response Codes: badRequest (400), unauthorized (401), forbidden (403), 
     * badMethod (405), serviceUnavailable (503)
     * 
     * @param request JSON representation of the metrics
     * @return JSON object
     */
    @PUT
    @Produces(MediaType.APPLICATION_JSON)
    public Response changeMetrics(String request) {
        MetricService svc = get(MetricService.class);
        // (...)  

        // Encode response
        return ok(r.toString()).build();
    }

    /**
     * Gets the metrics.
     * &amp;lt;p&amp;gt;
     * Normal Response Code(s): ok (200)
     * &amp;lt;p&amp;gt;
     * Error Response Codes: badRequest (400), unauthorized (401), forbidden (403), 
     * badMethod (405), serviceUnavailable (503), itemNotFound (404)
     *
     * @return JSON object
     */
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getMetrics() {
        MetricService svc = get(MetricService.class);
        // (...)
        return ok(r.toString()).build();
    }
}&lt;/PRE&gt;&lt;P&gt;I pretty much copied the DocProvider from the example:&lt;/P&gt;&lt;PRE&gt;@Component
public class DocProvider extends SelfRegisteringRSDocProvider {
    
    public DocProvider() {
        super("metrics", "rsdoc", DocProvider.class.getClassLoader());
    }

}&lt;/PRE&gt;&lt;P&gt;Same for the ServiceAssistant:&lt;/P&gt;&lt;PRE&gt;@Component(immediate=true, specVersion="1.1")
@References(value={
    @Reference(name="MetricService",
               referenceInterface=com.hp.mdd.api.MetricService.class,
               policy=ReferencePolicy.DYNAMIC, 
               cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE)
    })
public class ServiceAssistant {
    
    private ServiceLocator sl = ServiceLocator.INSTANCE;

    /**
     * Hook for registering MetricService implementation via declarative services.
     *
     * @param s newly advertised service to register
     * @param properties the properties associated with the service
     */
    protected void bindMetricService(com.hp.mdd.api.MetricService s, Map&amp;lt;String, Object&amp;gt; properties) {
        sl.register(com.hp.mdd.api.MetricService.class, s, properties);
    }
    
    /**
     * Hook for unregistering deactivated SystemInformationService via declarative services.
     *
     * @param s deactivated service to unregister
     */
    protected void unbindMetricService(com.hp.mdd.api.MetricService s) {
        sl.unregister(com.hp.mdd.api.MetricService.class, s);
    }

}&lt;/PRE&gt;&lt;P&gt;I tried to adjust the model.json, even though the documentation was pretty scarce on that:&lt;/P&gt;&lt;PRE&gt;{
    "${restPath}":
    {
        "metric": {
            "port": {"type": "long"},
            "packetthresh": {"type": "long"},
            "timewindow": {"type": "long"},
            "bytethresh": {"type": "long"},
            "packetwindow": {"type": "long"},
            "idletimeout": {"type": "int"}
        }
    }
}&lt;/PRE&gt;&lt;P&gt;And added my Resource to the param-values:&lt;/P&gt;&lt;PRE&gt;&amp;lt;param-value&amp;gt;
                com.hp.mdd.rs.MetricResource

                com.hp.sdn.rs.misc.DuplicateIdErrorHandler
                com.hp.sdn.rs.misc.NotFoundErrorHandler
                com.hp.sdn.rs.misc.ServiceNotFoundErrorHandler
                com.hp.sdn.rs.misc.IllegalDataHandler
                com.hp.sdn.rs.misc.IllegalStateHandler
                com.hp.sdn.rs.misc.AuthenticationHandler
         &amp;lt;/param-value&amp;gt;&lt;/PRE&gt;&lt;P&gt;When I activate the app normally and go to the REST API it just "fetching resource list: https://&amp;lt;controller_ip&amp;gt;&lt;SPAN&gt;:8443/api/rsdoc/metrics/1.0/resources.json" forever.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When I restart then I get the exceptions and I can't use the REST API anymore from the web interface (/in browser).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The API/Model part are pretty much working and simplistic.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jul 2015 16:18:07 GMT</pubDate>
    <dc:creator>franzj</dc:creator>
    <dc:date>2015-07-14T16:18:07Z</dc:date>
    <item>
      <title>Creating a REST API</title>
      <link>https://community.hpe.com/t5/software-defined-networking/creating-a-rest-api/m-p/6764776#M1757</link>
      <description>&lt;P&gt;I've been trying to create a REST API to adjust some values during runtime of my app and I can't seem to get it to work with the interface provided on https://&amp;lt;CONTROLLER_ADDRESS&amp;gt;:8443/api/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The REST API contains of two requests: a GET request to get the current values and a PUT request to set them.&lt;/P&gt;&lt;P&gt;The code compiles fine, I get a SocketTimeOutException or a NullPointer when I activate it and restart the controller.&lt;/P&gt;&lt;P&gt;I'm pretty sure I followed everything the documentation states.&lt;/P&gt;&lt;P&gt;I added a Class to "*-rs/src/main/java/com.*.*.rs" called "MetricResource.java":&lt;/P&gt;&lt;PRE&gt;@Path("metrics")
public class MetricResource extends ControllerResource {
    /**
     * Changes the metrics.
     * &amp;lt;p&amp;gt;
     * Normal Response Code(s): ok (200)
     * &amp;lt;p&amp;gt;
     * Error Response Codes: badRequest (400), unauthorized (401), forbidden (403), 
     * badMethod (405), serviceUnavailable (503)
     * 
     * @param request JSON representation of the metrics
     * @return JSON object
     */
    @PUT
    @Produces(MediaType.APPLICATION_JSON)
    public Response changeMetrics(String request) {
        MetricService svc = get(MetricService.class);
        // (...)  

        // Encode response
        return ok(r.toString()).build();
    }

    /**
     * Gets the metrics.
     * &amp;lt;p&amp;gt;
     * Normal Response Code(s): ok (200)
     * &amp;lt;p&amp;gt;
     * Error Response Codes: badRequest (400), unauthorized (401), forbidden (403), 
     * badMethod (405), serviceUnavailable (503), itemNotFound (404)
     *
     * @return JSON object
     */
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getMetrics() {
        MetricService svc = get(MetricService.class);
        // (...)
        return ok(r.toString()).build();
    }
}&lt;/PRE&gt;&lt;P&gt;I pretty much copied the DocProvider from the example:&lt;/P&gt;&lt;PRE&gt;@Component
public class DocProvider extends SelfRegisteringRSDocProvider {
    
    public DocProvider() {
        super("metrics", "rsdoc", DocProvider.class.getClassLoader());
    }

}&lt;/PRE&gt;&lt;P&gt;Same for the ServiceAssistant:&lt;/P&gt;&lt;PRE&gt;@Component(immediate=true, specVersion="1.1")
@References(value={
    @Reference(name="MetricService",
               referenceInterface=com.hp.mdd.api.MetricService.class,
               policy=ReferencePolicy.DYNAMIC, 
               cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE)
    })
public class ServiceAssistant {
    
    private ServiceLocator sl = ServiceLocator.INSTANCE;

    /**
     * Hook for registering MetricService implementation via declarative services.
     *
     * @param s newly advertised service to register
     * @param properties the properties associated with the service
     */
    protected void bindMetricService(com.hp.mdd.api.MetricService s, Map&amp;lt;String, Object&amp;gt; properties) {
        sl.register(com.hp.mdd.api.MetricService.class, s, properties);
    }
    
    /**
     * Hook for unregistering deactivated SystemInformationService via declarative services.
     *
     * @param s deactivated service to unregister
     */
    protected void unbindMetricService(com.hp.mdd.api.MetricService s) {
        sl.unregister(com.hp.mdd.api.MetricService.class, s);
    }

}&lt;/PRE&gt;&lt;P&gt;I tried to adjust the model.json, even though the documentation was pretty scarce on that:&lt;/P&gt;&lt;PRE&gt;{
    "${restPath}":
    {
        "metric": {
            "port": {"type": "long"},
            "packetthresh": {"type": "long"},
            "timewindow": {"type": "long"},
            "bytethresh": {"type": "long"},
            "packetwindow": {"type": "long"},
            "idletimeout": {"type": "int"}
        }
    }
}&lt;/PRE&gt;&lt;P&gt;And added my Resource to the param-values:&lt;/P&gt;&lt;PRE&gt;&amp;lt;param-value&amp;gt;
                com.hp.mdd.rs.MetricResource

                com.hp.sdn.rs.misc.DuplicateIdErrorHandler
                com.hp.sdn.rs.misc.NotFoundErrorHandler
                com.hp.sdn.rs.misc.ServiceNotFoundErrorHandler
                com.hp.sdn.rs.misc.IllegalDataHandler
                com.hp.sdn.rs.misc.IllegalStateHandler
                com.hp.sdn.rs.misc.AuthenticationHandler
         &amp;lt;/param-value&amp;gt;&lt;/PRE&gt;&lt;P&gt;When I activate the app normally and go to the REST API it just "fetching resource list: https://&amp;lt;controller_ip&amp;gt;&lt;SPAN&gt;:8443/api/rsdoc/metrics/1.0/resources.json" forever.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When I restart then I get the exceptions and I can't use the REST API anymore from the web interface (/in browser).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The API/Model part are pretty much working and simplistic.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2015 16:18:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/software-defined-networking/creating-a-rest-api/m-p/6764776#M1757</guid>
      <dc:creator>franzj</dc:creator>
      <dc:date>2015-07-14T16:18:07Z</dc:date>
    </item>
  </channel>
</rss>

