0

I am sending a GET request from my Angular client to the Java Vertx server where I am doing some operation on the server. Now at the end of the operation on the server, I send a message to the client notifying it that the operation has finished. But for some reason the API stays in the 204 and does not return 200 OK in the Network tab of the browser. But in the console I get to see the string which I send to the client. Please see image to clarify things.

Component class

startPrint(id: string) {
    console.log('Insdie startPrint() ::: JobID ',id);    
    let jobStatus = this.job_status.get(Number(id));    
    this.toggle(jobStatus, Number(id));

    if(jobStatus =='START')
    {
      console.log('INSIDE IF!!');
      
      this.coreService.getJobSerialToPrint(id).subscribe(
        (next) => {
          console.log("response in startPrint: " + JSON.stringify(next));
          console.log("response in startPrint: "+ next);
        },
        (err) => {
          console.log("error in response in startPrint: " + err);
        }
      );
    }
    else{
      console.log('INSIDE ELSE ---- Need to Pause Job on server');
    }
  }

Service class

//Start printing label for Job
  getJobSerialToPrint(id: string) {
      console.log("Send start print command to server!!: ", id);
    return this.httpClient.get(environment.restUrl + "/jobserials/"+id);
  }

Vertx code

startPrintJob(jobID, context)
    .onFailure(error -> {
        LOG.debug("startTest() Failed: ", error);
    })
    .onSuccess(res -> {
        LOG.debug("Finished !!");       
        LOG.debug(" onSuccess for startPrintJob()   " + res);
        
        String updatedStatus = "Job finished printing "+jobID;
        context.response().setStatusCode(HttpResponseStatus.OK.code())
        .putHeader(HttpHeaders.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON)
        .end(new JsonObject().put("message", updatedStatus)
                             .put("path", context.normalizedPath()).toBuffer()
                             );
    })

enter image description here

console image

enter image description here

user3840170
  • 26,597
  • 4
  • 30
  • 62
ZAJ
  • 793
  • 3
  • 23
  • 50
  • 1
    Try to `encode` your `JsonObject`, instead of `toBuffer`: `new JsonObject().put(...).encode()` – W.S. Jul 17 '22 at 14:34

1 Answers1

0

The problem was not code based but I had to uncheck the 3rd party request option in the console.Thant was the reason becasue it was filtering out my http status codes(200,201).

ZAJ
  • 793
  • 3
  • 23
  • 50