Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

i have been working on android project that has node.js backend that communicate with database in sql server and IOException keeps showing to me:

caused by java.io.EOFException: \n not found: limit=0 content=…

this is the whole stack trace:

W/System.err: java.io.IOException: unexpected end of stream on Connection{10.0.2.2:1433, proxy=DIRECT hostAddress=/10.0.2.2:1433 cipherSuite=none protocol=http/1.1}
                  at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:208)
                  at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
                  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
                  at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
                  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
                  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
                  at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
                  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
                  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
                  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
                  at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
                  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
                  at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
                  at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
                  at okhttp3.RealCall.execute(RealCall.java:92)
                  at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
                  at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:41)
                  at io.reactivex.Observable.subscribe(Observable.java:12036)
                  at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
W/System.err:     at io.reactivex.Observable.subscribe(Observable.java:12036)
                  at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
                  at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:579)
                  at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
                  at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
                  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                  at java.lang.Thread.run(Thread.java:761)
W/System.err: Caused by: java.io.EOFException: \n not found: limit=0 content=…
W/System.err:     at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:236)
                  at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:215)
                  at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
                ... 29 more

i been watching, reading tutorials to make sure that i build the API and the connection code right and reading other people that have the same problem and doing what they did none of this fixed my problem.

this is my node.js code:

var postData = req.body; // get post params
       var userId = uid.v4();
       const userExistQuery = 'SELECT email, first_name, last_name FROM User WHERE email = @email AND category = @category AND password = @password';
    if(postData.category.valueOf() == new String("Seller").valueOf()){
        connection.request()
        .input('email', sql.VarChar(45), postData.email)
        .input('password', sql.VarChar(45), postData.password)
        .input('category', sql.VarChar(45), postData.category)
             .query(userExistQuery)
             .then((recordSet)=>{
             if(recordSet.rowsAffected == 1){
                res.json("Already registered as Seller.");
              }else{
                var streetNum = postData.streetNum;
                var buildingNum = postData.buildingNum;
                var apartmentNum = postData.apartmentNum;
                var town = postData.town;
                var governance = postData.governance;
                var floorNum = postData.floorNum;
                var poBox = postData.poBox;
                var zipCode = postData.zipCode;
                var creditInfo = postData.creditInfo;
                const addSellerQuery =
                'INSERT INTO Seller(seller_id, street#, building#, apartment#, town, governance, floor#, P.O_box, zip_code, credit_info, first_name, last_name, email, password, phone_number ,category) VALUES(@sellerId,@streetNum,@buildingNum,@apartmentNum,@town,@governance,@floorNum,@poBox,@zipCode,@creditInfo,@firstName,@lastName,@email,@password, @phoneNumber, @category)';
 connection.request()
 .input('sellerId', sql.VarChar(45), userId)
 .input('streetNum', sql.VarChar(45), postData.streetNum)
 .input('buildingNum', sql.VarChar(45), postData.buildingNum)
 .input('apartmentNum', sql.VarChar(45), postData.apartmentNum)
 .input('town', sql.VarChar(45), postData.town)
 .input('governance', sql.VarChar(45), postData.governance)
 .input('floorNum', sql.VarChar(45), postData.floorNum)
 .input('poBox', sql.VarChar(45), postData.poBox)
 .input('zipCode', sql.VarChar(45), postData.zipCode)
 .input('creditInfo', sql.VarChar(45), postData.creditInfo)
 .input('firstName', sql.VarChar(45), postData.firstName)
 .input('lastName', sql.VarChar(45), postData.lastName)
 .input('email', sql.VarChar(45), postData.email)
 .input('password', sql.VarChar(45), postData.password)
 .input('phoneNumber', sql.VarChar(45), postData.phoneNumber)
 .input('category', sql.VarChar(45), postData.category)
.query(addSellerQuery)
.then((recordAdded)=>{
  if(recordAdded.rowsAffected == 1){
    res.json(dataPost.firstName + "Registered as Seller.");
  }else{
    res.json(dataPost.firstName + "failed to register as Seller.");

and this is my retrofit code:

public static Retrofit getRetrofit() {
    if (retrofit == null) {
        OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
                .connectTimeout(120, TimeUnit.SECONDS)
                .readTimeout(120, TimeUnit.SECONDS)
                .writeTimeout(120, TimeUnit.SECONDS)
                .build();
        retrofit = new Retrofit.Builder()
                .baseUrl("http://10.0.2.2:1433/")
                .client(okHttpClient)
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
    return retrofit;

this code how i get the data from the api:

 compositeSubs.add(myAPI.buyerSignUp(buyer.getEmail(), buyer.getName().split(" ")[0]
                        , buyer.getName().split(" ")[1], buyer.getPassword(), buyer.bringType(), buyer.getPhoneNumber())
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(s -> {   // onNext method
                            Log.d(TAG, "onPreExecute get data from api");
                            ((AuthListener) callBack).onSignUp(s, compositeSubs, false);
                            Log.d(TAG, "onPreExecute after get data from api");
                        }, throwable -> {   // onError method
                            Log.d(TAG, "onPreExecute getting api error");
                            throwable.printStackTrace();
                        }, () -> {          // onComplete method
                            Log.d(TAG, "onPreExecute after getting data from api");
                            Handler handler = new Handler(Looper.getMainLooper());
                            handler.post(() -> {
                                if (progressDialog.isShowing())
                                    progressDialog.dismiss();
                            Log.d(TAG, "completed");

i expect to see the new buyer is added to the buyer table in my database but this Exception prevent from adding the new buyer.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.