Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/main/java/net/interfax/rest/client/InterFAX.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,37 @@ public APIResponse sendFax(final String faxNumber,
final File[] filesToSendAsFax,
final Optional<SendFaxOptions> options) throws IOException, URISyntaxException;

/**
* Send a combination of files and pre-uploaded/HTTP-hosted document urls as a single fax
*
* @param faxNumber number to fax to
* @param filesToSendAsFax array of files to send as fax
* @param urlsOfDocs array of urls of documents to send as fax
* @return {@link APIResponse}
* @throws IOException
* @see <a href="https://www.interfax.net/en/dev/rest/reference/2918">https://www.interfax.net/en/dev/rest/reference/2918</a>
*/
public APIResponse sendFax(final String faxNumber,
final File[] filesToSendAsFax,
final String[] urlsOfDocs) throws IOException, URISyntaxException;

/**
* Send a combination of files and pre-uploaded/HTTP-hosted document urls as a single fax, with additional
* {@link SendFaxOptions}
*
* @param faxNumber number to fax to
* @param filesToSendAsFax array of files to send as fax
* @param urlsOfDocs array of urls of documents to send as fax
* @param options {@link SendFaxOptions} to use when sending the fax
* @return {@link APIResponse}
* @throws IOException
* @see <a href="https://www.interfax.net/en/dev/rest/reference/2918">https://www.interfax.net/en/dev/rest/reference/2918</a>
*/
public APIResponse sendFax(final String faxNumber,
final File[] filesToSendAsFax,
final String[] urlsOfDocs,
final Optional<SendFaxOptions> options) throws IOException, URISyntaxException;

/**
* Send an array of input streams as a fax with additional {@link SendFaxOptions}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.glassfish.jersey.client.RequestEntityProcessing;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.media.multipart.BodyPart;
import org.glassfish.jersey.media.multipart.MultiPart;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
Expand Down Expand Up @@ -123,6 +124,38 @@ public APIResponse sendFax(final String faxNumber,
return sendMultiPartFax(faxNumber, multiPart, options);
}

@Override
public APIResponse sendFax(final String faxNumber, final File[] filesToSendAsFax, final String[] urlsOfDocs)
throws IOException, URISyntaxException {

return sendFax(faxNumber, filesToSendAsFax, urlsOfDocs, Optional.empty());
}

@Override
public APIResponse sendFax(final String faxNumber,
final File[] filesToSendAsFax,
final String[] urlsOfDocs,
final Optional<SendFaxOptions> options) throws IOException, URISyntaxException {

MultiPart multiPart = new MultiPart();
int count = 1;
for (File file : filesToSendAsFax) {
String contentType = tika.detect(file);
String entityName = "file"+count++;
FileDataBodyPart fileDataBodyPart = new FileDataBodyPart(entityName, file, MediaType.valueOf(contentType));
multiPart.bodyPart(fileDataBodyPart);
}

for (String urlOfDoc : urlsOfDocs) {
BodyPart urlBodyPart = new BodyPart("", MediaType.TEXT_PLAIN_TYPE);
urlBodyPart.getHeaders().add("Content-Location", urlOfDoc);
urlBodyPart.getHeaders().add("Content-Length", "0");
multiPart.bodyPart(urlBodyPart);
}

return sendMultiPartFax(faxNumber, multiPart, options);
}

@Override
public APIResponse sendFax(String faxNumber,
InputStream[] streamsToSendAsFax,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@ public void testSendMultipleFilesAsFaxWithOptions() throws Exception {

}

@Test
public void testSendMixOfFilesAndUrlsAsFax() throws Exception {

String absoluteFilePath = this.getClass().getClassLoader().getResource("test.pdf").getFile();
File file = new File(absoluteFilePath);

File[] files = {file};
String[] urlsOfDocs = {"https://rest.interfax.net/outbound/documents/mixed-test-doc"};

InterFAX interFAX = new DefaultInterFAXClient();
APIResponse apiResponse = interFAX.sendFax(faxNumber, files, urlsOfDocs);
Assert.assertEquals("[https://rest.interfax.net/outbound/faxes/667457901]", apiResponse.getHeaders().get("Location").toString());
Assert.assertEquals(201, apiResponse.getStatusCode());
}

@Test
public void testSendMixOfFilesAndUrlsAsFaxWithOptions() throws Exception {

String absoluteFilePath = this.getClass().getClassLoader().getResource("test.pdf").getFile();
File file = new File(absoluteFilePath);

File[] files = {file};
String[] urlsOfDocs = {"https://rest.interfax.net/outbound/documents/mixed-test-doc"};

SendFaxOptions sendFaxOptions = new SendFaxOptions();
sendFaxOptions.setPageSize(Optional.of("a4"));

InterFAX interFAX = new DefaultInterFAXClient();
APIResponse apiResponse = interFAX.sendFax(faxNumber, files, urlsOfDocs, Optional.of(sendFaxOptions));
Assert.assertEquals("[https://rest.interfax.net/outbound/faxes/667457902]", apiResponse.getHeaders().get("Location").toString());
Assert.assertEquals(201, apiResponse.getStatusCode());
}

@Test
public void testSendMultipleInputStreamsAsFax() throws Exception {

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"uuid" : "c7b2f7c1-3a4e-4e9f-ad2b-7b3c9f0d1e22",
"request" : {
"url" : "/outbound/faxes?faxNumber=%2B442084978672&pageSize=a4",
"headers": {
"Authorization": {
"equalTo" : "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
},
"Content-Type": {
"matches" : "multipart/mixed.*"
}
},
"method" : "POST",
"bodyPatterns" : [ {
"matches" : "(?s).*test\\.pdf.*Content-Location: https://rest\\.interfax\\.net/outbound/documents/mixed-test-doc.*"
} ]
},
"response" : {
"status" : 201,
"bodyFileName" : "body-outbound-faxes-mixed-files-and-urls-with-options.json",
"headers" : {
"Cache-Control" : "private",
"Content-Type" : "text/json",
"Location" : "https://rest.interfax.net/outbound/faxes/667457902",
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods" : "*",
"Access-Control-Allow-Headers" : "Content-Type, Access-Control-Allow-Headers, Access-Control-Request-Method, Authorization, X-Requested-With, Origin, Accept, Accept-Encoding, Accept-Language, Connection, Host, Referer, User-Agent, Content-Disposition",
"Date" : "Fri, 30 Sep 2016 13:33:45 GMT"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"uuid" : "b6a1e6b0-2f3d-4d8e-9c1a-6a2b8f9c0d11",
"request" : {
"url" : "/outbound/faxes?faxNumber=%2B442084978672",
"headers": {
"Authorization": {
"equalTo" : "Basic dXNlcm5hbWU6cGFzc3dvcmQ="
},
"Content-Type": {
"matches" : "multipart/mixed.*"
}
},
"method" : "POST",
"bodyPatterns" : [ {
"matches" : "(?s).*test\\.pdf.*Content-Location: https://rest\\.interfax\\.net/outbound/documents/mixed-test-doc.*"
} ]
},
"response" : {
"status" : 201,
"bodyFileName" : "body-outbound-faxes-mixed-files-and-urls.json",
"headers" : {
"Cache-Control" : "private",
"Content-Type" : "text/json",
"Location" : "https://rest.interfax.net/outbound/faxes/667457901",
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods" : "*",
"Access-Control-Allow-Headers" : "Content-Type, Access-Control-Allow-Headers, Access-Control-Request-Method, Authorization, X-Requested-With, Origin, Accept, Accept-Encoding, Accept-Language, Connection, Host, Referer, User-Agent, Content-Disposition",
"Date" : "Fri, 30 Sep 2016 13:33:45 GMT"
}
}
}