AnsweredAssumed Answered

Creating site is working sometimes, why

Question asked by nareshvy on Dec 9, 2016
Latest reply on Dec 9, 2016 by ddraper

Hi I am creating a site here, but this sometimes works and sometimes not working.
try {
HttpClient client = new HttpClient();

String loginData = "username=admin&password=admin";
PostMethod loginPost = new PostMethod(
"http://127.0.0.1:8090/share/page/dologin");
loginPost.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
loginPost.setRequestEntity(new StringRequestEntity(loginData,
"text/plain", "UTF-8"));

System.out.println("dologin script status: "
+ client.executeMethod(loginPost));

GetMethod authenticationGet = new GetMethod(
"http://127.0.0.1:8090/share/service/modules/authenticated?a=user");
System.out.println("User is authenticated script status : "
+ client.executeMethod(authenticationGet));

PostMethod createSitePost = new PostMethod(
"http://127.0.0.1:8090/share/service/modules/create-site");
String shortName = "TestSiteFromCodeONeTwo";
JSONObject siteObject = new JSONObject();

siteObject.put("shortName", shortName);
siteObject.put("description", shortName);
siteObject.put("title", shortName);
siteObject.put("Visiblity", "Public");
siteObject.put("sitePreset", "site-dashboard");

createSitePost.setRequestEntity(new StringRequestEntity(siteObject
.toString(), "application/json", "UTF-8"));
createSitePost.setRequestHeader("Accept", "application/json");
// createSitePost.setRequestHeader("Content-Type", "application/json");

int status = client.executeMethod(createSitePost);
System.out.println("create a site script status :: " + status);

 

 

getting error 

create a site script status :: 400

Outcomes