Skip to content

Commit

Permalink
merged with poc branch
Browse files Browse the repository at this point in the history
  • Loading branch information
oboehm committed Jul 14, 2018
1 parent be12abb commit 3715a8a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 97 deletions.
22 changes: 2 additions & 20 deletions src/main/java/ch/ethz/vppserver/ippclient/IppResponse.java
Expand Up @@ -145,12 +145,8 @@ public IppResult getResponse(ByteBuffer buffer) throws IOException {
// read IPP header
if ((!ippHeaderResponse) && (buffer.hasRemaining())) {
_buf = buffer;
if (buffer.get(0) > 0x20) {
return parseErrorText();
} else {
result.setIppStatusResponse(getIPPHeader());
ippHeaderResponse = true;
}
result.setIppStatusResponse(getIPPHeader());
ippHeaderResponse = true;
}

_buf = buffer;
Expand Down Expand Up @@ -225,20 +221,6 @@ private String getIPPHeader() {
return null;
}

private IppResult parseErrorText() {
IppResult result = new IppResult();
byte[] buffer = new byte[_buf.capacity() - _buf.position()];
_buf.get(buffer);
String errorText = new String(buffer);
if (errorText.contains("Unauthorized")) {
result.setIppStatusResponse("client-error-not-authorized (0x403)");
} else {
result.setIppStatusResponse("unknown");
}
result.setIppStatusMessage(errorText);
return result;
}

/**
* <p>
* <strong>Note:</strong> Global variables <code>_attributeGroupResult</code>,
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/ch/ethz/vppserver/ippclient/IppResult.java
Expand Up @@ -23,7 +23,6 @@
public class IppResult {
private String httpStatusResponse = null;
private String ippStatusResponse = null;
private String ippStatusMessage = null;
private List<AttributeGroup> attributeGroupList = null;
private int httpStatusCode;

Expand Down Expand Up @@ -62,22 +61,6 @@ public void setIppStatusResponse(String statusResponse) {
ippStatusResponse = statusResponse;
}

/**
*
* @return
*/
public String getIppStatusMessage() {
return ippStatusMessage;
}

/**
*
* @param statusResponse
*/
public void setIppStatusMessage(String statusResponse) {
ippStatusMessage = ippStatusMessage;
}

/**
*
* @return
Expand Down
34 changes: 8 additions & 26 deletions src/main/java/org/cups4j/CupsClient.java
Expand Up @@ -15,14 +15,18 @@
* <http://www.gnu.org/licenses/>.
*/

import java.net.URL;
import java.util.List;

import org.cups4j.operations.IppOperation;
import org.cups4j.operations.cups.CupsGetDefaultOperation;
import org.cups4j.operations.cups.CupsGetPrintersOperation;
import org.cups4j.operations.cups.CupsMoveJobOperation;
import org.cups4j.operations.ipp.*;

import java.net.URL;
import java.util.List;
import org.cups4j.operations.ipp.IppCancelJobOperation;
import org.cups4j.operations.ipp.IppGetJobAttributesOperation;
import org.cups4j.operations.ipp.IppGetJobsOperation;
import org.cups4j.operations.ipp.IppHoldJobOperation;
import org.cups4j.operations.ipp.IppReleaseJobOperation;

/**
* Main Client for accessing CUPS features like
Expand Down Expand Up @@ -172,28 +176,6 @@ public CupsPrinter getPrinter(URL printerURL) throws Exception {
return printer;
}

/**
* Returns the printer with the given name. The search of the name is
* not case sensitiv.
*
* @param name name of the printer
* @return printer
*/
public CupsPrinter getPrinter(String name) {
try {
List<CupsPrinter> printers = getPrinters();
CupsPrinter printer = null;
for (CupsPrinter p : printers) {
if (name.equalsIgnoreCase(p.getName())) {
return p;
}
}
throw new IllegalArgumentException("not a valid printer name: " + name);
} catch (Exception ex) {
throw new IllegalStateException("cannot get printers", ex);
}
}

/**
* Returns job attributes for the job associated with the provided jobID
*
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/cups4j/PrintJob.java
Expand Up @@ -277,9 +277,4 @@ public String getResolution() {
return resolution;
}

@Override
public String toString() {
return this.getClass().getSimpleName() + " '" + jobName + "'";
}

}
25 changes: 4 additions & 21 deletions src/main/java/org/cups4j/PrintRequestResult.java
Expand Up @@ -14,13 +14,11 @@
* the GNU Lesser General Public License along with this program; if not, see
* <http://www.gnu.org/licenses/>.
*/

import ch.ethz.vppserver.ippclient.IppResult;
import org.cups4j.ipp.attributes.AttributeGroup;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import ch.ethz.vppserver.ippclient.IppResult;

/**
* Result of a print request
*
Expand All @@ -30,10 +28,8 @@ public class PrintRequestResult {
private int jobId;
private String resultCode = "";
private String resultDescription = "";
private final IppResult ippResult;

public PrintRequestResult(IppResult ippResult) {
this.ippResult = ippResult;
if ((ippResult == null) || isNullOrEmpty(ippResult.getHttpStatusResponse())) {
return;
}
Expand Down Expand Up @@ -66,30 +62,17 @@ private boolean isNullOrEmpty(String string) {
}

public boolean isSuccessfulResult() {
return (resultCode != null) && getResultCode().startsWith("0x00");
return (resultCode != null) && resultCode.startsWith("0x00");
}

public String getResultCode() {
if (ippResult.getHttpStatusCode() < 400) {
return resultCode;
} else {
return "0x" + ippResult.getHttpStatusCode();
}
return resultCode;
}

public String getResultDescription() {
return resultDescription;
}

public String getResultMessage() {
if (ippResult.hasAttributeGroup("operation-attributes-tag")) {
AttributeGroup attributeGroup = ippResult.getAttributeGroup("operation-attributes-tag");
return attributeGroup.getAttribute("status-message").getValue();
} else {
return ippResult.getHttpStatusResponse();
}
}

public int getJobId() {
return jobId;
}
Expand Down
11 changes: 3 additions & 8 deletions src/main/java/org/cups4j/operations/IppOperation.java
Expand Up @@ -173,15 +173,10 @@ private IppResult sendRequest(URL url, ByteBuffer ippBuf, InputStream documentSt
// client.getParams().setParameter("http.protocol.expect-continue",
// Boolean.valueOf(true));

URI uri = new URI("http://" + url.getHost() + ":" + ippPort + url.getPath());
return sendRequest(uri, ippBuf, documentStream);
}

protected IppResult sendRequest(URI uri, ByteBuffer ippBuf, InputStream documentStream) throws IOException {
IppResult ippResult;HttpClient client = HttpClientBuilder.create().build();

HttpPost httpPost = new HttpPost(uri);
HttpClient client = HttpClientBuilder.create().build();
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000).build();

HttpPost httpPost = new HttpPost(new URI("http://" + url.getHost() + ":" + ippPort) + url.getPath());
httpPost.setConfig(requestConfig);
httpCall = httpPost;

Expand Down

0 comments on commit 3715a8a

Please sign in to comment.