@Override
  public void handleRequest(RestRequest request, RequestContext requestContext, Callback<RestResponse> callback)
  {
    //This code path cannot accept content types or accept types that contain
    //multipart/related. This is because these types of requests will usually have very large payloads and therefore
    //would degrade server performance since RestRequest reads everything into memory.
    if (!isMultipart(request, requestContext, callback))
    {
      _restRestLiServer.handleRequest(request, requestContext, callback);
    }
  }
@Test
  public void testMultipartRelatedNoAttachmentsAtAll() throws Exception
  {
    //This test verifies the server's ability to throw an exception if there are absolutely no attachments at all
    //in the request. The protocol allows no user attachments to be required, but there must always be at least a rest.li
    //payload in the first part.

    final MultiPartMIMEWriter.Builder builder = new MultiPartMIMEWriter.Builder();

    final StreamRequest streamRequest =
        MultiPartMIMEStreamRequestFactory.generateMultiPartMIMEStreamRequest(new URI("/statuses/1"), "related",
                                                                             builder.build(), Collections.emptyMap(),
                                                                             "POST",
                                                                             ImmutableMap.of(RestConstants.HEADER_ACCEPT, RestConstants.HEADER_VALUE_MULTIPART_RELATED),
                                                                             Collections.emptyList());

    final Callback<StreamResponse> callback = new Callback<StreamResponse>()
    {
      @Override
      public void onSuccess(StreamResponse streamResponse)
      {
        Assert.fail();
      }

      @Override
      public void onError(Throwable e)
      {
        //Verify the exception.
        assertTrue(e instanceof StreamException);
        StreamException streamException = (StreamException)e;
        StreamResponse streamResponse = streamException.getResponse();

        assertEquals(streamResponse.getStatus(), 400);
        final FullEntityReader fullEntityReader = new FullEntityReader(new Callback<ByteString>()
        {
          @Override
          public void onError(Throwable e)
          {
            Assert.fail();
          }

          @Override
          public void onSuccess(ByteString result)
          {
            //We have the body so assert that the exception made it.
            assertTrue(result.length() > 0);
            assertTrue(result.asString(Charset.defaultCharset())
                           .contains("Did not receive any parts in the multipart mime request"));
          }
        });
        streamResponse.getEntityStream().setReader(fullEntityReader);
      }
    };

    _server.handleRequest(streamRequest, new RequestContext(), callback);
  }