Apache HTTP client equivalent of CURL command to configure shapefilesGet parameter from curl command in REST web serivcejava compilation: classname Vs classname with file-extensionCompile all files in src?How do Jersey-client and Apache HTTP Client compare?Dynamically configuring Apache Http clientUpload a file from java client to a apache http serverHTTPClient Example - Exception in thread “main” java.lang.NoSuchFieldError: INSTANCEIs it possible to write a program in Java without main() using JDK 1.7 or higher?Trouble running something from the consoleConnection reset by peer: socket write error httpclient and geoserver
Four ships at the ocean with the same distance
How many Jimmys can fit?
How can a person with a similar experience with the defendant, help the plaintiff in a lawsuit?
Is space division multiplexing really multiplexing?
Wires do not connect in Circuitikz
Is this car delivery via Ebay Motors on Craigslist a scam?
Is it possible for a character at any level to cast all 44 Cantrips in one week without Magic Items?
Tesco's Burger Relish Best Before End date number
Interpretation of non-significant results as "trends"
How do "gefälligst" and "ruhig" have different tones?
How can I use my cell phone's light as a reading light?
Is there a formal/better word than "skyrocket" for the given context?
How to slice a string input at a certain unknown index
Who goes first? Person disembarking bus or the bicycle?
Passwordless authentication - how and when to invalidate a login code
Sense of humor in your sci-fi stories
Gory anime with pink haired girl escaping an asylum
Very Simple Spell (Number to Words) 001 to 999 in VBA
Other Space Shuttle O-ring failures
As a supervisor, what feedback would you expect from a PhD who quits?
Is it possible to complete a PhD in CS in 3 years?
A ring of generalized power series
Strong Password Detection in Python
Curly braces adjustment in tikz?
Apache HTTP client equivalent of CURL command to configure shapefiles
Get parameter from curl command in REST web serivcejava compilation: classname Vs classname with file-extensionCompile all files in src?How do Jersey-client and Apache HTTP Client compare?Dynamically configuring Apache Http clientUpload a file from java client to a apache http serverHTTPClient Example - Exception in thread “main” java.lang.NoSuchFieldError: INSTANCEIs it possible to write a program in Java without main() using JDK 1.7 or higher?Trouble running something from the consoleConnection reset by peer: socket write error httpclient and geoserver
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
What is the equivalent of httpclient code for the following CURL command
curl -v -u username:password-XPUT -H "Content-type: text/plain" -d "E:/path_to_shapefile/shapefiles/" "http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all"
The CURL command works fine. I have limited knowledge of httpclient, however, adapting similar code, following is my attempt:
import org.apache.http.client.fluent.*;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("username", "password")
.authPreemptive("172.16.17.86:9090");
// Line below does not compile
String response = executor.execute(Request.Put("E:/path_to_shapefile/shapefiles/"
"http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all"))
.returnResponse()
.toString();
System.out.println(response);
This code above does not compile since I do not know how to encode two urls in the same request as in the CURL command. A fix to the above code or a new approach would be appreciated.
Thanks in advance.
java apache-httpclient-4.x
add a comment |
What is the equivalent of httpclient code for the following CURL command
curl -v -u username:password-XPUT -H "Content-type: text/plain" -d "E:/path_to_shapefile/shapefiles/" "http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all"
The CURL command works fine. I have limited knowledge of httpclient, however, adapting similar code, following is my attempt:
import org.apache.http.client.fluent.*;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("username", "password")
.authPreemptive("172.16.17.86:9090");
// Line below does not compile
String response = executor.execute(Request.Put("E:/path_to_shapefile/shapefiles/"
"http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all"))
.returnResponse()
.toString();
System.out.println(response);
This code above does not compile since I do not know how to encode two urls in the same request as in the CURL command. A fix to the above code or a new approach would be appreciated.
Thanks in advance.
java apache-httpclient-4.x
add a comment |
What is the equivalent of httpclient code for the following CURL command
curl -v -u username:password-XPUT -H "Content-type: text/plain" -d "E:/path_to_shapefile/shapefiles/" "http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all"
The CURL command works fine. I have limited knowledge of httpclient, however, adapting similar code, following is my attempt:
import org.apache.http.client.fluent.*;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("username", "password")
.authPreemptive("172.16.17.86:9090");
// Line below does not compile
String response = executor.execute(Request.Put("E:/path_to_shapefile/shapefiles/"
"http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all"))
.returnResponse()
.toString();
System.out.println(response);
This code above does not compile since I do not know how to encode two urls in the same request as in the CURL command. A fix to the above code or a new approach would be appreciated.
Thanks in advance.
java apache-httpclient-4.x
What is the equivalent of httpclient code for the following CURL command
curl -v -u username:password-XPUT -H "Content-type: text/plain" -d "E:/path_to_shapefile/shapefiles/" "http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all"
The CURL command works fine. I have limited knowledge of httpclient, however, adapting similar code, following is my attempt:
import org.apache.http.client.fluent.*;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("username", "password")
.authPreemptive("172.16.17.86:9090");
// Line below does not compile
String response = executor.execute(Request.Put("E:/path_to_shapefile/shapefiles/"
"http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all"))
.returnResponse()
.toString();
System.out.println(response);
This code above does not compile since I do not know how to encode two urls in the same request as in the CURL command. A fix to the above code or a new approach would be appreciated.
Thanks in advance.
java apache-httpclient-4.x
java apache-httpclient-4.x
asked Mar 25 at 22:15
Anand VeeraswamyAnand Veeraswamy
243 bronze badges
243 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
1
I think this looks right - but if at all possible, try not to use authPreemptive - use auth(HttpHost, String, String) this way you're not sending an authentication without being challenged
– Dave G
Mar 26 at 3:36
Sorry should have clarified this. This is a client side program. The files are located on a remote server and thus the client program only needs to specify the location of the files and not include the actual file. However, I don't understand how to specify this file location in the java code.
– Anand Veeraswamy
Mar 26 at 11:04
add a comment |
Thanks for the answer. I replaced bodyFile by bodyString and that worked.
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347196%2fapache-http-client-equivalent-of-curl-command-to-configure-shapefiles%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
1
I think this looks right - but if at all possible, try not to use authPreemptive - use auth(HttpHost, String, String) this way you're not sending an authentication without being challenged
– Dave G
Mar 26 at 3:36
Sorry should have clarified this. This is a client side program. The files are located on a remote server and thus the client program only needs to specify the location of the files and not include the actual file. However, I don't understand how to specify this file location in the java code.
– Anand Veeraswamy
Mar 26 at 11:04
add a comment |
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
1
I think this looks right - but if at all possible, try not to use authPreemptive - use auth(HttpHost, String, String) this way you're not sending an authentication without being challenged
– Dave G
Mar 26 at 3:36
Sorry should have clarified this. This is a client side program. The files are located on a remote server and thus the client program only needs to specify the location of the files and not include the actual file. However, I don't understand how to specify this file location in the java code.
– Anand Veeraswamy
Mar 26 at 11:04
add a comment |
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
edited Mar 27 at 14:10
Anand Veeraswamy
243 bronze badges
243 bronze badges
answered Mar 25 at 23:04
Not a JDNot a JD
1,4021 silver badge12 bronze badges
1,4021 silver badge12 bronze badges
1
I think this looks right - but if at all possible, try not to use authPreemptive - use auth(HttpHost, String, String) this way you're not sending an authentication without being challenged
– Dave G
Mar 26 at 3:36
Sorry should have clarified this. This is a client side program. The files are located on a remote server and thus the client program only needs to specify the location of the files and not include the actual file. However, I don't understand how to specify this file location in the java code.
– Anand Veeraswamy
Mar 26 at 11:04
add a comment |
1
I think this looks right - but if at all possible, try not to use authPreemptive - use auth(HttpHost, String, String) this way you're not sending an authentication without being challenged
– Dave G
Mar 26 at 3:36
Sorry should have clarified this. This is a client side program. The files are located on a remote server and thus the client program only needs to specify the location of the files and not include the actual file. However, I don't understand how to specify this file location in the java code.
– Anand Veeraswamy
Mar 26 at 11:04
1
1
I think this looks right - but if at all possible, try not to use authPreemptive - use auth(HttpHost, String, String) this way you're not sending an authentication without being challenged
– Dave G
Mar 26 at 3:36
I think this looks right - but if at all possible, try not to use authPreemptive - use auth(HttpHost, String, String) this way you're not sending an authentication without being challenged
– Dave G
Mar 26 at 3:36
Sorry should have clarified this. This is a client side program. The files are located on a remote server and thus the client program only needs to specify the location of the files and not include the actual file. However, I don't understand how to specify this file location in the java code.
– Anand Veeraswamy
Mar 26 at 11:04
Sorry should have clarified this. This is a client side program. The files are located on a remote server and thus the client program only needs to specify the location of the files and not include the actual file. However, I don't understand how to specify this file location in the java code.
– Anand Veeraswamy
Mar 26 at 11:04
add a comment |
Thanks for the answer. I replaced bodyFile by bodyString and that worked.
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
add a comment |
Thanks for the answer. I replaced bodyFile by bodyString and that worked.
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
add a comment |
Thanks for the answer. I replaced bodyFile by bodyString and that worked.
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
Thanks for the answer. I replaced bodyFile by bodyString and that worked.
import org.apache.http.client.fluent.*;
import org.apache.http.entity.ContentType;
public class QuickStart
public static void main(String[] args) throws Exception
Executor executor = Executor.newInstance()
.auth("admin", "geoserver")
.authPreemptive("172.16.17.86:9090");
String response = executor.execute(Request.Put("http://172.16.17.86:9090/geoserver/rest/workspaces/IDIRA6/datastores/scenario2373/external.shp?configure=all")
.bodyString("E:\Tomcat\apache-tomcat-8.5.37\webapps\geoserver\data\data\IDIRA6\scenario2373\", ContentType.create("text/plain")))
.returnResponse()
.toString();
System.out.println(response);
answered Mar 26 at 12:51
Anand VeeraswamyAnand Veeraswamy
243 bronze badges
243 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55347196%2fapache-http-client-equivalent-of-curl-command-to-configure-shapefiles%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown