Skip to content

Commit

Permalink
printer-uri in send-document operation contains port number
Browse files Browse the repository at this point in the history
  • Loading branch information
oboehm committed Jul 10, 2018
1 parent bf2e3a3 commit cbd5917
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public ByteBuffer getIppHeader(URL url, Map<String, String> map) throws Unsuppor
assert(url != null);
ByteBuffer ippBuf = ByteBuffer.allocateDirect(bufferSize);
ippBuf = IppTag.getOperation(ippBuf, operationID);
ippBuf = IppTag.getUri(ippBuf, "printer-uri", stripPortNumber(url));
ippBuf = IppTag.getUri(ippBuf, "printer-uri", url.toString());
ippBuf = IppTag.getInteger(ippBuf, "job-id", jobId);
ippBuf = IppTag.getBoolean(ippBuf, "last-document", lastDocument);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@
*/
package org.cups4j.operations.ipp;

import ch.ethz.vppserver.ippclient.IppResponse;
import ch.ethz.vppserver.ippclient.IppResult;
import org.cups4j.ipp.attributes.Attribute;
import org.cups4j.ipp.attributes.AttributeGroup;
import org.cups4j.operations.IppOperation;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

/**
* Klasse AbstractIppOperationTest.
*
Expand Down Expand Up @@ -63,4 +71,25 @@ protected static URL createURL(String url) {
}
}

protected static void checkAttribute(ByteBuffer buffer, String name, String expectedValue) {
IppResponse ippResponse = new IppResponse();
try {
buffer.rewind();
IppResult ippResult = ippResponse.getResponse(buffer);
for (AttributeGroup group : ippResult.getAttributeGroupList()) {
for (Attribute attr : group.getAttribute()) {
if (name.equals(attr.getName())) {
String value = attr.getValue();
assertEquals(expectedValue, value);
return;
}
}
}
} catch (IOException ioe) {
throw new IllegalArgumentException("invalid ByteBuffer " + buffer, ioe);
}
fail("Attribute '" + name + "' not found.");
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.cups4j.operations.ipp;

import ch.ethz.vppserver.ippclient.IppResponse;
import ch.ethz.vppserver.ippclient.IppResult;
import org.cups4j.CupsPrinter;
import org.cups4j.CupsPrinterTest;
Expand All @@ -10,7 +9,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -44,26 +42,6 @@ public void testGetIppHeader() throws UnsupportedEncodingException {

}

private static void checkAttribute(ByteBuffer buffer, String name, String expectedValue) {
IppResponse ippResponse = new IppResponse();
try {
buffer.rewind();
IppResult ippResult = ippResponse.getResponse(buffer);
for (AttributeGroup group : ippResult.getAttributeGroupList()) {
for (Attribute attr : group.getAttribute()) {
if (name.equals(attr.getName())) {
String value = attr.getValue();
assertEquals(expectedValue, value);
return;
}
}
}
} catch (IOException ioe) {
throw new IllegalArgumentException("invalid ByteBuffer " + buffer, ioe);
}
fail("Attribute '" + name + "' not found.");
}

private static byte[] toByteArray(ByteBuffer buffer) {
byte[] array = new byte[buffer.limit()];
buffer.get(array);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class IppSendDocumentOperationTest extends AbstractIppOperationTest {
public void testGetIppHeader() throws UnsupportedEncodingException {
ByteBuffer buffer = getIppHeader(operation);
assertEquals(6, buffer.get(3));
checkAttribute(buffer, "printer-uri", "http://localhost:631/printers/test-printer");
}

/**
Expand Down

0 comments on commit cbd5917

Please sign in to comment.