У меня возникли проблемы с преобразованием строки 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
Это делается в 'getTarget()', также выполняются запросы GET, поэтому проблем нет. –
Должен ли я понять, что вы можете вызывать запросы GET через своего клиента RESTEasy, и он работает? – Tomas