在将其上传到alfresco时,如何将自定义属性添加到文件中
我使用 alfresco的核心api 上传文件,上传文件我的版本我的Alfresco是社区-6.1.2 我有一个春季启动项目,可以在alfresco中上传文件,我想添加一些自定义属性 这是我的代码
URI uri = new URI(endpoint + nodeId + "/children");
LinkedMultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
String pathfile = "C:\\tmp\\alfrescorepo\\"+filename;
FileUtils.writeByteArrayToFile(new File(pathfile), bytefile);
File file = new File(pathfile);
params.add("filedata", new FileSystemResource(file));
params.add("majorVersion", true);
params.add("versioningEnabled", true);
JsonObject customProperties = new JsonObject();
customProperties.addProperty("title", "sample");
customProperties.addProperty("dataType", "cm:text");
customProperties.addProperty("description", "example");
customProperties.addProperty("defaultValue", "10");
params.add("properties", customProperties);
HttpEntity<Map<String, String>> request = new HttpEntity(params,headers);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new RestTemplateResponseErrorHandler());
ResponseEntity<NodeEntry> response = restTemplate.postForEntity(uri, request, NodeEntry.class);
return response.getBody().getEntry();
,我有这个错误
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: JsonObject; nested exception is com.fasterxml.jackson.databind.JsonMappingException: JsonObject (through reference chain: com.google.gson.JsonObject["asBoolean"])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:465)
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.writeInternal(AbstractGenericHttpMessageConverter.java:113)
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:227)
at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:541)
at org.springframework.http.converter.FormHttpMessageConverter.writeParts(FormHttpMessageConverter.java:517)
at org.springframework.http.converter.FormHttpMessageConverter.writeMultipart(FormHttpMessageConverter.java:497)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:369)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:156)
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:991)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:774)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:751)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:486)
at com.xpfibre.alfresco.repository.file.FileAlfrescoRepository.create(FileAlfrescoRepository.java:105)
at com.xpfibre.alfresco.repository.AlfrescoRepositoryApplication.main(AlfrescoRepositoryApplication.java:41)
... 5 more
Caused by: com.fasterxml.jackson.databind.JsonMappingException: JsonObject (through reference chain: com.google.gson.JsonObject["asBoolean"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:392)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:351)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:782)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1518)
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1007)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:456)
... 18 more
Caused by: java.lang.UnsupportedOperationException: JsonObject
at com.google.gson.JsonElement.getAsBoolean(JsonElement.java:153)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:689)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:774)
... 24 more
I use the CORE API of Alfresco to upload a file my version of alfresco is Community - 6.1.2
I have a spring boot project that upload a file in alfresco and I want to add some custom properties
Here is my code
URI uri = new URI(endpoint + nodeId + "/children");
LinkedMultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
String pathfile = "C:\\tmp\\alfrescorepo\\"+filename;
FileUtils.writeByteArrayToFile(new File(pathfile), bytefile);
File file = new File(pathfile);
params.add("filedata", new FileSystemResource(file));
params.add("majorVersion", true);
params.add("versioningEnabled", true);
JsonObject customProperties = new JsonObject();
customProperties.addProperty("title", "sample");
customProperties.addProperty("dataType", "cm:text");
customProperties.addProperty("description", "example");
customProperties.addProperty("defaultValue", "10");
params.add("properties", customProperties);
HttpEntity<Map<String, String>> request = new HttpEntity(params,headers);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new RestTemplateResponseErrorHandler());
ResponseEntity<NodeEntry> response = restTemplate.postForEntity(uri, request, NodeEntry.class);
return response.getBody().getEntry();
And I have this error
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: JsonObject; nested exception is com.fasterxml.jackson.databind.JsonMappingException: JsonObject (through reference chain: com.google.gson.JsonObject["asBoolean"])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:465)
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.writeInternal(AbstractGenericHttpMessageConverter.java:113)
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:227)
at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:541)
at org.springframework.http.converter.FormHttpMessageConverter.writeParts(FormHttpMessageConverter.java:517)
at org.springframework.http.converter.FormHttpMessageConverter.writeMultipart(FormHttpMessageConverter.java:497)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:369)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:156)
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:991)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:774)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:751)
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:486)
at com.xpfibre.alfresco.repository.file.FileAlfrescoRepository.create(FileAlfrescoRepository.java:105)
at com.xpfibre.alfresco.repository.AlfrescoRepositoryApplication.main(AlfrescoRepositoryApplication.java:41)
... 5 more
Caused by: com.fasterxml.jackson.databind.JsonMappingException: JsonObject (through reference chain: com.google.gson.JsonObject["asBoolean"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:392)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:351)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:316)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:782)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319)
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1518)
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1007)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:456)
... 18 more
Caused by: java.lang.UnsupportedOperationException: JsonObject
at com.google.gson.JsonElement.getAsBoolean(JsonElement.java:153)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:689)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:774)
... 24 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的错误是关于布尔参数的:
params
majorversion
和versioningEnabled
需要在URL中添加为参数:加上,如果您想使用alfresco的基本属性,例如desctiption和标题,您的JSON应该看起来像这样:
如果要添加自定义类型和自定义属性,则需要将自定义内容模型添加到Alfresco,请参阅:
<
关于自定义内容模型的好教程
Your error is about boolean parameters:
The params
majorVersion
andversioningEnabled
need to be added as parameters in the Url :Plus, if you want to use basic properties of alfresco like desctiption and title, your Json should look like this :
If you want to add custom types and custom properties, you need to add custom content model to Alfresco, see:
Alfresco Docs : Content models |
Good Tutorial About custom content models