我想编写一个上传json String的Java REST Client。我有关于webservice和C ++代码的描述,但这对我没有帮助。不幸的是,我在网上找到的解决方案对我不起作用。 Web服务的描述声明必须使用MultiPart。
这个描述对我没什么帮助。我正在努力创建MultiPart,在尝试发布数据时会得到一个非常长的异常堆栈。代码段如下:
Client client = ClientBuilder.newBuilder()
.register(MultiPartFeature.class)
.build();
WebTarget target = client.target(baseUri + "/FileHandler?projectRecId="+projectRecId+"&versionRecId="+versionRecId+"&updateSchedules=true");
MultivaluedMap<String, String> info = new MultivaluedHashMap<String, String>();
info.add("FileTypeRecId", scheduleGuid);
info.add("CreatedUpdatedBy", user);
info.add("actualFileName", scheduleFileName);
info.add("MetaData","PROJECTID:" + projektIdFromJson + ";EINBAUDATUM:" + einbaudatumFromJson);
MultiPart infoPart = new MultiPart();
infoPart.contentDisposition(FormDataContentDisposition.name("ObjectInfo").build());
infoPart.bodyPart(new BodyPart().entity(info));
MultiPart filePart = new MultiPart();
filePart.contentDisposition(FormDataContentDisposition.name(scheduleFileName).build());
filePart.bodyPart(scheduleJson, MediaType.APPLICATION_JSON_TYPE);
MultiPart multiPartEntity = new MultiPart()
.bodyPart(infoPart)
.bodyPart(filePart);
Response response = target.request(MediaType.MULTIPART_FORM_DATA)
.header("Authorization", "xxx")
.post(Entity.entity(multiPartEntity, multiPartEntity.getMediaType()));
例外明星:
Aug 19, 2015 10:37:14 AM org.glassfish.jersey.internal.Errors logErrors
WARNUNG: The following warnings have been detected: WARNING: HK2 service reification failed for [org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide] with an exception:
MultiException stack 1 of 2
java.lang.NoClassDefFoundError: org/jvnet/mimepull/MIMEParsingException
...
Caused by: java.lang.ClassNotFoundException: org.jvnet.mimepull.MIMEParsingException
...
MultiException stack 2 of 2
java.lang.IllegalArgumentException: Errors were discovered while reifying SystemDescriptor( implementation=org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide
contracts={javax.ws.rs.ext.MessageBodyReader}
scope=javax.inject.Singleton
qualifiers={org.glassfish.jersey.internal.inject.Custom}
descriptorType=CLASS
descriptorVisibility=NORMAL
metadata=
rank=0
loader=null
proxiable=null
proxyForSameScope=null
analysisName=null
id=70
locatorId=1
identityHashCode=1763344271
reified=false)
...
这些HK2错误中有更多错误,我可以提供所需的全部信息。
我现在知道我做错了什么,你们有没有想法?
答案 0 :(得分:0)
我认为你错过了项目中的以下罐子。
1. mimepull.jar
2. jersey-multipart.jar