是什么原因导致错误“内容已耗尽”?

时间:2019-10-02 19:05:10

标签: java android json http request

我有这种方法可以从服务器中检索内容,但是却遇到此错误,这是什么原因造成的?

我的方法:

private void retrieveNewAndUpdatedEntities(Long userId) throws Exception {
    try {
        String wsURL = Parameters.getParameter(Parameters.KEY_SERVER_URL) + Parameters.getInstance(context).getWSPath(Parameters.KEY_PATH_FOLDER) + "/auscultations/" + userId + "?page=";

        HttpGet getMethod;
        Integer page = 0;
        Integer totalPages = 1;

        HttpClient client = I9HttpClientFactory.buildHttpClient(context);
        HttpParams httpParams = client.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, Parameters.DEFAULT_CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(httpParams, Parameters.DEFAULT_SOCKET_TIMEOUT);

        HttpResponse response;
        EntityFolderAuscultationListResponse folderAuscultationsListResponse;
        List<EntityFolderAuscultation> folderAuscultations = new ArrayList<>();
        do {
            getMethod = new HttpGet(wsURL + page.toString());
            Log.i(AppConstants.TAG, "wsURL FolderAusc: " + wsURL);

            getMethod.addHeader("X-Auth-Token", Parameters.getParameter(Parameters.KEY_AUTH_TOKEN));

            response = client.execute(getMethod);
            if (response.getStatusLine().getStatusCode() == 200) {
                folderAuscultationsListResponse = GSONUtils.fromJSON(EntityFolderAuscultationListResponse.class, response.getEntity().getContent());
                totalPages = folderAuscultationsListResponse.getTotalPages();
                folderAuscultations.addAll(folderAuscultationsListResponse.getContent());
            } else {
                EntityErrorMessage errorMessage = GSONUtils.fromJSON(EntityErrorMessage.class, response.getEntity().getContent());
                throw new Exception("Error " + response.getStatusLine().getStatusCode() + " - "
                        + errorMessage.code);
            }
            page++;
        } while (page < totalPages);

        for (EntityFolderAuscultation remoteAuscultation : folderAuscultations) {
            EntityFolderAuscultation localAuscultation = FolderAuscultationDAO.findByIdServer(remoteAuscultation.getFolderId(), remoteAuscultation.getAuscultationId());

            if (localAuscultation != null) {
                remoteAuscultation.setFolderId(localAuscultation.getFolderId());
                remoteAuscultation.setAuscultationId(localAuscultation.getAuscultationId());
                //remoteAuscultation.setRemoteAuscultationId(AuscultationDAO.findByIdServer(auscultationId).getLocalId());
                remoteAuscultation.setSyncStatus(SYNCED);
                FolderAuscultationDAO.update(EntityFolderAuscultation.class, remoteAuscultation);
            } else {
                remoteAuscultation.setFolderId(null);
                remoteAuscultation.setAuscultationId(null);
                //remoteAuscultation.setRemoteAuscultationId(AuscultationDAO.findByIdServer(auscultationId).getLocalId());
                remoteAuscultation.setSyncStatus(SYNCED);
                FolderAuscultationDAO.insert(EntityFolderAuscultation.class, remoteAuscultation);
            }

        }
    } catch (Exception e) {
        Log.i(AppConstants.TAG, "Err requesting all folderAusc " + e.getMessage());
        throw e;
    }
}

服务器方法:

@GetMapping("/auscultations/{userId}")
public List<FolderAuscAssociation> retrieveFolderAusc(@PathVariable Long userId) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null || !authentication.isAuthenticated()) {
        throw new RuntimeException();
    }

    List<FolderAuscAssociation> folderAuscAssoc = new ArrayList<FolderAuscAssociation>();

    Users user = usersRepository.findById(userId).get();
    List<Folders> folderList = foldersRepository.findByOwner(user);
    for(Folders folder : folderList) {
        folderAuscAssoc.addAll(folderAuscAssociationRepository.findByFolder(folder));
    }

    return folderAuscAssoc;
}

stacktrace:

E / facade:AbstractEntityFacade.synchronizeWithServer exx:内容已消耗     java.lang.IllegalStateException:内容已被消耗         在org.apache.http.entity.BasicHttpEntity.getContent(BasicHttpEntity.java:89)         在org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:105)         在br.com.conectivida.mdconnect.facade.FolderAuscultationFacade.retrieveNewAndUpdatedEntities(FolderAuscultationFacade.java:217)         在br.com.conectivida.mdconnect.facade.FolderAuscultationFacade.retrieveEntitiesFromServer(FolderAuscultationFacade.java:281)上         在br.com.conectivida.mdconnect.facade.AbstractEntityFacade $ 1.run(AbstractEntityFacade.java:25)

我有其他类似的结构,它们也可以工作,但我不知道为什么这个结构不起作用

0 个答案:

没有答案