當前位置: 首頁>>代碼示例>>Java>>正文


Java Request.setEntity方法代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:17,代碼來源:FormRequestWriter.java

示例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;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:26,代碼來源:RequestWriterDelegator.java

示例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);
}
 
開發者ID:Hanmourang,項目名稱:Pinot,代碼行數:11,代碼來源:PinotFileUploadTest.java

示例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;
}
 
開發者ID:uber,項目名稱:uReplicator,代碼行數:7,代碼來源:ControllerRequestURLBuilder.java

示例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;
}
 
開發者ID:uber,項目名稱:uReplicator,代碼行數:7,代碼來源:ControllerRequestURLBuilder.java

示例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;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:55,代碼來源:ValueCompositeRequestWriter.java


注:本文中的org.restlet.Request.setEntity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。