Fixed publisher due to changes on REST API for post and put methods
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@134409 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9c8852f225
commit
7e5556b691
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.informationsystem.resourceregistry.publisher.proxy;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -9,7 +10,6 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -112,6 +112,7 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
protected final String path;
|
||||
protected final HTTPMETHOD method;
|
||||
protected final String urlParameters;
|
||||
protected final String body;
|
||||
|
||||
protected String getParametersDataString(
|
||||
List<Map.Entry<String, String>> parameters)
|
||||
|
@ -137,7 +138,14 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public HTTPInputs(String path, HTTPMETHOD method,
|
||||
List<Map.Entry<String, String>> parameters)
|
||||
throws UnsupportedEncodingException {
|
||||
this(path, method, parameters, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path
|
||||
* @param method
|
||||
|
@ -145,33 +153,38 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public HTTPInputs(String path, HTTPMETHOD method,
|
||||
List<Map.Entry<String, String>> parameters)
|
||||
List<Map.Entry<String, String>> parameters, String body)
|
||||
throws UnsupportedEncodingException {
|
||||
super();
|
||||
this.path = path;
|
||||
this.method = method;
|
||||
this.urlParameters = getParametersDataString(parameters);
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the path
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
return this.path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the method
|
||||
*/
|
||||
public HTTPMETHOD getMethod() {
|
||||
return method;
|
||||
return this.method;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the urlParameters
|
||||
*/
|
||||
public String getUrlParameters() {
|
||||
return urlParameters;
|
||||
return this.urlParameters;
|
||||
}
|
||||
|
||||
public String getBody(){
|
||||
return this.body;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -221,13 +234,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
|
||||
connection.setRequestMethod(method.toString());
|
||||
|
||||
/*
|
||||
* if(method==HTTPMETHOD.POST){ connection.setDoOutput(true);
|
||||
* DataOutputStream wr = new
|
||||
* DataOutputStream(connection.getOutputStream());
|
||||
* wr.writeBytes(httpInputs.getUrlParameters()); wr.flush();
|
||||
* wr.close(); }
|
||||
*/
|
||||
String body = httpInputs.getBody();
|
||||
if (body!=null && (method == HTTPMETHOD.POST || method == HTTPMETHOD.PUT)) {
|
||||
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
|
||||
wr.writeBytes(body);
|
||||
wr.flush();
|
||||
wr.close();
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
@ -280,12 +293,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(facetClass.getSimpleName());
|
||||
|
||||
List<Map.Entry<String, String>> parameters = new ArrayList<>();
|
||||
parameters.add(new RREntry<String, String>(
|
||||
EntityPath.DEFINITION_PARAM, Entities.marshal(facet)));
|
||||
String body = Entities.marshal(facet);
|
||||
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
||||
HTTPMETHOD.PUT, parameters);
|
||||
HTTPMETHOD.PUT, null, body);
|
||||
|
||||
ResourceRegistryCall<F> call = new ResourceRegistryCall<>(
|
||||
facetClass, httpInputs);
|
||||
|
@ -311,12 +322,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(facet.getHeader().getUUID().toString());
|
||||
|
||||
List<Map.Entry<String, String>> parameters = new ArrayList<>();
|
||||
parameters.add(new RREntry<String, String>(
|
||||
EntityPath.DEFINITION_PARAM, Entities.marshal(facet)));
|
||||
|
||||
String body = Entities.marshal(facet);
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
||||
HTTPMETHOD.POST, parameters);
|
||||
HTTPMETHOD.POST, null, body);
|
||||
|
||||
ResourceRegistryCall<F> call = new ResourceRegistryCall<>(
|
||||
facetClass, httpInputs);
|
||||
|
@ -371,12 +380,10 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(resourceClass.getSimpleName());
|
||||
|
||||
List<Map.Entry<String, String>> parameters = new ArrayList<>();
|
||||
parameters.add(new RREntry<String, String>(
|
||||
EntityPath.DEFINITION_PARAM, Entities.marshal(resource)));
|
||||
String body = Entities.marshal(resource);
|
||||
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
||||
HTTPMETHOD.PUT, parameters);
|
||||
HTTPMETHOD.PUT, null, body);
|
||||
|
||||
ResourceRegistryCall<R> call = new ResourceRegistryCall<>(
|
||||
resourceClass, httpInputs);
|
||||
|
@ -438,15 +445,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(consistsOf.getTarget().getHeader().getUUID()
|
||||
.toString());
|
||||
|
||||
List<Map.Entry<String, String>> parameters = new ArrayList<>();
|
||||
parameters.add(new RREntry<String, String>(EntityPath.TYPE_PARAM,
|
||||
consistsOfClass.getSimpleName()));
|
||||
parameters.add(new RREntry<String, String>(
|
||||
EntityPath.PROPERTIES_PARAM, Entities.marshal(consistsOf)));
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(consistsOfClass.getSimpleName());
|
||||
|
||||
String body = Entities.marshal(consistsOf);
|
||||
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
||||
HTTPMETHOD.PUT, parameters);
|
||||
HTTPMETHOD.PUT, null, body);
|
||||
|
||||
ResourceRegistryCall<C> call = new ResourceRegistryCall<>(
|
||||
consistsOfClass, httpInputs);
|
||||
|
@ -510,17 +515,13 @@ public class ResourceRegistryPublisherImpl implements ResourceRegistryPublisher
|
|||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(isRelatedTo.getTarget().getHeader().getUUID()
|
||||
.toString());
|
||||
stringWriter.append(PATH_SEPARATOR);
|
||||
stringWriter.append(isRelatedToClass.getSimpleName());
|
||||
|
||||
List<Map.Entry<String, String>> parameters = new ArrayList<>();
|
||||
parameters.add(new RREntry<String, String>(EntityPath.TYPE_PARAM,
|
||||
isRelatedToClass.getSimpleName()));
|
||||
parameters
|
||||
.add(new RREntry<String, String>(
|
||||
EntityPath.PROPERTIES_PARAM, Entities
|
||||
.marshal(isRelatedTo)));
|
||||
String body = Entities.marshal(isRelatedTo);
|
||||
|
||||
HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(),
|
||||
HTTPMETHOD.PUT, parameters);
|
||||
HTTPMETHOD.PUT, null, body);
|
||||
|
||||
ResourceRegistryCall<I> call = new ResourceRegistryCall<>(
|
||||
isRelatedToClass, httpInputs);
|
||||
|
|
Loading…
Reference in New Issue