SOLR-3012: Move System.getProperty(type) in postData() to main()

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1229602 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Koji Sekiguchi 2012-01-10 15:35:31 +00:00
parent 3b8458f6de
commit 6a085c2fa9
2 changed files with 49 additions and 17 deletions

View File

@ -394,6 +394,11 @@ Documentation
================== 3.6.0 ==================
Upgrading from Solr 3.5
----------------------
* As doGet() methods in SimplePostTool was changed to static, the client applications of this
class need to be recompiled.
New Features
----------------------
* SOLR-2904: BinaryUpdateRequestHandler should be able to accept multiple update requests from
@ -421,10 +426,12 @@ New Features
Optimizations
----------------------
* SOLR-1931 Speedup for LukeRequestHandler and admin/schema browser. New parameter
* SOLR-1931: Speedup for LukeRequestHandler and admin/schema browser. New parameter
reportDocCount defaults to 'false'. Old behavior still possible by specifying this as 'true'
(Erick Erickson)
* SOLR-3012: Move System.getProperty("type") in postData() to main() and add type argument so that
the client applications of SimplePostTool can set content type via method argument. (koji)
Bug Fixes
----------------------

View File

@ -44,7 +44,7 @@ public class SimplePostTool {
private static final String DEFAULT_OPTIMIZE = "no";
private static final String DEFAULT_OUT = "no";
private static final String DEFAULT_DATA_TYPE = "application/xml";
public static final String DEFAULT_DATA_TYPE = "application/xml";
private static final String DATA_MODE_FILES = "files";
private static final String DATA_MODE_ARGS = "args";
@ -89,6 +89,7 @@ public class SimplePostTool {
}
OutputStream out = null;
final String type = System.getProperty("type", DEFAULT_DATA_TYPE);
URL u = null;
try {
@ -111,7 +112,7 @@ public class SimplePostTool {
if (DATA_MODE_FILES.equals(mode)) {
if (0 < args.length) {
info("POSTing files to " + u + "..");
t.postFiles(args, 0, out);
t.postFiles(args, 0, out, type);
} else {
info("No files specified. (Use -h for help)");
}
@ -120,13 +121,13 @@ public class SimplePostTool {
if (0 < args.length) {
info("POSTing args to " + u + "..");
for (String a : args) {
t.postData(SimplePostTool.stringToStream(a), null, out);
t.postData(SimplePostTool.stringToStream(a), null, out, type);
}
}
} else if (DATA_MODE_STDIN.equals(mode)) {
info("POSTing stdin to " + u + "..");
t.postData(System.in, null, out);
t.postData(System.in, null, out, type);
}
if ("yes".equals(System.getProperty("commit",DEFAULT_COMMIT))) {
info("COMMITting Solr index changes..");
@ -142,15 +143,24 @@ public class SimplePostTool {
fatal("RuntimeException " + e);
}
}
/** Post all filenames provided in args, return the number of files posted*/
/**
* @deprecated use {@link #postData(InputStream, Integer, OutputStream, String)} instead
*/
@Deprecated
int postFiles(String [] args,int startIndexInArgs, OutputStream out) {
final String type = System.getProperty("type", DEFAULT_DATA_TYPE);
return postFiles(args, startIndexInArgs, out, type);
}
/** Post all filenames provided in args, return the number of files posted*/
int postFiles(String [] args,int startIndexInArgs, OutputStream out, String type) {
int filesPosted = 0;
for (int j = startIndexInArgs; j < args.length; j++) {
File srcFile = new File(args[j]);
if (srcFile.canRead()) {
info("POSTing file " + srcFile.getName());
postFile(srcFile, out);
postFile(srcFile, out, type);
filesPosted++;
} else {
warn("Cannot read input file: " + srcFile);
@ -198,17 +208,25 @@ public class SimplePostTool {
return url + (url.indexOf('?')>0 ? "&" : "?") + param;
}
/**
* @deprecated use {@link #postFile(File, OutputStream, String)} instead
*/
public void postFile(File file, OutputStream output) {
final String type = System.getProperty("type", DEFAULT_DATA_TYPE);
postFile(file, output, type);
}
/**
* Opens the file and posts it's contents to the solrUrl,
* writes to response to output.
* @throws UnsupportedEncodingException
*/
public void postFile(File file, OutputStream output) {
public void postFile(File file, OutputStream output, String type) {
InputStream is = null;
try {
is = new FileInputStream(file);
postData(is, (int)file.length(), output);
postData(is, (int)file.length(), output, type);
} catch (IOException e) {
fatal("Can't open/read file: " + file);
} finally {
@ -224,7 +242,7 @@ public class SimplePostTool {
* Performs a simple get on the given URL
* @param url
*/
public void doGet(String url) {
public static void doGet(String url) {
try {
doGet(new URL(url));
} catch (MalformedURLException e) {
@ -236,7 +254,7 @@ public class SimplePostTool {
* Performs a simple get on the given URL
* @param url
*/
public void doGet(URL url) {
public static void doGet(URL url) {
try {
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
if (HttpURLConnection.HTTP_OK != urlc.getResponseCode()) {
@ -248,13 +266,20 @@ public class SimplePostTool {
}
}
/**
* @deprecated use {@link #postData(InputStream, Integer, OutputStream, String)} instead
*/
@Deprecated
public void postData(InputStream data, Integer length, OutputStream output) {
final String type = System.getProperty("type", DEFAULT_DATA_TYPE);
postData(data, length, output, type);
}
/**
* Reads data from the data stream and posts it to solr,
* writes to the response to output
*/
public void postData(InputStream data, Integer length, OutputStream output) {
final String type = System.getProperty("type", DEFAULT_DATA_TYPE);
public void postData(InputStream data, Integer length, OutputStream output, String type) {
HttpURLConnection urlc = null;
try {
@ -308,7 +333,7 @@ public class SimplePostTool {
}
}
private static InputStream stringToStream(String s) {
public static InputStream stringToStream(String s) {
InputStream is = null;
try {
is = new ByteArrayInputStream(s.getBytes("UTF-8"));
@ -320,7 +345,7 @@ public class SimplePostTool {
/**
* Pipes everything from the source to the dest. If dest is null,
* then everything is read fro msource and thrown away.
* then everything is read from source and thrown away.
*/
private static void pipe(InputStream source, OutputStream dest) throws IOException {
byte[] buf = new byte[1024];