JCIFSWrapperImpl.java
4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* jcifs.smb.NtlmPasswordAuthentication
* jcifs.smb.SmbException
* jcifs.smb.SmbFile
* jcifs.util.LogStream
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Service
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.jcifs.wrapper.impl;
import com.adobe.fd.jcifs.wrapper.api.JCIFSWrapper;
import com.adobe.fd.jcifs.wrapper.api.JCIFSWrapperException;
import com.adobe.fd.jcifs.wrapper.internal.exception.GeneralJCIFSWrapperException;
import com.adobe.fd.jcifs.wrapper.internal.exception.PrinterAccessDeniedException;
import com.adobe.fd.jcifs.wrapper.internal.exception.PrinterNotFoundException;
import com.adobe.fd.jcifs.wrapper.internal.exception.TooManyConnectionsException;
import com.adobe.fd.jcifs.wrapper.internal.util.ThirdPartyOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.MalformedURLException;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import jcifs.util.LogStream;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(label="AEMFD JCIFSWrapper ", description="AEMFD JCIFSWrapper ")
@Service(value={JCIFSWrapper.class})
public class JCIFSWrapperImpl
implements JCIFSWrapper {
private static Logger logger = LoggerFactory.getLogger(JCIFSWrapperImpl.class);
@Activate
void activate() {
LogStream.setInstance((PrintStream)new PrintStream(new ThirdPartyOutputStream(logger)));
if (logger.isDebugEnabled()) {
LogStream.setLevel((int)10);
}
}
@Override
public int print(InputStream is, String smbUri, String jobName, String domainName, String userName, String password) throws JCIFSWrapperException {
try {
SmbFile smbFile = this.getPrinter(smbUri, domainName, userName, password);
return smbFile.print(is, jobName);
}
catch (MalformedURLException e) {
throw new GeneralJCIFSWrapperException(e);
}
catch (SmbException e) {
switch (e.getNtStatus()) {
case -1073741819:
case -1073741790:
case -1073741730:
case -1073741724:
case -1073741718:
case -1073741715:
case -1073741714:
case -1073741713:
case -1073741711:
case -1073741710:
case -1073741709:
case -1073741622:
case -1073741477:
case -1073741428:
case -1073741276:
case -1073741260: {
throw new PrinterAccessDeniedException((Throwable)e);
}
case -1073741616: {
throw new TooManyConnectionsException((Throwable)e);
}
case -1073741810:
case -1073741809:
case -1073741773:
case -1073741772:
case -1073741767:
case -1073741766:
case -1073741765:
case -1073741620:
case -1073741606:
case -1073741601:
case -1073741487:
case -1073741275: {
throw new PrinterNotFoundException((Throwable)e);
}
}
throw new GeneralJCIFSWrapperException((Throwable)e);
}
catch (IOException e) {
throw new GeneralJCIFSWrapperException(e);
}
}
@Override
public boolean isAccessible(String smbURI, String domainName, String userName, String password) {
try {
SmbFile printer = this.getPrinter(smbURI, domainName, userName, password);
printer.connect();
logger.debug("SmbURI=" + smbURI + " is accessible");
}
catch (Exception e) {
logger.debug(e.getMessage(), (Throwable)e);
return false;
}
return true;
}
private SmbFile getPrinter(String smbURI, String domainName, String userName, String password) throws MalformedURLException {
NtlmPasswordAuthentication auth = null;
if (userName != null) {
auth = new NtlmPasswordAuthentication(domainName, userName, password);
}
SmbFile printer = new SmbFile(smbURI, auth);
return printer;
}
}