Hi Leute,
ich moechte folgendes Objekt von einem Client an einem REST Service senden.
Die Klasse hat zwei kleine Wrapper Klassen ->
Ich benutze zum marshallen der Objekte Jackson in der Version 2.2.1 und Jersey als REST Service in version 1.17.1.
Die erzeugte JSON Datei scheint aber valide zu sein. Aus irgendeinen Grund kann er nicht senden.
Ich habe auch eine zweite Klasse, namens PhoenixTask(ohne die 2), dort funktioniert es wunderbar. Am Sendeprozess scheint es also nicht direkt zu liegen, sondern die Klasse, die gesendet werden soll.
Weiß wer rat? Die Fehlermeldung ist ein wenig generisch.
ich moechte folgendes Objekt von einem Client an einem REST Service senden.
Java:
public class PhoenixTask2 implements Sendable {
private String description;
private List<PhoenixAttachment> attachments;
private List<PhoenixText> pattern;
public PhoenixTask2(String description, List<File> fileAttachments, List<File> filePattern) throws IOException {
// Erstellung von der Klasse
}
}
public String getDescription() {
return description;
}
public List<PhoenixText> getPattern() {
return new ArrayList<PhoenixText>(pattern);
}
public List<PhoenixAttachment> getAttachments() {
return new ArrayList<PhoenixAttachment>(attachments);
}
@Override
public ClientResponse send(WebResource rs) {
return rs.type(MediaType.APPLICATION_JSON_TYPE).post(ClientResponse.class, this);
}
}
Die Klasse hat zwei kleine Wrapper Klassen ->
Java:
public class PhoenixAttachment {
private byte[] content;
private Date creationDate;
private String name;
private String type;
public PhoenixAttachment(File file, Date creationDate) throws IOException {
read(file);
this.creationDate = creationDate;
this.name = file.getName();
int fileSeperator = name.lastIndexOf('.');
this.type = name.substring(fileSeperator + 1);
name = name.substring(0, fileSeperator);
}
private void read(File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
content = new byte[(int) file.length()];
fis.read(content);
fis.close();
}
@JsonIgnore
public File getFile() throws IOException {
File f = File.createTempFile(name, type);
f.deleteOnExit();
FileOutputStream fout = new FileOutputStream(f);
fout.write(content);
fout.close();
return f;
}
@JsonIgnore
public InputStream getStream() {
return new ByteArrayInputStream(content);
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public Date getCreationDate() {
return creationDate;
}
public byte[] getContent() {
return Arrays.copyOf(content, content.length);
}
}
Java:
public class PhoenixText {
private String content;
private Date creationDate;
private String name;
private String type;
public PhoenixText(File file, Date creationDate) throws IOException {
read(file);
this.creationDate = creationDate;
this.name = file.getName();
int fileSeperator = name.lastIndexOf('.');
this.type = name.substring(fileSeperator + 1);
name = name.substring(0, fileSeperator);
}
private void read(File file) throws IOException {
FileInputStream fis = new FileInputStream(file);
byte[] tmp = new byte[(int) file.length()];
fis.read(tmp);
fis.close();
this.content = new String(tmp);
}
public String getText() {
return content;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public Date getCreationDate() {
return creationDate;
}
}
Ich benutze zum marshallen der Objekte Jackson in der Version 2.2.1 und Jersey als REST Service in version 1.17.1.
Die erzeugte JSON Datei scheint aber valide zu sein. Aus irgendeinen Grund kann er nicht senden.
Ich habe auch eine zweite Klasse, namens PhoenixTask(ohne die 2), dort funktioniert es wunderbar. Am Sendeprozess scheint es also nicht direkt zu liegen, sondern die Klasse, die gesendet werden soll.
Weiß wer rat? Die Fehlermeldung ist ein wenig generisch.