gcube-cms-suite/geoportal-client/src/main/java/org/gcube/application/geoportal/client/ResponseCommons.java

26 lines
833 B
Java
Raw Normal View History

2022-03-07 13:59:24 +01:00
package org.gcube.application.geoportal.client;
2022-05-13 18:41:43 +02:00
import lombok.extern.slf4j.Slf4j;
2022-03-07 13:59:24 +01:00
import org.gcube.application.geoportal.client.utils.Serialization;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.rmi.RemoteException;
2022-05-13 18:41:43 +02:00
@Slf4j
2022-03-07 13:59:24 +01:00
public class ResponseCommons {
2022-05-13 18:41:43 +02:00
protected static<R> R check(Response resp, Class<R> clazz) throws Exception {
2022-03-07 13:59:24 +01:00
String resString=resp.readEntity(String.class);
if(resp.getStatus()<200||resp.getStatus()>=300)
2022-05-13 18:41:43 +02:00
throw new Exception("RESP STATUS IS "+resp.getStatus()+". Message : "+resString);
log.debug("Resp String is "+resString);
2022-03-07 13:59:24 +01:00
if(clazz!=null)
2022-05-13 18:41:43 +02:00
if (clazz==String.class)
return (R) resString;
else
return Serialization.read(resString, clazz);
2022-03-07 13:59:24 +01:00
else return null;
}
}