Class StockQuoteService

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

    @Path("/stockquote")
    public class StockQuoteService
    extends java.lang.Object
    implements org.wso2.msf4j.Microservice
    StockQuote sample. This service will be available at. http://localhost:8080/stockquote
    • 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
      void addStock​(Stock stock)
      Add a new stock.
      Stocks getAllStocks​(org.wso2.msf4j.Request request)
      Retrieve all stocks.
      javax.ws.rs.core.Response getCommunicationInformationForRequestURI()
      Retrieve information on what methods are allowed on the Request-URI.
      javax.ws.rs.core.Response getMetaInformationForQuote​(java.lang.String symbol)
      Retrieve metainformation about the entity implied by the request.
      javax.ws.rs.core.Response getQuote​(java.lang.String symbol)
      Retrieve a stock for a given symbol.
      javax.ws.rs.core.Response getQuoteUsingCookieParam​(java.lang.String symbol)
      Retrieve a stock for a given symbol using a cookie.
      • Methods inherited from class java.lang.Object

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

      • StockQuoteService

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

      • 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:
        Response
        Throws:
        SymbolNotFoundException
      • getMetaInformationForQuote

        @HEAD
        @Path("/{symbol}")
        @Produces({"application/json","text/xml"})
        public javax.ws.rs.core.Response getMetaInformationForQuote​(@PathParam("symbol")
                                                                    java.lang.String symbol)
                                                             throws SymbolNotFoundException
        Retrieve metainformation about the entity implied by the request. curl -i -X HEAD http://localhost:8080/stockquote/IBM
        Returns:
        Response
        Throws:
        SymbolNotFoundException
      • getQuoteUsingCookieParam

        @GET
        @Produces({"application/json","text/xml"})
        public javax.ws.rs.core.Response getQuoteUsingCookieParam​(@CookieParam("symbol")
                                                                  java.lang.String symbol)
                                                           throws SymbolNotFoundException
        Retrieve a stock for a given symbol using a cookie. This method demonstrates the CookieParam JAXRS annotation in action. curl -v --header "Cookie: symbol=IBM" http://localhost:8080/stockquote
        Parameters:
        symbol - Stock symbol will be taken from the symbol cookie.
        Returns:
        Response
        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.
      • getCommunicationInformationForRequestURI

        @OPTIONS
        @Path("/all")
        public javax.ws.rs.core.Response getCommunicationInformationForRequestURI()
        Retrieve information on what methods are allowed on the Request-URI. curl -i -X OPTIONS http://localhost:8080/stockquote/all
        Returns:
        Response