Java Code Examples for org.restlet.Request.setEntity()

The following are Jave code examples for showing how to use setEntity() of the org.restlet.Request class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: polygene-java   File: FormRequestWriter.java   Source Code and License Vote up 6 votes
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
   if (requestObject instanceof Form)
   {
      // Form as query parameters
      if (request.getMethod().equals(Method.GET))
         request.getResourceRef().setQuery(((Form)requestObject).getQueryString());
      else
         request.setEntity(((Form)requestObject).getWebRepresentation(CharacterSet.UTF_8));

      return true;
   }

   return false;
}
 
Example 2
Project: polygene-java   File: RequestWriterDelegator.java   Source Code and License Vote up 6 votes
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
   if (requestObject == null)
   {
      if (!Method.GET.equals(request.getMethod()))
         request.setEntity(new EmptyRepresentation());

      return true;
   }

   if (requestObject instanceof Representation)
   {
      request.setEntity((Representation) requestObject);
      return true;
   }

   for (RequestWriter requestWriter : requestWriters)
   {
      if (requestWriter.writeRequest(requestObject, request))
         return true;
   }

   return false;
}
 
Example 3
Project: Pinot   File: PinotFileUploadTest.java   Source Code and License Vote up 5 votes
@Test
public void testUploadBogusData() {
  Client client = new Client(Protocol.HTTP);
  Request request =
      new Request(Method.POST, ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forDataFileUpload());
  request.setEntity("blah", MediaType.MULTIPART_ALL);
  Response response = client.handle(request);

  Assert.assertEquals(response.getStatus(), Status.SERVER_ERROR_INTERNAL);
}
 
Example 4
Project: uReplicator   File: ControllerRequestURLBuilder.java   Source Code and License Vote up 4 votes
public Request getTopicCreationRequestUrl(String topic, int numPartitions) {
  Request request = new Request(Method.POST, _baseUrl + "/topics/");
  TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions);
  request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON);
  return request;
}
 
Example 5
Project: uReplicator   File: ControllerRequestURLBuilder.java   Source Code and License Vote up 4 votes
public Request getTopicExpansionRequestUrl(String topic, int numPartitions) {
  Request request = new Request(Method.PUT, _baseUrl + "/topics/");
  TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions);
  request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON);
  return request;
}
 
Example 6
Project: chaperone   File: ControllerRequestURLBuilder.java   Source Code and License Vote up 4 votes
public Request getTopicCreationRequestUrl(String topic, int numPartitions) {
  Request request = new Request(Method.POST, _baseUrl + "/topics/");
  TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions);
  request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON);
  return request;
}
 
Example 7
Project: chaperone   File: ControllerRequestURLBuilder.java   Source Code and License Vote up 4 votes
public Request getTopicExpansionRequestUrl(String topic, int numPartitions) {
  Request request = new Request(Method.PUT, _baseUrl + "/topics/");
  TopicPartition topicPartitionInfo = new TopicPartition(topic, numPartitions);
  request.setEntity(topicPartitionInfo.toJSON().toJSONString(), MediaType.APPLICATION_JSON);
  return request;
}
 
Example 8
Project: polygene-java   File: ValueCompositeRequestWriter.java   Source Code and License Vote up 4 votes
@Override
public boolean writeRequest(Object requestObject, Request request) throws ResourceException
{
   if (requestObject instanceof ValueComposite)
   {
      // Value as parameter
      final ValueComposite valueObject = (ValueComposite) requestObject;
      if (request.getMethod().equals(Method.GET))
      {
         StateHolder holder = spi.stateOf( valueObject );
         final ValueDescriptor descriptor = spi.valueDescriptorFor( valueObject );

          final Reference ref = request.getResourceRef();
          ref.setQuery( null );
          descriptor.state().properties().forEach( propertyDescriptor -> {
              try
              {
                  Object value = holder.propertyFor( propertyDescriptor.accessor() ).get();
                  String param;
                  if( value == null )
                  {
                      param = null;
                  }
                  else
                  {
                      param = serializer.serialize( value );
                  }
                  ref.addQueryParameter( propertyDescriptor.qualifiedName().name(), param );
              }
              catch( SerializationException e )
              {
                  throw new ResourceException( e );
              }
          } );
      }
      else
      {
         request.setEntity(new WriterRepresentation( MediaType.APPLICATION_JSON )
         {
             @Override
             public void write( Writer writer )
                 throws IOException
             {
                setCharacterSet( CharacterSet.UTF_8 );
                serializer.serialize( writer, valueObject );
             }
         });
      }

      return true;
   }

   return false;
}