Allow empty content in request

This commit is contained in:
Greg Schueler 2014-04-04 11:40:24 -07:00
parent b5f4ec8ccd
commit 0cb3da88ec
2 changed files with 15 additions and 0 deletions

View file

@ -310,6 +310,8 @@ class ApiCall {
}else if(apiPath.getXmlDocument()!=null) { }else if(apiPath.getXmlDocument()!=null) {
httpPost.setHeader("Content-Type", "application/xml"); httpPost.setHeader("Content-Type", "application/xml");
httpPost.setEntity(new EntityTemplate(new DocumentContentProducer(apiPath.getXmlDocument()))); httpPost.setEntity(new EntityTemplate(new DocumentContentProducer(apiPath.getXmlDocument())));
}else if(apiPath.isEmptyContent()){
//empty content
}else { }else {
throw new IllegalArgumentException("No Form or Multipart entity for POST content-body"); throw new IllegalArgumentException("No Form or Multipart entity for POST content-body");
} }

View file

@ -50,6 +50,7 @@ class ApiPathBuilder {
private InputStream contentStream; private InputStream contentStream;
private File contentFile; private File contentFile;
private String contentType; private String contentType;
private boolean emptyContent = false;
/** Marker for using the right separator between parameters ("?" or "&") */ /** Marker for using the right separator between parameters ("?" or "&") */
private boolean firstParamDone = false; private boolean firstParamDone = false;
@ -308,6 +309,15 @@ class ApiPathBuilder {
} }
return this; return this;
} }
/**
* When POSTing a request, send an empty request.
*
* @return this, for method chaining
*/
public ApiPathBuilder emptyContent() {
this.emptyContent=true;
return this;
}
/** /**
* When POSTing a request, add the given XMl Document as the content of the request. * When POSTing a request, add the given XMl Document as the content of the request.
* *
@ -403,6 +413,9 @@ class ApiPathBuilder {
return contentFile; return contentFile;
} }
public boolean isEmptyContent() {
return emptyContent;
}
/** /**
* BuildsParameters can add URL or POST parameters to an {@link ApiPathBuilder} * BuildsParameters can add URL or POST parameters to an {@link ApiPathBuilder}
* *