Файл, созданный в папке Folder в Alfresco

Я пытаюсь создать папку в Alfresco, используя XMSI ниже код, который я использую.

public static void main (String [] args) выдает Exception { long start = System.currentTimeMillis();

    String host = "127.0.0.1";
    int port = 9080;
    String username = "admin";
    String password = "admin";
    String parentFolder = "Company%20Home";
    String folderName = "sales3";
    String description = "sales space3";

    RulesRequest request  = new RulesRequest();
    //request.setRemediationProfileObj(remediationProfile);
    Gson gs = new Gson();
    String json = gs.toJson(request);
    DefaultHttpClient client = new DefaultHttpClient();
    RestClient rstClnt = new RestClient();
    String  ticket = rstClnt.restClientPost(json, "http://127.0.0.10:9080/alfresco/service/api/login?u=admin&pw=admin", client);
    //String url = "http://" + host + ":" + port + "/alfresco/service/api/path/workspace/SpacesStore/" + parentFolder + "/children";
    String url = "http://localhost:9080/alfresco/service/cmis/s/workspace:SpacesStore/i/078b05c6-14bd-439c-a1ae-db032c5d98fc/children?alf_ticket="+ticket;

    String contentType = "application/atom+xml;type=entry";

    String xml = 
        "<?xml version='1.0' encoding='utf-8'?>\n" +
        "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:cmis='http://www.cmis.org/2008/05'>\n" +
        "<title>" + folderName + "</title>\n" +
        "<summary>" + description + "</summary>\n" +
        "<cmis:object>\n"+
        "<cmis:properties>\n" +
        "<cmis:propertyString cmis:name='cmis:objectTypeId'>\n" +
        "<cmis:value>cmis:folder</cmis:value>\n" +
        "</cmis:propertyString>\n" +
        "</cmis:properties>\n" +
        "</cmis:object>\n" +
        "</entry>\n"; 




    DefaultHttpClient httpclient = new DefaultHttpClient();

    httpclient.getCredentialsProvider().setCredentials(
            new AuthScope(host, port),
            new UsernamePasswordCredentials(username, password));

    HttpPost httppost = new HttpPost(url);
    httppost.setHeader("Content-type", contentType);

    StringEntity requestEntity = new StringEntity(xml, "UTF-8");
    httppost.setEntity(requestEntity);


    System.out.println("executing request" + httppost.getRequestLine());
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();

    System.out.println("----------------------------------------");
    System.out.println(response.getStatusLine());
    if (entity != null) {
        System.out.println("Response content type: " + entity.getContentType());
        long contentLength = entity.getContentLength();
        System.out.println("Response content length: "
                + entity.getContentLength());

        if (contentLength > 0) {
            byte [] b = new byte[(int) contentLength];
            entity.getContent().read(b);
            System.out.println("Response content: " + new String(b));
        }

        entity.writeTo(System.out);
    }

    // When HttpClient instance is no longer needed,
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
    long end = System.currentTimeMillis();
    System.out.println("Time spend: " + (end-start) + "ms");
}

Вместо создания папки создается файл размером 0.

Спасибо Гарвит

1 ответ

Ваша собственность не того типа. Вы неправильно используете cmis:propertyString вместо cmis:propertyId Попробуйте следующее

<cmis:propertyId propertyDefinitionId="cmis:objectTypeId">
    <cmis:value>cmis:folder</cmis:value>
</cmis:propertyId>

Как говорит @Gagravarr, подобных проблем легко избежать, если использовать хорошо известные клиентские библиотеки. Если вы сами создаете HTTP-запросы, у вас должна быть на то веская причина.

Другие вопросы по тегам