1 PACKAGE BODY INV_PRINT_REQUEST AS
2 /* $Header: INVPRRQB.pls 120.1 2006/03/02 00:44:24 dchithir noship $ */
3
4 PROCEDURE trace(p_message VARCHAR2) IS
5 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6 BEGIN
7 IF (l_debug = 1) THEN
8 inv_label.trace(p_message, 'PRINT_REQUEST');
9 END IF;
10 END trace;
11
12 PROCEDURE SYNC_PRINT_REQUEST
13 (
14 p_xml_content IN LONG
15 , x_job_status OUT NOCOPY VARCHAR2
16 , x_printer_status OUT NOCOPY VARCHAR2
17 , x_status_type OUT NOCOPY NUMBER
18 ) IS
19 BEGIN
20 -- Call out to 3rd party print procedures
21 INV_SYNC_PRINT_REQUEST.SYNC_PRINT_REQUEST
22 (p_xml_content, x_job_status,x_printer_status,x_status_type);
23 END;
24
25 PROCEDURE WRITE_XML
26 (
27 p_xml_content IN LONG
28 , p_request_id IN NUMBER
29 , x_return_status OUT NOCOPY VARCHAR2
30 , x_msg_count OUT NOCOPY NUMBER
31 , x_msg_data OUT NOCOPY VARCHAR2
32 ) IS
33 l_output_dir VARCHAR2(200);
34 l_output_file_prefix VARCHAR2(50);
35 l_output_file_name VARCHAR2(50);
36
37 l_file_end CONSTANT VARCHAR2(10) := '.xml';
38 l_file_handler UTL_FILE.FILE_TYPE;
39
40 --l_substr VARCHAR2(254);
41 --i NUMBER;
42 --l_last_index NUMBER;
43 --l_cur_index NUMBER;
44 l_dir_seperator VARCHAR2(1);
45
46 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
47 BEGIN
48 -- Initialize API return status to success
49 x_return_status := FND_API.G_RET_STS_SUCCESS;
50
51 -- Get profile values for output directory
52 -- and output file prefix
53 FND_PROFILE.GET('WMS_LABEL_OUTPUT_DIRECTORY', l_output_dir);
54 IF (l_output_dir IS NULL) OR (trim(l_output_dir) = '') THEN
55 IF (l_debug = 1) THEN
56 trace(' WMS_LABEL_OUTPUT_DIRECTORY is null, can not write XML file ');
57 END IF;
58 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
59 END IF;
60 FND_PROFILE.GET('WMS_LABEL_FILE_PREFIX', l_output_file_prefix);
61 IF (l_debug = 1) THEN
62 trace(' Profile value obtained, dir='||l_output_dir ||', prefix='|| l_output_file_prefix);
63 END IF;
64
65 -- Get the file name = prefix + l_request_id .xml
66 l_output_file_name := l_output_file_prefix || p_request_id || l_file_end;
67
68 l_dir_seperator := '/';
69 IF(instr(l_output_dir, l_dir_seperator) = 0) THEN
70 l_dir_seperator := '\';
71 END IF;
72
73 -- Open the file
74 l_file_handler := UTL_FILE.fopen(rtrim(l_output_dir,l_dir_seperator), l_output_file_name, 'w');
75
76 -- Write into the file
77 /*l_last_index :=1;
78 l_cur_index := instr(p_xml_content, '>', l_last_index);
79
80 WHILE l_cur_index <> 0 LOOP
81 l_substr := substr(p_xml_content, l_last_index, l_cur_index-l_last_index+1);
82 utl_file.put_line(l_file_handler, l_substr);
83 l_last_index := l_cur_index + 1;
84 IF(substr(p_xml_content, l_last_index+1,1) = 'v') THEN
85 l_cur_index := instr(p_xml_content, '>', l_last_index, 2);
86 ELSE
87 l_cur_index := instr(p_xml_content, '>', l_last_index, 1);
88 END IF;
89 END LOOP; */
90
91 -- Because of the change that line break will be included in p_xml_content,
92 -- can just use one put_line to write all the data into file
93 utl_file.put_line(l_file_handler, p_xml_content);
94 utl_file.fflush(l_file_handler);
95 utl_file.fclose(l_file_handler);
96 IF (l_debug = 1) THEN
97 trace(length(p_xml_content) ||' characters of xml string writtten into '||l_output_dir||l_dir_seperator||l_output_file_name);
98 END IF;
99
100 EXCEPTION
101 WHEN utl_file.invalid_path THEN
102 IF (l_debug = 1) THEN
103 trace(' Invalid Path error in '|| G_PKG_NAME||'.write_xml, can not write xml file');
104 trace('ERROR CODE = ' || SQLCODE);
105 trace('ERROR MESSAGE = ' || SQLERRM);
106 END IF;
107 utl_file.fclose(l_file_handler);
108 x_return_status := FND_API.G_RET_STS_ERROR;
109 x_msg_data := SQLERRM;
110 WHEN fnd_api.g_exc_error THEN
111 IF (l_debug = 1) THEN
112 trace(' Expected Error In '|| G_PKG_NAME||'.write_xml');
113 trace('ERROR CODE = ' || SQLCODE);
114 trace('ERROR MESSAGE = ' || SQLERRM);
115 END IF;
116 utl_file.fclose(l_file_handler);
117 x_return_status := FND_API.G_RET_STS_ERROR;
118 x_msg_data := SQLERRM;
119 WHEN fnd_api.g_exc_unexpected_error THEN
120 IF (l_debug = 1) THEN
121 trace(' Unexpected Error In '|| G_PKG_NAME||'.write_xml');
122 trace('ERROR CODE = ' || SQLCODE);
123 trace('ERROR MESSAGE = ' || SQLERRM);
124 END IF;
125 utl_file.fclose(l_file_handler);
126 x_return_status := FND_API.G_RET_STS_ERROR;
127 x_msg_data := SQLERRM;
128 WHEN others THEN
129 IF (l_debug = 1) THEN
130 trace(' Other Error In '|| G_PKG_NAME||'.write_xml');
131 trace('ERROR CODE = ' || SQLCODE);
132 trace('ERROR MESSAGE = ' || SQLERRM);
133 END IF;
134 utl_file.fclose(l_file_handler);
135 x_return_status := FND_API.G_RET_STS_ERROR;
136 x_msg_data := SQLERRM;
137 END WRITE_XML;
138
139 PROCEDURE GET_REQUEST_STATUS
140 (
141 p_request_id IN NUMBER
142 , x_job_status OUT NOCOPY VARCHAR2
143 , x_printer_status OUT NOCOPY VARCHAR2
144 , x_status_type OUT NOCOPY NUMBER
145 ) IS
146 BEGIN
147 null;
148 END;
149
150
151
152 /*
153 * Method for sending the label XML file to a TCP-IP address when profile
154 * WMS:Label Print Mode is set to Synchronous TCP/IP. The TCP-IP address
155 * is derived by first retrieving the printer specified in the XML file,
156 * and then doing a lookup for this printer in the Printer-IP table.
157 */
158 PROCEDURE SYNC_PRINT_TCPIP
159 (
160 p_xml_content IN LONG
161 , x_job_status OUT NOCOPY VARCHAR2
162 , x_printer_status OUT NOCOPY VARCHAR2
163 , x_status_type OUT NOCOPY NUMBER
164 , x_return_status OUT NOCOPY VARCHAR2
165 , x_return_msg OUT NOCOPY VARCHAR2
166 ) IS
167 l_printer_name VARCHAR2(50);
168 l_ip_address VARCHAR2(50);
169 l_port_number NUMBER;
170 l_index NUMBER;
171 l_ocurrent_count NUMBER;
172 l_start_of_printername NUMBER;
173 l_end_of_printername NUMBER;
174
175 l_return NUMBER;
176 l_return_msg VARCHAR2(2000);
177 l_printer_status VARCHAR2(2000);
178
179 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
180
181 --Fix for Bug: 5004303.
182 l_time DATE;
183 l_delay_time number := NVL(FND_PROFILE.VALUE('WMS_SYNCHRONOUS_TCPIP_LABEL_REQUEST_DELAY'),0);
184 --End of fix for 5004303
185
186 BEGIN
187 -- Initialize API return status to success
188 x_return_status := FND_API.G_RET_STS_SUCCESS;
189
190 -- Search for the occurrent of _PRINTERNAME in the p_xml_content
191 -- from the end, until found a PRINTERNAME which is not null
192 l_printer_name := null;
193 l_index := 0;
194 l_ocurrent_count := 1;
195 LOOP
196 l_index := instr(p_xml_content, '_PRINTERNAME',-1,l_ocurrent_count);
197 IF l_index = 0 THEN
198 IF l_debug = 1 THEN
199 trace('End of searching. l_index ='||l_index);
200 END IF;
201 EXIT;
202 END IF;
203 -- Get the value of the printername from _PRINTERNAME="XXX"
204 -- Find the first and second occurence of " after the start of _PRINTERNAME
205 l_start_of_printername := instr(p_xml_content, '"', l_index, 1);
206 l_end_of_printername := instr(p_xml_content, '"', l_index, 2);
207 IF l_end_of_printername-l_start_of_printername <= 1 THEN
208 l_printer_name := null;
209 ELSE
210 l_printer_name := trim(substr(p_xml_content,l_start_of_printername+1, l_end_of_printername-l_start_of_printername-1));
211 END IF;
212 IF length(l_printer_name) > 0 THEN
213 EXIT;
214 END IF;
215 l_ocurrent_count := l_ocurrent_count + 1;
216 END LOOP;
217 IF l_printer_name IS NULL OR length(l_printer_name) = 0 THEN
218 IF l_debug = 1 THEN
219 trace('Printer name is null, can not process');
220 END IF;
221 fnd_message.set_name('WSH','WSH_PRINTER_NAME_REQUIRED'); --Printer name is required
222 x_return_msg := fnd_message.get();
223 raise fnd_api.G_EXC_ERROR;
224 END IF;
225
226 IF l_debug = 1 THEN
227 trace('Found PRINTER NAME as '||l_printer_name);
228 END IF;
229 -- Obtain the IP address and port number for the printer
230 BEGIN
231 SELECT ip_address, port_number
232 INTO l_ip_address, l_port_number
233 FROM WMS_PRINTER_IP_DEF
234 WHERE printer_name = l_printer_name;
235 EXCEPTION
236 WHEN no_data_found THEN
237 IF l_debug = 1 THEN
238 trace('Can not find IP address and port number for printer '||l_printer_name);
239 END IF;
240 fnd_message.set_name('INV','INV_NO_IP_PORT'); -- Invalid Printer, can not find IP address and port number
241 fnd_message.set_token('PRINTER',l_printer_name); -- Invalid Printer, can not find IP address and port number
242 x_return_msg := fnd_message.get();
243 raise fnd_api.G_EXC_ERROR;
244 WHEN others THEN
245 IF l_debug = 1 THEN
246 trace('Other error when getting IP address and port number for printer '||l_printer_name);
247 END IF;
248 raise fnd_api.G_EXC_UNEXPECTED_ERROR;
249 END;
250 IF l_debug = 1 THEN
251 trace('IP address:'||l_ip_address||', Port number:'||l_port_number);
252 trace('Calling SEND_XML_TCPIP ');
253 END IF;
254
255 l_return := SEND_XML_TCPIP(
256 p_ip_address => l_ip_address
257 , p_port => to_char(l_port_number)
258 , p_xml_content => p_xml_content
259 , x_return_msg => l_return_msg
260 , x_printer_status => l_printer_status
261 );
262
263 IF l_debug = 1 THEN
264 trace('Called SEND_XML_TCPIP, l_return='||l_return||', l_return_msg='||l_return_msg||', l_printer_status='||l_printer_status);
265 trace('Starting time delay...');
266 END IF;
267
268 --Fix for Bug: 5004303
269 l_time := SYSDATE + (l_delay_time/(86400000));
270 WHILE l_time > SYSDATE LOOP
271 NULL;
272 END LOOP ;
273 --End of fix for 5004303
274
275 IF l_debug = 1 THEN
276 trace('After time delay.');
277 END IF;
278
279 IF l_return = -1 THEN
280 x_return_msg := l_return_msg;
281 raise fnd_api.G_EXC_ERROR;
282 END IF;
283
284 x_printer_status := l_printer_status;
285
286 EXCEPTION
287 WHEN fnd_api.G_EXC_ERROR THEN
288 IF l_debug = 1 THEN
289 trace('Expected Error in SYNC_PRINT_TCPIP');
290 trace('ERROR Code ='||SQLCODE);
291 trace('ERROR Message='||SQLERRM);
292 END IF;
293 x_return_status := fnd_api.G_RET_STS_ERROR;
294 WHEN fnd_api.G_EXC_UNEXPECTED_ERROR THEN
295 IF l_debug = 1 THEN
296 trace('Unexpected Error in SYNC_PRINT_TCPIP');
297 trace('ERROR Code ='||SQLCODE);
298 trace('ERROR Message='||SQLERRM);
299 END IF;
300 x_return_status := fnd_api.G_RET_STS_UNEXP_ERROR;
301 WHEN others THEN
302 IF l_debug = 1 THEN
303 trace('Other Error in SYNC_PRINT_TCPIP');
304 trace('ERROR Code ='||SQLCODE);
305 trace('ERROR Message='||SQLERRM);
306 END IF;
307 x_return_status := fnd_api.G_RET_STS_UNEXP_ERROR;
308 END SYNC_PRINT_TCPIP;
309
310 /*
311 * Method for sending a string to a TCP-IP address. Used to send the
312 * label-XML file to a print-server. The x_return_msg returns any
313 * message send back from this TCP-IP address. This function returns
314 * 0 if the file was send successfully. It returns -1 if there was
315 * any error.
316 */
317 FUNCTION SEND_XML_TCPIP
318 (
319 p_ip_address IN VARCHAR2
320 , p_port IN VARCHAR2
321 , p_xml_content IN VARCHAR2
322 , x_return_msg OUT NOCOPY VARCHAR2
323 , x_printer_status OUT NOCOPY VARCHAR2
324 ) RETURN NUMBER
325 AS LANGUAGE JAVA NAME 'oracle.apps.inv.labels.server.SyncTCPIP.sendXML(
326 java.lang.String,
327 java.lang.String,
328 java.lang.String,
329 java.lang.String[],
330 java.lang.String[]) return java.lang.Integer';
331
332
333 END INV_PRINT_REQUEST;