本文整理匯總了Java中org.restlet.Request.setEntity方法的典型用法代碼示例。如果您正苦於以下問題:Java Request.setEntity方法的具體用法?Java Request.setEntity怎麽用?Java Request.setEntity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.restlet.Request
的用法示例。
在下文中一共展示了Request.setEntity方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeRequest
import org.restlet.Request; //導入方法依賴的package包/類
@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;
}
示例2: writeRequest
import org.restlet.Request; //導入方法依賴的package包/類
@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;
}
示例3: testUploadBogusData
import org.restlet.Request; //導入方法依賴的package包/類
@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);
}
示例4: getTopicCreationRequestUrl
import org.restlet.Request; //導入方法依賴的package包/類
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;
}
示例5: getTopicExpansionRequestUrl
import org.restlet.Request; //導入方法依賴的package包/類
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;
}
示例6: writeRequest
import org.restlet.Request; //導入方法依賴的package包/類
@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;
}