import javax.json.JsonObject; //导入方法依赖的package包/类
private JsonObject getRatings(Cookie user, String xreq, String xtraceid, String xspanid,
String xparentspanid, String xsampled, String xflags, String xotspan){
ClientBuilder cb = ClientBuilder.newBuilder();
String timeout = star_color.equals("black") ? "10000" : "2500";
cb.property("com.ibm.ws.jaxrs.client.connection.timeout", timeout);
cb.property("com.ibm.ws.jaxrs.client.receive.timeout", timeout);
Client client = cb.build();
Invocation.Builder builder = ratingsTarget.request(MediaType.APPLICATION_JSON);
if(xreq!=null) {
builder.header("x-request-id",xreq);
}
if(xtraceid!=null) {
builder.header("x-b3-traceid",xtraceid);
}
if(xspanid!=null) {
builder.header("x-b3-spanid",xspanid);
}
if(xparentspanid!=null) {
builder.header("x-b3-parentspanid",xparentspanid);
}
if(xsampled!=null) {
builder.header("x-b3-sampled",xsampled);
}
if(xflags!=null) {
builder.header("x-b3-flags",xflags);
}
if(xotspan!=null) {
builder.header("x-ot-span-context",xotspan);
}
if(user!=null) {
builder.cookie(user);
}
Response r = builder.get();
int statusCode = r.getStatusInfo().getStatusCode();
if (statusCode == Response.Status.OK.getStatusCode() ) {
StringReader stringReader = new StringReader(r.readEntity(String.class));
try (JsonReader jsonReader = Json.createReader(stringReader)) {
JsonObject j = jsonReader.readObject();
JsonObjectBuilder jb = Json.createObjectBuilder();
for(String key : j.keySet()){
int count = j.getInt(key);
String stars = "";
for(int i=0; i
stars += "";
}
stars += "";
if(count<5){
for(int i=0; i
stars += "";
}
}
jb.add(key,stars);
}
JsonObject result = jb.build();
return result;
}
}else{
return null;
}
}