ERR_INCOMPLETE_CHUNKED_ENCODING on angularjs - rest服务使用高级REST客户端返回无限json文件,但 Postman 出错

c6ubokkw  于 2023-03-22  发布在  Angular
关注(0)|答案(2)|浏览(142)

我遇到了一个非常奇怪的问题。在angular(用ionic v1构建的应用程序)中,我调用了一些java中构建的REST调用,但出现了一些问题,chrome建议我使用以下错误:

有趣的代码是这样的,angular js中的REST服务:

bankaccountsbyuser: function(_getbauser, _error){
            var currentToken = _GetToken();
  
            if(currentToken!=null){
                var Headers = {
                    token: currentToken.tokenUser,
                };
            }
            
            _timerTokenControl(currentToken, _error);
            
            if (setupTime == null) {
                console.log("token scaduto");
                //modificare
                //$window.location.href="login.html";
            }
            

            if (currentToken !== null) {
            $http({  
                        method : 'GET',  
                        headers: Headers,
                        url : REST_URL+'bankaccount'
                    }).then(function successCallback(response) {  
                        console.log(response)
                        _getbauser(response)
                    }, function errorCallback(response) {  
                        console.log(response.statusText);  
                    });  
               }  else {
                   var alertPopup = $ionicPopup.alert({
                         title: 'Accesso negato!',
                         template: 'Devi essere un utente registrato, non sei loggato!'
                     });
                    console.log("NON SEI LOGGATO!!!");
            }
        },

调试:

你可以看到,get REST服务返回了一个错误,因此,让我们看看这个用java构建的REST服务:

package it.jack.fdd.services;

import java.util.List;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import it.jack.fdd.dao.FactoryDao;
import it.jack.fdd.dao.impl.BankAccountDaoImpl;
import it.jack.fdd.dao.interfaces.BankAccountDao;
import it.jack.fdd.domain.BankAccount;
import it.jack.fdd.domain.User;
import it.jack.fdd.dto.TokenUserDto;
import it.jack.fdd.dto.UserDto;
import it.jack.fdd.util.ConverterDTO;

@Path("/bankaccount")
public class BankAccountServices {

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public List<BankAccount> getBankAccountOfUser() {
   
		BankAccountDao baDao = new BankAccountDaoImpl();
		List<BankAccount> balist = baDao.getBAByUserId(1);		
		return balist;

	}

我尝试在方法中传递数字“1”,只是为了简化。该方法的实现如下:

package it.jack.fdd.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import it.jack.fdd.dao.interfaces.BankAccountDao;
import it.jack.fdd.domain.BankAccount;
import it.jack.fdd.domain.Staff;
import it.jack.fdd.domain.User;
import it.jack.fdd.util.HibernateUtilLezione;

public class BankAccountDaoImpl extends BaseDaoImpl<BankAccount> implements BankAccountDao{
	

	public List<BankAccount> getBAByUserId(int id) {
		
		try{
			
			Session session = HibernateUtilLezione.openSession();
			Transaction tx = session.beginTransaction();
			
			@SuppressWarnings("unchecked")
			List<BankAccount> accounts = session.createQuery("from BankAccount b "
					+ "where b.user= "+id).list();
			
			tx.commit();
			session.close();
			
			return accounts;
		}
		catch(HibernateException e){
			e.printStackTrace();
			return null;
		}
	}
	
}

如你所见,这个方法要求一个id,我把id 1放在这里只是为了检查,因为在数据库中有一个字段有这个id
[it.jack.fdd.domain.BankAccount@4f8d86e4]
我还检查了列表的维度为1(因此,只有一条记录,就像在数据库中一样,只有一条记录具有该iduser)
因此,尝试使用postman打开这个REST调用,结果如下:

奇怪的是,postman向我展示了另一个REST调用的相同结果,它以前工作过。但对于最后一个REST调用不是问题,因为奇怪的是它在我的应用程序上工作,它不仅仅在postman中工作。因此,尝试使用高级REST客户端我有一个奇怪的不同结果:

一个奇怪的,非常大的列表,每次重复相同的字段!!它就像一个循环!发生了什么?我怎么能解决?

rekjcdws

rekjcdws1#

解决了。问题出在java的域类中:当域类具有一对多关系时,必须将标记@JsonIgnore放在json filex 1c 0d1x中以避免这些重复记录
实体类:

package it.jack.fdd.domain;
// Generated 30-nov-2016 0.17.09 by Hibernate Tools 4.3.1.Final

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * BankAccount generated by hbm2java
 */
@Entity
@Table(name = "bank_account", catalog = "fdd_dbproducts")
public class BankAccount implements java.io.Serializable {

	private Integer idbankAccount;
	private User user;
	private String iban;
	private String pin;
	private String society;
	private Date expiration;

	public BankAccount() {
	}

	public BankAccount(User user, String iban, String pin, String society) {
		this.user = user;
		this.iban = iban;
		this.pin = pin;
		this.society = society;
	}

	public BankAccount(User user, String iban, String pin, String society, Date expiration) {
		this.user = user;
		this.iban = iban;
		this.pin = pin;
		this.society = society;
		this.expiration = expiration;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)

	@Column(name = "idbank_account", unique = true, nullable = false)
	public Integer getIdbankAccount() {
		return this.idbankAccount;
	}

	public void setIdbankAccount(Integer idbankAccount) {
		this.idbankAccount = idbankAccount;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "fkuser_baccount", nullable = false)
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name = "iban", nullable = false, length = 45)
	public String getIban() {
		return this.iban;
	}

	public void setIban(String iban) {
		this.iban = iban;
	}

	@Column(name = "pin", nullable = false, length = 45)
	public String getPin() {
		return this.pin;
	}

	public void setPin(String pin) {
		this.pin = pin;
	}

	@Column(name = "society", nullable = false, length = 45)
	public String getSociety() {
		return this.society;
	}

	public void setSociety(String society) {
		this.society = society;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "expiration", length = 10)
	public Date getExpiration() {
		return this.expiration;
	}

	public void setExpiration(Date expiration) {
		this.expiration = expiration;
	}

}
4ktjp1zp

4ktjp1zp2#

不仅对于一对多关系,而且对于多对多关系,将@JsonIgnore标记放在模型类中

相关问题