in modules/core/src/main/java/org/apache/savan/atom/AtomEventingClient.java [172:233]
public void publishWithREST(String serviceurl, final OMElement content, String topic)
throws SavanException {
// Create an instance of HttpClient.
HttpClient client = new HttpClient();
StringBuffer queryUrl = new StringBuffer(serviceurl);
if (!serviceurl.endsWith("/")) {
queryUrl.append("/");
}
queryUrl.append("publish");
if (topic != null) {
queryUrl.append("?").append(EventingConstants.ElementNames.Topic).append("=")
.append(topic);
}
PostMethod method = new PostMethod(queryUrl.toString());
// Request content will be retrieved directly
// from the input stream
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
content.serialize(out);
out.flush();
final byte[] data = out.toByteArray();
RequestEntity entity = new RequestEntity() {
public void writeRequest(OutputStream outstream)
throws IOException {
outstream.write(data);
}
public boolean isRepeatable() {
return false;
}
public String getContentType() {
return "text/xml";
}
public long getContentLength() {
return data.length;
}
};
method.setRequestEntity(entity);
// Execute the method.
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK && statusCode != HttpStatus.SC_ACCEPTED) {
throw new SavanException("Method failed: " + method.getStatusLine());
}
} catch (IOException e) {
throw new SavanException(e);
} catch (XMLStreamException e) {
throw new SavanException(e);
} finally {
// Release the connection.
method.releaseConnection();
}
}