* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rv.apiVersion = apiVersion;
return rv;
}
-
+
protected abstract Rcli<CT> clone(URI uri, SecuritySetter<CT> ss);
-
+
public abstract void invalidate() throws CadiException;
public Rcli<CT> readTimeout(int millis) {
this.apiVersion = apiVersion;
return this;
}
-
+
public boolean isApiVersion(String prospective) {
return apiVersion.equals(prospective);
}
@Override
public void transfer(OutputStream os) throws IOException, APIException {
PrintStream ps;
- if(os instanceof PrintStream) {
+ if (os instanceof PrintStream) {
ps = (PrintStream)os;
} else {
ps = new PrintStream(os);
}
boolean first = true;
- for(String fp : formParam) {
- if(fp!=null) {
- if(first) {
+ for (String fp : formParam) {
+ if (fp!=null) {
+ if (first) {
first = false;
} else {
ps.print('&');
}
- if(fp.endsWith("=")) {
+ if (fp.endsWith("=")) {
first = true;
}
ps.print(fp);
/**
* Read String, using POST for keyInfo
- *
+ *
* @param pathinfo
* @param df
* @param t
*/
public<T,R> Future<R> readPost(String pathinfo, final RosettaDF<T> df, final T t, final RosettaDF<R> resp) throws APIException, CadiException {
final ParsePath pp = new ParsePath(pathinfo);
-
+
EClient<CT> client = client();
client.setMethod(POST);
client.addHeader(CONTENT_TYPE,typeString(df.getTypeClass()));
public Future<String> read(String pathinfo, String accept, String ... headers) throws APIException, CadiException {
final ParsePath pp = new ParsePath(pathinfo);
-
+
EClient<CT> client = client();
client.setMethod(GET);
client.addHeader(ACCEPT, accept);
-
- for(int i=1;i<headers.length;i=i+2) {
+
+ for (int i=1;i<headers.length;i=i+2) {
client.addHeader(headers[i-1],headers[i]);
}
client.setPathInfo(pp.path());
EClient<CT> client = client();
client.setMethod(GET);
client.addHeader(ACCEPT, accept);
- for(int i=1;i<headers.length;i=i+2) {
+ for (int i=1;i<headers.length;i=i+2) {
client.addHeader(headers[i-1],headers[i]);
}
client.setPathInfo(pp.path());
EClient<CT> client = client();
client.setMethod(GET);
client.addHeader(ACCEPT, typeString(df.getTypeClass()));
- for(int i=1;i<headers.length;i=i+2) {
+ for (int i=1;i<headers.length;i=i+2) {
client.addHeader(headers[i-1],headers[i]);
}
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
client.setFragment(pp.frag());
-
+
client.setPayload(null);
client.send();
return client.futureRead(df,type);
client.addHeader(ACCEPT, typeString(cls));
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
client.setPayload(null);
client.send();
client.addHeader(CONTENT_TYPE,contentType);
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
client.setPayload(new EClient.Transfer() {
@Override
public void transfer(OutputStream os) throws IOException, APIException {
client.send();
return client.future(t);
}
-
+
public<T> Future<String> updateRespondString(String pathinfo, final RosettaDF<T> df, final T t) throws APIException, CadiException {
final ParsePath pp = new ParsePath(pathinfo);
-
+
EClient<CT> client = client();
client.setMethod(PUT);
client.addHeader(CONTENT_TYPE, typeString(df.getTypeClass()));
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
client.setPayload(new EClient.Transfer() {
@Override
client.send();
return client.futureReadString();
}
-
+
public Future<String> update(String pathinfo, String contentType, EClient.Transfer content) throws APIException, CadiException {
final ParsePath pp = new ParsePath(pathinfo);
client.addHeader(CONTENT_TYPE, typeString(df.getTypeClass()));
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
-
+ client.setFragment(pp.frag());
+
client.setPayload(new EClient.Transfer() {
@Override
public void transfer(OutputStream os) throws IOException, APIException {
client.send();
return client.future(t);
}
-
+
public<T> Future<T> update(String pathinfo, Class<?> cls, final RosettaDF<T> df, final T t) throws APIException, CadiException {
final ParsePath pp = new ParsePath(pathinfo);
-
+
EClient<CT> client = client();
client.setMethod(PUT);
client.addHeader(CONTENT_TYPE, typeString(cls));
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
client.setPayload(new EClient.Transfer() {
@Override
client.send();
return client.future(t);
}
-
+
/**
client.addHeader(CONTENT_TYPE, typeString(Void.class));
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
// client.setPayload(new EClient.Transfer() {
// @Override
client.send();
return client.future(null);
}
-
+
public<T> Future<T> delete(String pathinfo, String contentType, final RosettaDF<T> df, final T t) throws APIException, CadiException {
final ParsePath pp = new ParsePath(pathinfo);
client.addHeader(CONTENT_TYPE, contentType);
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
client.setPayload(new EClient.Transfer() {
@Override
client.addHeader(CONTENT_TYPE, typeString(cls));
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
client.setPayload(new EClient.Transfer() {
@Override
public void transfer(OutputStream os) throws IOException, APIException {
client.addHeader(CONTENT_TYPE, typeString(df.getTypeClass()));
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
client.setPayload(new EClient.Transfer() {
@Override
public void transfer(OutputStream os) throws IOException, APIException {
client.addHeader(CONTENT_TYPE, typeString(cls));
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
client.setPayload(null);
client.send();
client.addHeader(CONTENT_TYPE, contentType);
client.setPathInfo(pp.path());
client.setQueryParams(pp.query());
- client.setFragment(pp.frag());
+ client.setFragment(pp.frag());
client.setPayload(null);
client.send();
throw new CadiException("Invalid incoming URI",e);
}
String name;
- for(Enumeration<String> en = req.getHeaderNames();en.hasMoreElements();) {
+ for (Enumeration<String> en = req.getHeaderNames();en.hasMoreElements();) {
name = en.nextElement();
client.addHeader(name,req.getHeader(name));
}
client.setPathInfo(pathParam);
String meth = req.getMethod();
client.setMethod(meth);
- if(!"GET".equals(meth)) {
+ if (!"GET".equals(meth)) {
client.setPayload(new EClient.Transfer() {
@Override
public void transfer(OutputStream os) throws IOException, APIException {
int read;
// reuse Buffers
Pooled<byte[]> pbuff = buffPool.get();
- try {
- while((read=is.read(pbuff.content))>=0) {
+ try {
+ while ((read=is.read(pbuff.content))>=0) {
os.write(pbuff.content,0,read);
}
} finally {
public ParsePath(final String origPath) {
path = origPath;
- if(origPath==null) {
+ if (origPath==null) {
query=queryEnd=pound=-1;
queryParams=null;
} else {
query = origPath.indexOf('?');
pound = origPath.indexOf('#');
queryEnd = pound>=0?pound:path.length();
- if(oneCallQueryParams==null) {
- if(query>=0) {
- queryParams = path.substring(query+1,queryEnd);
+ if (oneCallQueryParams==null) {
+ if (query>=0) {
+ queryParams = path.substring(query+1,queryEnd);
} else {
queryParams=null;
}
} else {
- if(query>=0) {
- queryParams = oneCallQueryParams + '&' + path.substring(query+1,queryEnd);
+ if (query>=0) {
+ queryParams = oneCallQueryParams + '&' + path.substring(query+1,queryEnd);
} else {
queryParams = oneCallQueryParams;
}
}
}
}
-
+
public String path() {
- if(query>=0) {
- if(pound>=0) {
+ if (query>=0) {
+ if (pound>=0) {
return path.substring(pound+1);
}
return path.substring(0,query);
- } else if(pound>=0) {
+ } else if (pound>=0) {
return path.substring(0,pound);
} else {
return path;
}
}
-
+
public String query() {
return queryParams;
}
-
+
public String frag() {
- if(pound>=0) {
+ if (pound>=0) {
return path.substring(pound+1);
} else {
return null;