MCPcopy Create free account
hub / github.com/apache/solr / postData

Method postData

solr/core/src/java/org/apache/solr/cli/PostTool.java:939–1009  ·  view source on GitHub ↗

Reads data from the data stream and posts it to solr, writes to the response to output @return true if success

(
      InputStream data, Long length, OutputStream output, String type, URI uri)

Source from the content-addressed store, hash-verified

937 * @return true if success
938 */
939 public boolean postData(
940 InputStream data, Long length, OutputStream output, String type, URI uri) {
941 if (dryRun) {
942 return true;
943 }
944
945 if (!params.isEmpty()) {
946 try {
947 uri = new URI(appendParam(uri.toString(), params));
948 } catch (URISyntaxException e) {
949 warn("Malformed params");
950 }
951 }
952
953 boolean success = true;
954 if (type == null) {
955 type = DEFAULT_CONTENT_TYPE;
956 }
957 HttpURLConnection urlConnection = null;
958 try {
959 try {
960 urlConnection = (HttpURLConnection) (uri.toURL()).openConnection();
961 try {
962 urlConnection.setRequestMethod("POST");
963 } catch (ProtocolException e) {
964 warn("Shouldn't happen: HttpURLConnection doesn't support POST??" + e);
965 }
966 urlConnection.setDoOutput(true);
967 urlConnection.setDoInput(true);
968 urlConnection.setUseCaches(false);
969 urlConnection.setAllowUserInteraction(false);
970 urlConnection.setRequestProperty("Content-type", type);
971 basicAuth(urlConnection);
972 if (null != length) {
973 urlConnection.setFixedLengthStreamingMode(length);
974 } else {
975 urlConnection.setChunkedStreamingMode(-1); // use JDK default chunkLen, 4k in Java 8.
976 }
977 urlConnection.connect();
978 } catch (IOException e) {
979 warn("Connection error (is Solr running at " + solrUpdateUrl + " ?): " + e);
980 success = false;
981 } catch (Exception e) {
982 warn("POST failed with error " + e.getMessage());
983 }
984
985 try (final OutputStream out = urlConnection.getOutputStream()) {
986 pipe(data, out);
987 } catch (IOException e) {
988 warn("IOException while posting data: " + e);
989 }
990
991 try {
992 success &= checkResponseCode(urlConnection);
993 try (final InputStream in = urlConnection.getInputStream()) {
994 pipe(in, output);
995 }
996 } catch (IOException e) {

Callers 5

doArgsModeMethod · 0.95
doStdinModeMethod · 0.95
webCrawlMethod · 0.95
postFileMethod · 0.95
getLinksFromWebPageMethod · 0.80

Calls 11

appendParamMethod · 0.95
warnMethod · 0.95
basicAuthMethod · 0.95
pipeMethod · 0.95
checkResponseCodeMethod · 0.95
getOutputStreamMethod · 0.80
toStringMethod · 0.65
connectMethod · 0.65
getInputStreamMethod · 0.65
isEmptyMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected