当前位置: 首页>>代码示例>>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;未经允许,请勿转载。