Loading ...
Sorry, an error occurred while loading the content.
 

Including "metadata" in representations

Expand Messages
  • Ebenezer Ikonne
    This is more of a design/implementation question but I m wondering if its acceptable to include metadata with the representation of a resource when the
    Message 1 of 10 , Feb 10, 2008
      This is more of a design/implementation question but I'm wondering if
      its acceptable to include "metadata" with the representation of a
      resource when the representation is being sent from a client to a
      server. I am assuming yes, but I want to make sure.

      Most trivial examples show (for example) the sending of an order's
      representation when the order is being updated. But what if the user
      needs to send credentials so that the server can validate before
      actually updating the order? How does this information get sent?

      In other cases, "processing instructions" need to be provided so that
      the system knows exactly what to do the resource being manipulated -
      these processing instructions are not really part of the resource.

      Thanks.
    • Subbu Allamaraju
      ... Are these credentials different from those that could be sent via HTTP authentication? ... Could you elaborate? It is strange for a client to specify
      Message 2 of 10 , Feb 13, 2008
        On Feb 10, 2008, at 6:55 PM, Ebenezer Ikonne wrote:

        > This is more of a design/implementation question but I'm wondering if
        > its acceptable to include "metadata" with the representation of a
        > resource when the representation is being sent from a client to a
        > server. I am assuming yes, but I want to make sure.
        >
        > Most trivial examples show (for example) the sending of an order's
        > representation when the order is being updated. But what if the user
        > needs to send credentials so that the server can validate before
        > actually updating the order? How does this information get sent?

        Are these credentials different from those that could be sent via HTTP
        authentication?

        > In other cases, "processing instructions" need to be provided so that
        > the system knows exactly what to do the resource being manipulated -
        > these processing instructions are not really part of the resource.

        Could you elaborate? It is strange for a client to specify
        instructions on how to process a resource.

        Subbu
        http://subbu.org
        >
      • Griffin Caprio
        Hi all, What s the best way to return specific errors to a client if they make a malformed request? My company has a REST web service that accepts POSTed data
        Message 3 of 10 , Feb 14, 2008
          Hi all,

          What's the best way to return specific errors to a client if they make a malformed request?  My company has a REST web service that accepts POSTed data to it.  We wanted to return a 400 response code in cases where the data being sent is invalid for some reason ( invalid XML, invalid business rules, etc.. ) .  We also wanted to return specific validation messages as part of the response body.  

          However, we're running into problems with some java clients because apparently the HttpUrlConnection class in the JDK swallows the response bodies when a 400 or higher return code is sent back:

          From HttpUrlConnection ( around line 970 )

          if (respCode >= 400) {
             if (respCode == 404 || respCode == 410) {
                 throw new FileNotFoundException(url.toString());
             } else {
                throw new java.io.IOException(
                                   "Server returned HTTP"
                                   + " response code: " + respCode
                                   + " for URL: " + url.toString());
             }
          }


          So my question: Is what we're trying to do not really correct?  I've looked in the HTTP spec and it says that an Entity Body may be returned with a 400 error, so maybe it's just a bug in the Java implementation?

          Any input would be appreciated.

          Thanks,
          Griffin
        • Chris Burdess
          ... It is correct. ... It s more of a pain to do with the way that HttpURLConnection is specified. There is a workaround: HttpURLConnection.getErrorStream -
          Message 4 of 10 , Feb 14, 2008
            Griffin Caprio wrote:
            > What's the best way to return specific errors to a client if they make
            > a malformed request? My company has a REST web service that accepts
            > POSTed data to it. We wanted to return a 400 response code in cases
            > where the data being sent is invalid for some reason ( invalid XML,
            > invalid business rules, etc.. ) . We also wanted to return specific
            > validation messages as part of the response body.
            >
            > However, we're running into problems with some java clients because
            > apparently the HttpUrlConnection class in the JDK swallows the
            > response bodies when a 400 or higher return code is sent back:
            >
            > From HttpUrlConnection ( around line 970 )
            >
            > if (respCode >= 400) {
            > if (respCode == 404 || respCode == 410) {
            > throw new FileNotFoundException(url.toString());
            > } else {
            > throw new java.io.IOException(
            > "Server returned HTTP"
            > + " response code: " + respCode
            > + " for URL: " + url.toString());
            > }
            > }
            >
            >
            > So my question: Is what we're trying to do not really correct?

            It is correct.

            > I've
            > looked in the HTTP spec and it says that an Entity Body may be
            > returned with a 400 error, so maybe it's just a bug in the Java
            > implementation?

            It's more of a pain to do with the way that HttpURLConnection is
            specified. There is a workaround: HttpURLConnection.getErrorStream -
            see the Javadoc for this - but most developers probably don't know
            or ignore this.

            Just a poor design.
            --
            Chris Burdess
          • Subbu Allamaraju
            This looks like a bug in the HttpURLConnection. Per RFC 2616, the server SHOULD include an entity containing an explanation of the error situation for all
            Message 5 of 10 , Feb 14, 2008
              This looks like a bug in the HttpURLConnection. Per RFC 2616, "the server SHOULD include an entity containing an explanation of the error situation" for all 4xx errors. Accordingly, it is not necessarily the best choice for a client side API such as HttpURLConnection to consume the body and translate those errors into generic exceptions.

              Subbu

              On Feb 14, 2008, at 7:15 AM, Griffin Caprio wrote:

              Hi all,

              What's the best way to return specific errors to a client if they make a malformed request?  My company has a REST web service that accepts POSTed data to it.  We wanted to return a 400 response code in cases where the data being sent is invalid for some reason ( invalid XML, invalid business rules, etc.. ) .  We also wanted to return specific validation messages as part of the response body.  

              However, we're running into problems with some java clients because apparently the HttpUrlConnection class in the JDK swallows the response bodies when a 400 or higher return code is sent back:

              From HttpUrlConnection ( around line 970 )

              if (respCode >= 400) {
                 if (respCode == 404 || respCode == 410) {
                     throw new FileNotFoundException(url.toString());
                 } else {
                    throw new java.io.IOException(
                                       "Server returned HTTP"
                                       + " response code: " + respCode
                                       + " for URL: " + url.toString());
                 }
              }


              So my question: Is what we're trying to do not really correct?  I've looked in the HTTP spec and it says that an Entity Body may be returned with a 400 error, so maybe it's just a bug in the Java implementation?

              Any input would be appreciated.

              Thanks,
              Griffin


            • Ebenezer Ikonne
              Credentials was probably a bad illustration and processing instructions is just a wrong way to express what I m after. :) Basically I have/had a situation
              Message 6 of 10 , Feb 14, 2008
                Credentials was probably a bad illustration and processing
                instructions is just a wrong way to express what I'm after. :)

                Basically I have/had a situation where I have resources such as a
                Book that exist in different locations/stores. I was struggling (for
                a while) on how to indicate the location/store where I wanted the
                resource manipulated.

                Anyway, the "location" should be part of the URI in my opinion as its
                part of the resources address.

                Thanks.

                --- In rest-discuss@yahoogroups.com, Subbu Allamaraju
                <subbu.allamaraju@...> wrote:
                >
                >
                >
                > On Feb 10, 2008, at 6:55 PM, Ebenezer Ikonne wrote:
                >
                > > This is more of a design/implementation question but I'm
                wondering if
                > > its acceptable to include "metadata" with the representation of a
                > > resource when the representation is being sent from a client to a
                > > server. I am assuming yes, but I want to make sure.
                > >
                > > Most trivial examples show (for example) the sending of an order's
                > > representation when the order is being updated. But what if the
                user
                > > needs to send credentials so that the server can validate before
                > > actually updating the order? How does this information get sent?
                >
                > Are these credentials different from those that could be sent via
                HTTP
                > authentication?
                >
                > > In other cases, "processing instructions" need to be provided so
                that
                > > the system knows exactly what to do the resource being
                manipulated -
                > > these processing instructions are not really part of the resource.
                >
                > Could you elaborate? It is strange for a client to specify
                > instructions on how to process a resource.
                >
                > Subbu
                > http://subbu.org
                > >
                >
              • Alan Dean
                ... Perhaps something like: Start by finding out info about the book: -- GET /isbn/0123456789012 A Cool
                Message 7 of 10 , Feb 14, 2008
                  On Thu, Feb 14, 2008 at 5:53 PM, Ebenezer Ikonne <amaeze@...> wrote:
                  >
                  > Basically I have/had a situation where I have resources such as a
                  > Book that exist in different locations/stores. I was struggling (for
                  > a while) on how to indicate the location/store where I wanted the
                  > resource manipulated.
                  >
                  > Anyway, the "location" should be part of the URI in my opinion as its
                  > part of the resources address.

                  Perhaps something like:

                  Start by finding out info about the book:

                  -->
                  GET /isbn/0123456789012

                  <--
                  200 OK

                  <book isbn="0123456789012">
                  <title>A Cool Book</title>
                  <location name="Los Angeles" href="http://example.com/location/london">
                  <stock count="12"
                  href="http://example.com/isbn/0123456789012/location/london" />
                  </location>
                  <location name="New York" href="http://example.com/location/paris">
                  <stock count="5"
                  href="http://example.com/isbn/0123456789012/location/paris" />
                  </location>
                  ...
                  </book>

                  If the UA wants to know more about the location, it can request the
                  <location> href:

                  -->
                  GET /location/paris

                  <--
                  200 OK

                  <location name="Paris">
                  ...
                  </location>

                  If the UA wants to know more about the stock, it can request the <stock> href:

                  -->
                  GET /isbn/0123456789012/location/london

                  <--
                  200 OK

                  <stock count="5">
                  <sku condition="new" id="abc123" href="http://example.com/sku/abc123">
                  <price currency="GBP">10.99</price>
                  <price currency="EUR">15.99</price>
                  <price currency="USD">18.49</price>
                  </sku>
                  ...
                  </stock>

                  Does that work for you?

                  Regards,
                  Alan Dean
                  http://thoughtpad.net/alan-dean
                • Ebenezer Ikonne
                  ... href= http://example.com/location/london ... href= http://example.com/location/paris ... href= http://example.com/sku/abc123 ... Well not exactly,
                  Message 8 of 10 , Feb 14, 2008
                    > Perhaps something like:
                    >
                    > Start by finding out info about the book:
                    >
                    > -->
                    > GET /isbn/0123456789012
                    >
                    > <--
                    > 200 OK
                    >
                    > <book isbn="0123456789012">
                    > <title>A Cool Book</title>
                    > <location name="Los Angeles"
                    href="http://example.com/location/london">
                    > <stock count="12"
                    > href="http://example.com/isbn/0123456789012/location/london" />
                    > </location>
                    > <location name="New York"
                    href="http://example.com/location/paris">
                    > <stock count="5"
                    > href="http://example.com/isbn/0123456789012/location/paris" />
                    > </location>
                    > ...
                    > </book>
                    >
                    > If the UA wants to know more about the location, it can request the
                    > <location> href:
                    >
                    > -->
                    > GET /location/paris
                    >
                    > <--
                    > 200 OK
                    >
                    > <location name="Paris">
                    > ...
                    > </location>
                    >
                    > If the UA wants to know more about the stock, it can request the
                    <stock> href:
                    >
                    > -->
                    > GET /isbn/0123456789012/location/london
                    >
                    > <--
                    > 200 OK
                    >
                    > <stock count="5">
                    > <sku condition="new" id="abc123"
                    href="http://example.com/sku/abc123">
                    > <price currency="GBP">10.99</price>
                    > <price currency="EUR">15.99</price>
                    > <price currency="USD">18.49</price>
                    > </sku>
                    > ...
                    > </stock>
                    >

                    Well not exactly, but I could see how it could work. :) I am
                    interested in the book as my resource and not the location.

                    I guess I was thinking that the URI would look more so like this:
                    http://example.com/location/london/isbn/0123456789012

                    This is assuming that there was a search engine (web service) that
                    could aggregate the location of the books i.e. how you started.

                    Thanks.
                  • Griffin Caprio
                    Chris, Great, thanks for your help! - Griffin
                    Message 9 of 10 , Feb 14, 2008
                      Chris,

                      Great, thanks for your help!

                      - Griffin
                      On Feb 14, 2008, at 10:18 AM, Chris Burdess wrote:

                      > Griffin Caprio wrote:
                      >> What's the best way to return specific errors to a client if they
                      >> make
                      >> a malformed request? My company has a REST web service that accepts
                      >> POSTed data to it. We wanted to return a 400 response code in cases
                      >> where the data being sent is invalid for some reason ( invalid XML,
                      >> invalid business rules, etc.. ) . We also wanted to return specific
                      >> validation messages as part of the response body.
                      >>
                      >> However, we're running into problems with some java clients because
                      >> apparently the HttpUrlConnection class in the JDK swallows the
                      >> response bodies when a 400 or higher return code is sent back:
                      >>
                      >> From HttpUrlConnection ( around line 970 )
                      >>
                      >> if (respCode >= 400) {
                      >> if (respCode == 404 || respCode == 410) {
                      >> throw new FileNotFoundException(url.toString());
                      >> } else {
                      >> throw new java.io.IOException(
                      >> "Server returned HTTP"
                      >> + " response code: " + respCode
                      >> + " for URL: " + url.toString());
                      >> }
                      >> }
                      >>
                      >>
                      >> So my question: Is what we're trying to do not really correct?
                      >
                      > It is correct.
                      >
                      >> I've
                      >> looked in the HTTP spec and it says that an Entity Body may be
                      >> returned with a 400 error, so maybe it's just a bug in the Java
                      >> implementation?
                      >
                      > It's more of a pain to do with the way that HttpURLConnection is
                      > specified. There is a workaround: HttpURLConnection.getErrorStream -
                      > see the Javadoc for this - but most developers probably don't know
                      > or ignore this.
                      >
                      > Just a poor design.
                      > --
                      > Chris Burdess
                    • Steve Loughran
                      On Thu, Feb 14, 2008 at 3:15 PM, Griffin Caprio ... no, its worse than that. Historically, it s choice of action depended on the extension of the remote URL.
                      Message 10 of 10 , Mar 2, 2008
                        On Thu, Feb 14, 2008 at 3:15 PM, Griffin Caprio
                        <griffin.caprio@...> wrote:
                        >
                        > Hi all,
                        >
                        > What's the best way to return specific errors to a client if they make a
                        > malformed request? My company has a REST web service that accepts POSTed
                        > data to it. We wanted to return a 400 response code in cases where the data
                        > being sent is invalid for some reason ( invalid XML, invalid business rules,
                        > etc.. ) . We also wanted to return specific validation messages as part of
                        > the response body.
                        >
                        > However, we're running into problems with some java clients because
                        > apparently the HttpUrlConnection class in the JDK swallows the response
                        > bodies when a 400 or higher return code is sent back:

                        no, its worse than that. Historically, it's choice of action depended
                        on the extension of the remote URL. .html extensions tended to include
                        the test, but .jsp pages didnt.

                        One word: httpclient

                        -steve
                      Your message has been successfully submitted and would be delivered to recipients shortly.