Class StockQuoteService

  • All Implemented Interfaces:
    org.wso2.msf4j.Microservice

    @Path("/stockquote")
    public class StockQuoteService
    extends java.lang.Object
    implements org.wso2.msf4j.Microservice
    StockQuote microservice.
    • Constructor Summary

      Constructors 
      Constructor Description
      StockQuoteService()
      Add initial stocks IBM, GOOG, AMZN.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void activate​(org.osgi.framework.BundleContext bundleContext)  
      void addStock​(Stock stock)
      Add a new stock.
      protected void deactivate​(org.osgi.framework.BundleContext bundleContext)  
      Stocks getAllStocks​(org.wso2.msf4j.Request request)
      Retrieve all stocks.
      javax.ws.rs.core.Response getQuote​(java.lang.String symbol)
      Retrieve a stock for a given symbol.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • StockQuoteService

        public StockQuoteService()
        Add initial stocks IBM, GOOG, AMZN.
    • Method Detail

      • activate

        protected void activate​(org.osgi.framework.BundleContext bundleContext)
      • deactivate

        protected void deactivate​(org.osgi.framework.BundleContext bundleContext)
      • getQuote

        @GET
        @Path("/{symbol}")
        @Produces({"application/json","text/xml"})
        public javax.ws.rs.core.Response getQuote​(@PathParam("symbol")
                                                  java.lang.String symbol)
                                           throws SymbolNotFoundException
        Retrieve a stock for a given symbol. http://localhost:8080/stockquote/IBM
        Parameters:
        symbol - Stock symbol will be taken from the path parameter.
        Returns:
        Throws:
        SymbolNotFoundException
      • addStock

        @POST
        @Consumes("application/json")
        public void addStock​(Stock stock)
                      throws DuplicateSymbolException
        Add a new stock. curl -v -X POST -H "Content-Type:application/json" \ -d '{"symbol":"BAR","name": "Bar Inc.", \ "last":149.62,"low":150.78,"high":149.18, "createdByHost":"10.100.1.192"}' \ http://localhost:8080/stockquote
        Parameters:
        stock - Stock object will be created from the request Json body.
        Throws:
        DuplicateSymbolException
      • getAllStocks

        @GET
        @Path("/all")
        @Produces({"application/json","text/xml"})
        public Stocks getAllStocks​(@Context
                                   org.wso2.msf4j.Request request)
        Retrieve all stocks. http://localhost:8080/stockquote/all
        Returns:
        All stocks will be sent to the client as Json/xml according to the Accept header of the request.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object