2017-02-10 12:51:04 +01:00
|
|
|
package org.gcube.common.calls.jaxrs;
|
|
|
|
|
|
|
|
import javax.ws.rs.client.Client;
|
|
|
|
import javax.ws.rs.client.ClientBuilder;
|
|
|
|
import javax.ws.rs.client.WebTarget;
|
|
|
|
import javax.xml.ws.EndpointReference;
|
|
|
|
|
|
|
|
import org.glassfish.jersey.client.ClientProperties;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
public class TargetFactory implements TargetFactoryDSL.AtClause{
|
|
|
|
|
|
|
|
private static Logger log = LoggerFactory.getLogger(TargetFactory.class);
|
|
|
|
|
|
|
|
private GcubeService target;
|
|
|
|
|
|
|
|
public static TargetFactory stubFor(GcubeService target){
|
|
|
|
return new TargetFactory(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private TargetFactory(GcubeService target) {
|
|
|
|
this.target = target;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public WebTarget at(String address) {
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
2018-07-04 15:52:19 +02:00
|
|
|
Client client = ClientBuilder.newClient()
|
|
|
|
.property(ClientProperties.FOLLOW_REDIRECTS, Boolean.FALSE)
|
2018-07-05 12:38:05 +02:00
|
|
|
.property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024);
|
2018-06-20 17:27:08 +02:00
|
|
|
|
2017-02-10 12:51:04 +01:00
|
|
|
/*
|
|
|
|
String resourceAddress = address.substring(0, address.indexOf("/service"));
|
|
|
|
|
|
|
|
WebTarget resourcetarget = client.target(resourceAddress).path("/resource/");
|
|
|
|
|
|
|
|
int status = resourcetarget.request().get().getStatus();
|
|
|
|
|
|
|
|
if (status!=200)
|
|
|
|
throw new Exception();*/
|
|
|
|
|
|
|
|
WebTarget webTarget = client.target(address).path(target.path());
|
|
|
|
|
|
|
|
webTarget.register(new JaxRSRequestFilter(target));
|
|
|
|
|
|
|
|
return webTarget;
|
|
|
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
log.error("error building service",e);
|
|
|
|
throw new RuntimeException("error building service",e);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public WebTarget at(EndpointReference endpoint){
|
|
|
|
return at(new JaxRSEndpointReference(endpoint).address);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|