Skip to content

Commit

Permalink
Merge pull request #83 from nicolasmoreau/dev
Browse files Browse the repository at this point in the history
HEAD request returned with a status = 204
  • Loading branch information
nicolasmoreau authored Jul 12, 2018
2 parents f2e12c1 + 596de8b commit c719165
Showing 1 changed file with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public enum Response{
Response(String description){
this.description = description;
}

public String getDescription(){
return this.description;
}

}

private String ivoaID;
Expand All @@ -59,10 +59,10 @@ public HttpHeadResponse(){
}

public HttpHeadResponse(String ivoaID, HttpURLConnection connection) {
retrieveHeaders(connection);
this.ivoaID = ivoaID;
this.fullQueryURL = connection.getURL().toString();
this.status = retrieveStatus(connection);
retrieveHeaders(connection);
this.status = retrieveStatus(connection);
if (truncated>0 && truncated<100)
this.status=Response.TRUNCATED;
}
Expand Down Expand Up @@ -94,7 +94,7 @@ private int getValue( HttpURLConnection connection,String headerName){
return 0;
}
}

private int getTruncatedValue( HttpURLConnection connection,String headerName ){
try{
String val = connection.getHeaderField(headerName);
Expand Down Expand Up @@ -131,11 +131,32 @@ private Response retrieveStatus(HttpURLConnection connection){
@Id @GeneratedValue
public Integer getRecordID() { return recordID; }
public void setRecordID(Integer recordID) { this.recordID = recordID; }

public String getIvoaID() { return ivoaID; }
public void setIvoaID(String ivoaID) { this.ivoaID = ivoaID; }

public Response getStatus() { return status; }

/**
* if a node answers a HEAD request, there is no content and the
* response code can be 204
* In that case, if data have been found ( processes + species + states > 0 )
* we return a OK status instead of EMPTY
* @return
*/
public Response getStatus() {
try {
int total = processes + species + states;
if(total > 0) {
return Response.OK;
}else {
return status;
}
}catch(Exception e) {
e.printStackTrace();
return status;
}
}


public void setStatus(Response status) { this.status = status; }
@Transient
public String getStatusDescription() {return status.getDescription();}
Expand All @@ -155,18 +176,18 @@ public boolean isLastModSet(){
public int getNonRadiative() { return nonRadiative; }
public int getCollisions() { return collisions; }
public String getRequestToken(){ return requestToken; }

@Transient
public int getTruncated() { return truncated; }

public void setSpecies(int species) { this.species = species; }
public void setStates(int states) { this.states = states; }
public void setProcesses(int processes) { this.processes = processes; }
public void setRadiative(int radiative) { this.radiative = radiative; }
public void setNonRadiative(int nonRadiative) { this.nonRadiative = nonRadiative; }
public void setCollisions(int collisions) { this.collisions = collisions; }
public void setRequestToken(String token){ this.requestToken = token; }

@Lob
public String getFullQueryURL() { return fullQueryURL; }
public void setFullQueryURL(String fullQueryURL) { this.fullQueryURL = fullQueryURL; }
Expand All @@ -179,6 +200,6 @@ public boolean isLastModSet(){

@Transient
public boolean isOk(){
return this.status==Response.OK || this.status == Response.TRUNCATED;
return this.getStatus()==Response.OK || this.getStatus() == Response.TRUNCATED;
}
}

0 comments on commit c719165

Please sign in to comment.