title: RESTEasy: what causes code to execute?
body: <p>I'm trying to solidify my understanding of Rest.  </p>
  
  <p>1) How does this function get called when there's no @Path, specifically, what triggers getCustomers to get called?
     "public StreamingOutput getCustomers(final @QueryParam("start") int start,
                         final @QueryParam("size") @DefaultValue("2") int size)"</p>
  
  <p>Source:</p>
  
  <pre><code>package com.restfully.shop.services;
  
  import com.restfully.shop.domain.Customer;
  
  import javax.ws.rs.DefaultValue;
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.QueryParam;
  import javax.ws.rs.WebApplicationException;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.StreamingOutput;
  import javax.ws.rs.core.UriInfo;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.PrintStream;
  import java.util.Collections;
  import java.util.LinkedHashMap;
  import java.util.Map;
  
  @Path("/customers")
  public class CustomerResource
  {
     private Map&lt;Integer, Customer&gt; customerDB = Collections.synchronizedMap(new LinkedHashMap&lt;Integer, Customer&gt;());
  
     public CustomerResource()
     {
        Customer customer;
        int id = 1;
  
        customer = new Customer();
        customer.setId(id);
        customer.setFirstName("Bill");
        customer.setLastName("Burke");
        customerDB.put(id++, customer);
  
        customer = new Customer();
        customer.setId(id);
        customer.setFirstName("Joe");
        customer.setLastName("Burke");
        customerDB.put(id++, customer);
     }
  
     @GET
     @Produces("application/xml")
     public StreamingOutput getCustomers(final @QueryParam("start") int start,
                                         final @QueryParam("size") @DefaultValue("2") int size)
     {
        return new StreamingOutput()
        {
           public void write(OutputStream outputStream) throws IOException, WebApplicationException
           {
              PrintStream writer = new PrintStream(outputStream);
              writer.println("&lt;customers&gt;");
              synchronized (customerDB)
              {
                 int i = 0;
                 for (Customer customer : customerDB.values())
                 {
                    if (i &gt;= start &amp;&amp; i &lt; start + size) outputCustomer("   ", writer, customer);
                    i++;
                 }
              }
              writer.println("&lt;/customers&gt;");
           }
        };
     }
  
     @GET
     @Produces("application/xml")
     @Path("uriinfo")
     public StreamingOutput getCustomers(@Context UriInfo info)
     {
        int start = 0;
        int size = 2;
        if (info.getQueryParameters().containsKey("start"))
        {
           start = Integer.valueOf(info.getQueryParameters().getFirst("start"));
        }
        if (info.getQueryParameters().containsKey("size"))
        {
           size = Integer.valueOf(info.getQueryParameters().getFirst("size"));
        }
        return getCustomers(start, size);
     }
  
     protected void outputCustomer(String indent, PrintStream writer, Customer cust) throws IOException
     {
        writer.println(indent + "&lt;customer id=\"" + cust.getId() + "\"&gt;");
        writer.println(indent + "   &lt;first-name&gt;" + cust.getFirstName() + "&lt;/first-name&gt;");
        writer.println(indent + "   &lt;last-name&gt;" + cust.getLastName() + "&lt;/last-name&gt;");
        writer.println(indent + "&lt;/customer&gt;");
     }
  }
  </code></pre>
  
  <p>2) As for the second getCustomers function, Am I correct that it is the the existence of the <strong><em>path*</em></strong> @Path("uriinfo") that matches the URL that triggers the call? Note #1 has no @path at all.  I know there's the precedence rules, but what happens if I had an almost identical method that has the same path, then will BOTH methods get called?</p>
  
  <p>Let's say I also have this- note the 2 in getCustomers2:</p>
  
  <pre><code>   @GET
     @Produces("application/xml")
     @Path("uriinfo")
     public StreamingOutput getCustomers2(@Context UriInfo info)
     {
        int start = 0;
        int size = 2;
        if (info.getQueryParameters().containsKey("start"))
        {
           start = Integer.valueOf(info.getQueryParameters().getFirst("start"));
        }
        if (info.getQueryParameters().containsKey("size"))
        {
           size = Integer.valueOf(info.getQueryParameters().getFirst("size"));
        }
        return getCustomers(start, size);
     }
  </code></pre>
  
  <p>I got a compilation error. </p>
  
  <h2>3) is it true that a) the @Path must be unique b) one unique path per method c) if @Path for the method is not specified and there's only one method, then it's referencing the "class" @Path and expects to have no more than one method.</h2>
  
  <p>Sorry, I made an error previously, what if I had these two methods in the class:</p>
  
  <pre><code>@GET
  @Produces("application/xml")
  public StreamingOutput getCustomers3(final @QueryParam("start") int start,
                                     final @QueryParam("size") @DefaultValue("2") int   size)
  {
      return new StreamingOutput()
      {
       public void write(OutputStream outputStream) throws IOException, WebApplicationException
       {
           PrintStream writer = new PrintStream(outputStream);
           writer.println("&lt;customers&gt;");
           synchronized (customerDB)
           {
              int i = 0;
              for (Customer customer : customerDB.values())
              {
                 if (i &gt;= start &amp;&amp; i &lt; start + size) outputCustomer("   ", writer, customer); 
                 i++;
              }
           }
           writer.println("&lt;/customers&gt;");
        }
      };
  }
  
  
     @GET
     @Produces("application/xml")
     public StreamingOutput getCustomers4(final @QueryParam("start") int start,
                                     final @QueryParam("size") @DefaultValue("2") int   size)
     {
        return new StreamingOutput()
        {
          public void write(OutputStream outputStream) throws IOException,  WebApplicationException
        {
           PrintStream writer = new PrintStream(outputStream);
           writer.println("&lt;customers&gt;");
           synchronized (customerDB)
           {
              int i = 0;
              for (Customer customer : customerDB.values())
              {
                 if (i &gt;= start &amp;&amp; i &lt; start + size) outputCustomer("   ", writer, customer) ;
                 i++;
              }
           }
           writer.println("&lt;/customers&gt;");
        }
     };
  } 
  </code></pre>