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


Java MediaType.APPLICATION_JSON屬性代碼示例

本文整理匯總了Java中org.restlet.data.MediaType.APPLICATION_JSON屬性的典型用法代碼示例。如果您正苦於以下問題:Java MediaType.APPLICATION_JSON屬性的具體用法?Java MediaType.APPLICATION_JSON怎麽用?Java MediaType.APPLICATION_JSON使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.restlet.data.MediaType的用法示例。


在下文中一共展示了MediaType.APPLICATION_JSON屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeResponse

@Override
public boolean writeResponse( final Object result, final Response response )
    throws ResourceException
{
    MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType();
    if( MediaType.APPLICATION_JSON.equals( type ) )
    {
        if( result instanceof String || result instanceof Number || result instanceof Boolean )
        {
            StringRepresentation representation = new StringRepresentation( result.toString(),
                                                                            MediaType.APPLICATION_JSON );

            response.setEntity( representation );

            return true;
        }
    }

    return false;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:20,代碼來源:DefaultResponseWriter.java

示例2: representJson

private Representation representJson()
    throws ResourceException
{
    try
    {
        final Iterable<EntityReference> query = entityFinder.findEntities( EntityComposite.class, null, null, null, null, Collections.emptyMap() )
                                                            .collect( toList() );
        return new OutputRepresentation( MediaType.APPLICATION_JSON )
        {
            @Override
            public void write( OutputStream outputStream )
                throws IOException
            {
                stateSerialization.serialize( new OutputStreamWriter( outputStream ), query );
            }
        };
    }
    catch( Exception e )
    {
        throw new ResourceException( e );
    }
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:22,代碼來源:EntitiesResource.java

示例3: handleCreateTargetPut

private Representation handleCreateTargetPut(String dbname) {

        // TODO - authenticate request
        /*
            HTTP/1.1 500 Internal Server Error
            Cache-Control: must-revalidate
            Content-Length: 108
            Content-Type: application/json
            Date: Fri, 09 May 2014 13:50:32 GMT
            Server: CouchDB (Erlang OTP)

            {
              "error": "unauthorized",
              "reason": "unauthorized to access or create database http://localhost:5984/target"
            }
        */

        // TODO this method does not check and handle failure to create the database
        Datastore ds;
		try {
			ds = manager.openDatastore(dbname);
			ds.close();
		} catch (DatastoreNotCreatedException e) {
			throw new RuntimeException(e);
		}

        String body = "{ \"ok\": true }";
        getResponse().setStatus(Status.SUCCESS_CREATED);
        return new StringRepresentation(body, MediaType.APPLICATION_JSON);
    }
 
開發者ID:ibm-watson-data-lab,項目名稱:sync-android-p2p,代碼行數:30,代碼來源:HttpListener.java

示例4: lastSequence

private Representation lastSequence(String dbname) {
    // the update_seq value may not actually be required
    Map<String, Object> response = new HashMap<String, Object>();
    response.put("instance_start_time", getInstanceStartTime(dbname).toString());
    response.put("update_seq", getLastSequence(dbname));
    String body = JSONUtils.serializeAsString(response);
    return new StringRepresentation(body, MediaType.APPLICATION_JSON);
}
 
開發者ID:ibm-watson-data-lab,項目名稱:sync-android-p2p,代碼行數:8,代碼來源:HttpListener.java

示例5: handleEnsureFullCommitPost

private Representation handleEnsureFullCommitPost(String dbname) {
    // http://docs.couchdb.org/en/latest/replication/protocol.html#ensure-in-commit
    Map<String, Object> response = new HashMap<String, Object>();
    response.put("instance_start_time", getInstanceStartTime(dbname));
    response.put("ok", true);
    String responseBody = JSONUtils.serializeAsString(response);
    //System.out.println(responseBody);
    getResponse().setStatus(Status.SUCCESS_CREATED);
    return new StringRepresentation(responseBody, MediaType.APPLICATION_JSON);
}
 
開發者ID:ibm-watson-data-lab,項目名稱:sync-android-p2p,代碼行數:10,代碼來源:HttpListener.java

示例6: representJson

private Representation representJson( EntityState entityState )
{
    // TODO This guy needs to represent an Entity as JSON
    if( entityState instanceof JSONEntityState )
    {
        JSONEntityState jsonState = (JSONEntityState) entityState;
        return new StringRepresentation( jsonState.state().toString(), MediaType.APPLICATION_JSON );
    }
    else
    {
        throw new ResourceException( Status.CLIENT_ERROR_NOT_ACCEPTABLE );
    }
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:13,代碼來源:EntityResource.java

示例7: buildVersionResponse

@HttpVerb("get")
@Summary("Obtains the version number of the Pinot components")
@Tags({ "version" })
@Paths({ "/version" })
private Representation buildVersionResponse() {
  JSONObject jsonObject = new JSONObject(Utils.getComponentVersions());
  return new StringRepresentation(jsonObject.toString(), MediaType.APPLICATION_JSON);
}
 
開發者ID:Hanmourang,項目名稱:Pinot,代碼行數:8,代碼來源:PinotVersionRestletResource.java

示例8: GsonRepresentation

public GsonRepresentation(T object) {
    super(MediaType.APPLICATION_JSON);
    iObject = object;
    iObjectClass = ((Class<T>) ((object == null) ? null : object.getClass()));
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:5,代碼來源:GsonRepresentation.java

示例9: handleChangesGet

private Representation handleChangesGet(String path) {
    // TODO changes handling isn't required ??
    String body = "changes";
    return new StringRepresentation(body, MediaType.APPLICATION_JSON);
}
 
開發者ID:ibm-watson-data-lab,項目名稱:sync-android-p2p,代碼行數:5,代碼來源:HttpListener.java

示例10: httpSuccess

private Representation httpSuccess() {
    // FIXME StringRepresentation is probably not the right choice as we aren't returning a body
    return new StringRepresentation("", MediaType.APPLICATION_JSON);
}
 
開發者ID:ibm-watson-data-lab,項目名稱:sync-android-p2p,代碼行數:4,代碼來源:HttpListener.java

示例11: handleRevsDiff

private Representation handleRevsDiff(String dbname) {
    String response = buildRevsDiffResponse(dbname);
    System.out.println(port + " handleRevsDiff:" + response);
    return new StringRepresentation(response, MediaType.APPLICATION_JSON);
}
 
開發者ID:ibm-watson-data-lab,項目名稱:sync-android-p2p,代碼行數:5,代碼來源:HttpListener.java

示例12: handleBulkDocsPost

private Representation handleBulkDocsPost(String dbname) {
      // http://docs.couchdb.org/en/latest/replication/protocol.html#upload-batch-of-changed-documents

      Datastore ds;
try {
	ds = manager.openDatastore(dbname);
} catch (DatastoreNotCreatedException e1) {
	throw new RuntimeException(e1);
}

      Map<String, Object> bulkDocsRequest = getRequestEntityAsMap();
      System.out.println(port + " bulkDocsRequest: " + bulkDocsRequest);

      List<Map<String, Object>> docs = (List<Map<String, Object>>) bulkDocsRequest.get("docs");

      List<Map<String, Object>> response = new ArrayList<Map<String, Object>>();

      for (Map<String, Object> doc : docs) {

          String docId = (String)doc.get("_id");
          String revId = (String)doc.get("_rev");

          Map<String, Object> revisionHistoryMap = (Map<String, Object>)doc.get("_revisions");
          int revStart = (Integer)revisionHistoryMap.get("start");

          List<String> revisionIds = (List<String>)revisionHistoryMap.get("ids");
          List<String> revisionHistoryList = appendRevisionSequence(revisionIds, revStart);

          // saving fails unless the revisionHistoryList is in reverse order
          Collections.reverse(revisionHistoryList);

          doc.remove("_revisions");
          doc.remove("_id");
          doc.remove("_rev");

          DocumentBody body = DocumentBodyFactory.create(doc);

          DocumentRevisionBuilder builder = new DocumentRevisionBuilder();
          builder.setDocId(docId);
          builder.setRevId(revId);
          builder.setBody(body);

          DocumentRevision rev = builder.build();

          try {
              ((DatastoreImpl) ds).forceInsert(rev, revisionHistoryList.toArray(
                      new String[revisionHistoryList.size()]));
          } catch (DocumentException e) {
              throw new RuntimeException(e);
          }
          
          Map<String, Object> responseItem = new TreeMap<String, Object>();
          responseItem.put("ok", true);
          responseItem.put("id", docId);
          responseItem.put("rev", revId);
          response.add(responseItem);
      }

      ds.close();

      Boolean newEdits = (Boolean)bulkDocsRequest.get("new_edits");
      
      String responseJSON = "";
      if (newEdits != null && !newEdits) {
      	responseJSON = "[]";
      } else {
      	responseJSON = ExtendedJSONUtils.serializeAsString(response);
      }
      System.out.println(port + " handleBulkDocsPost: " + responseJSON);
      getResponse().setStatus(Status.SUCCESS_CREATED);
      return new StringRepresentation(responseJSON, MediaType.APPLICATION_JSON);
  }
 
開發者ID:ibm-watson-data-lab,項目名稱:sync-android-p2p,代碼行數:72,代碼來源:HttpListener.java

示例13: handleLocalPut

private Representation handleLocalPut(String dbname) {

        Map<String, Object> request = getRequestEntityAsMap();

        System.out.println( JSONUtils.serializeAsString(request) );

        String docId = (String)request.get("_id");
        String revId = (String)request.get("_rev");

        request.remove("_id");
        request.remove("_rev");
        request.remove("_revision");
        request.remove("_revisions");
        
        DocumentBody body = DocumentBodyFactory.create(request);
        
        DocumentRevisionBuilder builder = new DocumentRevisionBuilder();
        builder.setDocId(docId);
        builder.setRevId(revId);
        builder.setDeleted(false);
        builder.setBody(body);
        DocumentRevision doc = builder.build();

        Datastore ds = null;
		try {
			ds = manager.openDatastore(dbname);
		} catch (DatastoreNotCreatedException e1) {
			throw new RuntimeException(e1);
		}
		
        try {
            if (!ds.containsDocument(docId, revId)) {
               
                ((DatastoreImpl)ds).forceInsert(doc);
                
            } else {
                // FIXME the datastore shouldn't contain this revId
                System.out.println("XXXXXXXX " + docId + " " + revId);
            }
        } catch (Exception e) {
            // TODO handle properly (return 500?)
            throw new RuntimeException(e);
        } finally {
            ds.close();
        }

        Map<String, Object> response = new HashMap<String, Object>();
        response.put("id", docId);
        response.put("ok", true);
        response.put("rev", revId);

        String responseBody = JSONUtils.serializeAsString(response);

        System.out.println(responseBody);

        getResponse().setStatus(Status.SUCCESS_CREATED);
        return new StringRepresentation(responseBody, MediaType.APPLICATION_JSON);
    }
 
開發者ID:ibm-watson-data-lab,項目名稱:sync-android-p2p,代碼行數:58,代碼來源:HttpListener.java

示例14: createJsonRepresentation

private StringRepresentation createJsonRepresentation( Links result )
{
    String json = jsonSerializer.serialize( result );
    return new StringRepresentation( json, MediaType.APPLICATION_JSON );
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:5,代碼來源:LinksResponseWriter.java

示例15: JsonRepresentation

public JsonRepresentation()
{
    super( MediaType.APPLICATION_JSON );
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:4,代碼來源:JsonRepresentation.java


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