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;








1















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.










share|improve this question




























    1















    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.










    share|improve this question
























      1












      1








      1








      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 22:15









      Anand VeeraswamyAnand Veeraswamy

      243 bronze badges




      243 bronze badges






















          2 Answers
          2






          active

          oldest

          votes


















          0














          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);







          share|improve this answer




















          • 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


















          0














          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);







          share|improve this answer

























            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
            );



            );













            draft saved

            draft discarded


















            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









            0














            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);







            share|improve this answer




















            • 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















            0














            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);







            share|improve this answer




















            • 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













            0












            0








            0







            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);







            share|improve this answer















            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);








            share|improve this answer














            share|improve this answer



            share|improve this answer








            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












            • 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













            0














            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);







            share|improve this answer



























              0














              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);







              share|improve this answer

























                0












                0








                0







                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);







                share|improve this answer













                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);








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 26 at 12:51









                Anand VeeraswamyAnand Veeraswamy

                243 bronze badges




                243 bronze badges



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?