Hello, for some reason my program freezes during second/third use of my
Uploading Page method (RESTful API). How can I fix this?
Here is my authentication method:
public void connectMethod(CloseableHttpClient client, String scheme, String
host, Integer port, String login, String password) throws
ClientProtocolException, IOException{
ConnectionThread = new Thread(new Runnable(){
public void run(){
HttpHost targetHost = new HttpHost(host, port, scheme);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials(login, password));
InetAddress address;
AuthCache authCache = new BasicAuthCache();
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);
HttpGet httpget = new HttpGet("/");
//for (int i = 0; i < 3; i++) {
try{
CloseableHttpResponse response;
response = client.execute(targetHost, httpget, context);
logArea.setText("Авторизация№" + counter + " " +
response.getStatusLine().toString());
counter++;
HttpEntity entity = response.getEntity();
response.close();
} catch (IOException e){
e.printStackTrace();
logArea.setText(e.getMessage());
}
//}
}
});
ConnectionThread.start();
}
And my Upload Method:
public void SendTestPage(CloseableHttpClient client){
UploadingThread = new Thread(new Runnable(){
public void run(){
JAXBContext context;
ObjectFactory factory = new ObjectFactory();
Page page = factory.createPage();
// Page page = new Page();
page.setName("TestPage");
//page.setTitle("TestPageTitle");
page.setContent(logArea.getText());
page.setParent("Kiss");
try {
context = JAXBContext.newInstance("org.xwiki.rest.model.jaxb");
Unmarshaller unmarshaller = context.createUnmarshaller();
Marshaller marshaller = context.createMarshaller();
String name = page.getName();
System.out.println(name);
name = URLEncoder.encode(name, "UTF-8");
//page.setName(name);
//page.setXwikiRelativeUrl("http://www.xwiki.org/rel/page");
HttpPut putMethod = new HttpPut(checkAccessField.getText());
putMethod.addHeader("Accept", "application/xml");
putMethod.addHeader("Accept-Ranges", "bytes");
Page p = new Page();
p.setContent(page.getContent());
p.setTitle(page.getTitle());
p.setParent(page.getParent());
StringWriter writer = new StringWriter();
marshaller.marshal(page, writer);
System.out.println("WRITER = [[[[" + writer + "]]]]");
StringEntity entity = new StringEntity(writer.toString(), "UTF-8");
entity.setContentType("application/xml");
putMethod.setEntity(entity);
//putMethod.setEntity(new StringEntity("My shit", "UTF-8"));
client.execute(putMethod);
} catch (IOException e){
e.printStackTrace();
logArea.setText(e.getMessage());
}
finally {
return;
}
}
});
UploadingThread.start();
}
--
View this message in context:
http://xwiki.475771.n2.nabble.com/xWiki-RESTful-API-HttpPut-tp7599270.html
Sent from the XWiki- Users mailing list archive at
Nabble.com.