我无法将示例cURL字符串(即有效)转换为有意义的resteasy表达式。卷曲是:将cURL字符串转换为Resteasy
curl -X POST -u admin:admin --data-binary "@tempfile.xml" http://localhost:8810/rest/configurations
我:
public void sendPost(ConfigurationDTO config) throws JAXBException, FileNotFoundException {
// client target is: http://localhost:8810/rest
ResteasyWebTarget target = getTarget();
target.path("configurations");
JAXBContext context = JAXBContext.newInstance(ConfigurationDTO.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
// this here produces exactly what I need
marshaller.marshal(config, new File("test.xml"));
MultipartFormDataOutput dataOutput = new MultipartFormDataOutput();
dataOutput.addFormData("file", new FileInputStream(new File("test.xml")), MediaType.APPLICATION_OCTET_STREAM_TYPE);
GenericEntity<MultipartFormDataOutput> entity = new GenericEntity<MultipartFormDataOutput>(dataOutput) {};
Response response = target.request().post(Entity.entity(entity, MediaType.MULTIPART_FORM_DATA_TYPE));
response.close();
}
protected ResteasyWebTarget getTarget() {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromUri(restUrl).build());
client.register(new AddAuthHeadersRequestFilter(user, pass));
return target;
}
抛出HTTP.500,我没有对服务器的访问,看看发生了什么。
首先我错过了代码中的用户密码信息。 – Tomas 2014-10-03 11:34:43
它在'getTarget()'中完成,GET请求也可以工作,所以没有问题。 – 2014-10-03 11:37:41
我是否应该理解您可以通过RESTEasy客户端调用GET请求,并且它可以工作? – Tomas 2014-10-03 11:40:52