001/* 002 * Copyright (c) 2009-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: crawl $' 006 * '$Date: 2015-08-14 17:31:59 +0000 (Fri, 14 Aug 2015) $' 007 * '$Revision: 33571 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.actor.rest; 031 032import java.io.BufferedReader; 033import java.io.File; 034import java.io.FileNotFoundException; 035import java.io.IOException; 036import java.io.InputStream; 037import java.io.InputStreamReader; 038import java.net.ConnectException; 039import java.net.URI; 040import java.net.URISyntaxException; 041import java.util.ArrayList; 042import java.util.Iterator; 043import java.util.List; 044 045import org.apache.commons.httpclient.HttpClient; 046import org.apache.commons.httpclient.HttpException; 047import org.apache.commons.httpclient.methods.GetMethod; 048import org.apache.commons.httpclient.methods.MultipartPostMethod; 049import org.apache.commons.httpclient.methods.multipart.FilePart; 050import org.apache.commons.httpclient.methods.multipart.Part; 051import org.apache.commons.httpclient.methods.multipart.StringPart; 052import org.apache.commons.logging.Log; 053import org.apache.commons.logging.LogFactory; 054 055import ptolemy.actor.IOPort; 056import ptolemy.actor.TypedAtomicActor; 057import ptolemy.actor.TypedIOPort; 058import ptolemy.actor.parameters.PortParameter; 059import ptolemy.data.StringToken; 060import ptolemy.data.Token; 061import ptolemy.data.expr.Parameter; 062import ptolemy.data.type.BaseType; 063import ptolemy.data.type.Type; 064import ptolemy.kernel.CompositeEntity; 065import ptolemy.kernel.util.IllegalActionException; 066import ptolemy.kernel.util.NameDuplicationException; 067 068 069////////////////////////////////////////////////////////////////////////// 070////RESTService 071/** 072 * <p> 073 * The RESTService actor provides the user with a plug-in interface to execute 074 * any REST web service. Given a URL for the web service and type of the service 075 * GET or POST. It works with both type of servers implementing REST standards 076 * or not. 077 * </p> 078 * <p> 079 * User shall provide all the parameters that server is expecting either through 080 * user configured ports or through actor defined paramInputPort. For the user 081 * defined port(s), port name is the parameter name and its value is parameter 082 * value. Parameters provided through actor defined paramInputPort should have 083 * name & value separated by = and each name value pair should be separated by a 084 * comma. Same thing holds true for actor defined fileInputPort, parameter name 085 * and the file path are separated by a = and name value pairs are separated by 086 * a user defined delimiter(default value is comma. This port is not read for 087 * the GET service. 088 * </p> 089 * <p> 090 * <li>Please double-click on the actor to start customization.</li> 091 * <li>To enter a URL for the service URLs, select from "methodtype" dropdown 092 * and select GET or POST as appropriate.</li> 093 * <li>After you select the URL and methodType, "Commit" .</li></ul> </i> 094 * </p> 095 * 096 * @author Madhu, SDSC 097 * @version $Id: RESTService.java 33571 2015-08-14 17:31:59Z crawl $ 098 */ 099public class RESTService extends TypedAtomicActor { 100 101 102 private static final long serialVersionUID = 1L; 103 private static Log log = LogFactory.getLog(RESTService.class); 104 105 private static final String GET = "Get"; 106 private static final String POST = "Post"; 107 108 private String parDelimiter = null; 109 private StringBuilder messageBldr = null; 110 111 /** Output of REST service. */ 112 public TypedIOPort outputPort; 113 114 /** Input file. */ 115 public TypedIOPort fileInputPort; 116 117 /** Input parameters to REST service. */ 118 public TypedIOPort paramInputPort; 119 120 /** The REST service URL. */ 121 public PortParameter serviceSiteURL; 122 123 124 /** The REST service method to use, either GET or POST. */ 125 public Parameter methodType; 126 127 /** The REST service method to use, either GET or POST. */ 128 public Parameter delimiter; 129 130 /** 131 * Construct an actor with the given container and name. In addition to 132 * invoking the base class constructors, construct the <i>serviceSiteURL</i> 133 * and <i>methodType</i> parameter. Initialize <i>serviceSiteURL</i> to the 134 * URL of the site offering the web services. It is needed and must start 135 * with "http://". <i>methodType</i> is a drop down for the type of the 136 * request this service is accepting, which could be Get or Post. 137 * 138 * @param container 139 * The container. 140 * @param name 141 * The name of this actor. 142 * @exception IllegalActionException 143 * If the actor cannot be contained by the proposed 144 * container. 145 * @exception NameDuplicationException 146 * If the container already has an actor with this name. 147 */ 148 public RESTService(CompositeEntity container, String name) 149 throws NameDuplicationException, IllegalActionException { 150 151 152 super(container, name); 153 154 // serviceSiteURL = new Parameter(this, "serviceSiteURL"); 155 serviceSiteURL = new PortParameter(this, "serviceSiteURL"); 156 serviceSiteURL.setExpression(""); 157 serviceSiteURL.setStringMode(true); 158 159 methodType = new Parameter(this, "methodType"); 160 methodType.setStringMode(true); 161 methodType.setExpression(GET); 162 methodType.addChoice(GET); 163 methodType.addChoice(POST); 164 165 delimiter = new Parameter(this, "Provide delimiter"); 166 delimiter.setExpression(ServiceUtils.PARAMDELIMITER); 167 delimiter.setStringMode(true); 168 169 outputPort = new TypedIOPort(this, "outputPort", false, true); 170 outputPort.setTypeEquals(BaseType.STRING); 171 172 paramInputPort = new TypedIOPort(this, "paramInputPort", true, false); 173 paramInputPort.setTypeEquals(BaseType.STRING); 174 175 fileInputPort = new TypedIOPort(this, "fileInputPort", true, false); 176 fileInputPort.setTypeEquals(BaseType.STRING); 177 178 } 179 180 /** 181 * It returns the URL provided as a value of <i> serviceSiteURL </i> 182 * Parameter for RESTService actor as a String. 183 * 184 * @return ServiceSiteURL as String 185 */ 186 private String getServiceSiteURL() throws IllegalActionException { 187 188 return ((StringToken) serviceSiteURL.getToken()).stringValue() 189 .trim(); 190 191 } 192 193 /** 194 * It works only on user defined/configured ports and excludes actor defined 195 * ports. 196 * 197 * @return List of Name, Value pairs of port names and values 198 */ 199 private List<NameValuePair> getPortValuePairs()throws IllegalActionException { 200 201 List<NameValuePair> nvList = new ArrayList<NameValuePair>(); 202 List<TypedIOPort> inPortList = this.inputPortList(); 203 Iterator<TypedIOPort> ports = inPortList.iterator(); 204 205 while (ports.hasNext()) { 206 IOPort p = ports.next(); 207 if (p != fileInputPort && p != paramInputPort 208 && !p.getName().equals(serviceSiteURL.getName())) { 209 210 String pValue = getPortValue(p); 211 if (pValue != null && pValue.trim().length() != 0) { 212 nvList.add(new NameValuePair(p.getName(), pValue)); 213 System.out.println("NAME: " + p.getName() + " VALUE: " 214 + pValue); 215 } 216 217 } 218 } 219 220 return nvList; 221 222 } 223 224 /** 225 * 226 * @param iop 227 * @return the value associated with a particular port 228 * @throws IllegalActionException 229 */ 230 231 private String getPortValue(IOPort iop) throws IllegalActionException{ 232 233 String result = null; 234 if(iop.getWidth() > 0){ 235 Token tk = iop.get(0); 236 Type tp = tk.getType(); 237 if(tp == BaseType.INT || tp == BaseType.LONG || 238 tp == BaseType.FLOAT || tp == BaseType.DOUBLE){ 239 240 result = tk.toString().trim(); 241 log.debug("String value of the Token: " + result); 242 }else{ 243 result =((StringToken)tk).stringValue().trim(); 244 } 245 if(_debugging){ 246 _debug("In getPortValue method RESULT: " + result); 247 } 248 } 249 250 return result; 251 } 252 253 /** 254 * 255 * @param inputValues 256 * is a comma separated values fed as input to the actor from a 257 * String Constant actor. 258 * @return a List after splitting the inputValues with PARAMDELIMITER (,) 259 * defined in the ServiceUtils class 260 */ 261 private List<String> generateInputParameterList(String inputValues) { 262 263 String[] paramArray = inputValues.split(parDelimiter); 264 265 List<String> pList = new ArrayList<String>(); 266 267 if (paramArray.length == 0) { 268 return null; 269 } 270 for (String param : paramArray) { 271 pList.add(param); 272 } 273 return pList; 274 } 275 276 /** 277 * It converts List<String> to List<NameValuePair> after splitting each 278 * String with EQUALDELIMITER and adding to the NameValuePair List if Split 279 * String array length is 2 else reject it. 280 * 281 * @param valuesList 282 * @return a List<NameValuePair> 283 */ 284 private List<NameValuePair> generatePairList(List<String> valuesList) { 285 List<NameValuePair> pairList = new ArrayList<NameValuePair>(); 286 if (valuesList.size() > 0) { 287 288 for (String value : valuesList) { 289 String[] splitString = value.split(ServiceUtils.EQUALDELIMITER); 290 if (splitString.length == 2) { 291 if (!ServiceUtils.checkEmptyString(splitString[0]) 292 && !ServiceUtils.checkEmptyString(splitString[1])) { 293 pairList.add(new NameValuePair(ServiceUtils 294 .trimString(splitString[0]), ServiceUtils 295 .trimString(splitString[1]))); 296 } 297 } 298 } 299 300 return pairList; 301 } 302 return null; 303 } 304 305 306 private void setParDelimiter() throws IllegalActionException { 307 308 String tmp = ((StringToken) delimiter.getToken()).stringValue().trim(); 309 310 if (!ServiceUtils.checkEmptyString(tmp)) { 311 312 parDelimiter = tmp; 313 } else { 314 parDelimiter = ServiceUtils.PARAMDELIMITER; 315 } 316 } 317 318 /** 319 * Sends the results as a String back after executing the appropriate 320 * service. 321 */ 322 @Override 323 public void fire() throws IllegalActionException { 324 325 super.fire(); 326 serviceSiteURL.update(); 327 328 setParDelimiter(); 329 330 if(_debugging) { 331 _debug("DELIMITER IS: " + parDelimiter); 332 } 333 334 String ssURL = getServiceSiteURL(); 335 336 if (ServiceUtils.checkEmptyString(ssURL)) { 337 outputPort.send(0, new StringToken("Please provide URL")); 338 return; 339 } else if (!ssURL.startsWith("http://")) { 340 outputPort.send(0, new StringToken("URL must start with http://")); 341 return; 342 } 343 344 String inputP = null; 345 // In case no port is connected to the paramInputPort 346 if (paramInputPort.getWidth() > 0) { 347 Token tkP = paramInputPort.get(0); 348 if (tkP != null) { 349 inputP = ((StringToken) tkP).stringValue().trim(); 350 } 351 if (_debugging) { 352 _debug("INPUT parameter: " + inputP); 353 } 354 } 355 356 List<String> paramList = null; 357 List<NameValuePair> paramPairList = null; 358 359 if (!ServiceUtils.checkEmptyString(inputP)) { 360 paramList = generateInputParameterList(inputP); 361 // check for null parmaeter list. this can happen 362 // if the wrong delimeter is used. 363 if (paramList != null && paramList.size() > 0) { 364 paramPairList = generatePairList(paramList); 365 } 366 } 367 368 String type = ((StringToken) methodType.getToken()).stringValue(); 369 if (_debugging) { 370 _debug("METHOD TYPE VALUE: " + type); 371 } 372 373 String returnedResults = null; 374 375 if (type.equals(GET)) { 376 log.debug("CALLING GET METHOD"); 377 returnedResults = executeGetMethod(paramPairList, ssURL); 378 } else if (type.equals(POST)) { 379 log.debug("CALLING POST METHOD"); 380 381 String fileParam = null; 382 if (fileInputPort.getWidth() == 0) { 383 returnedResults = executePostMethod(paramPairList, null, ssURL); 384 } else { 385 386 Token tkF = fileInputPort.get(0); 387 fileParam = ((StringToken) tkF).stringValue().trim(); 388 389 if (_debugging) { 390 _debug("INPUT FILE parameters: " + fileParam); 391 } 392 393 List<String> fileList = null; 394 List<NameValuePair> filePairList = null; 395 396 if (!ServiceUtils.checkEmptyString(fileParam)) { 397 fileList = generateInputParameterList(fileParam); 398 if (fileList.size() > 0) { 399 filePairList = generatePairList(fileList); 400 } 401 } 402 403 returnedResults = executePostMethod(paramPairList, 404 filePairList, ssURL); 405 } 406 } else { 407 returnedResults = "NO WEB SERVICE CALL MADE"; 408 log.debug("NEITHER GET NOR POST"); 409 } 410 411 messageBldr = null; // messageBldr is set to null again 412 outputPort.send(0, new StringToken(returnedResults)); 413 414 } 415 416 /** 417 * 418 * @param pmPairList 419 * List of the name and value parameters that user has provided 420 * through paramInputPort. However in method this list is 421 * combined with the user configured ports and the combined list 422 * name value pair parameters are added to the service URL 423 * separated by ampersand. 424 * @param nvPairList 425 * List of the name and value parameters that user has provided 426 * @return the results after executing the Get service. 427 */ 428 public String executeGetMethod(List<NameValuePair> nvPairList, 429 String serSiteURL)throws IllegalActionException { 430 431 if (_debugging) { 432 _debug("I AM IN GET METHOD"); 433 } 434 //log.debug("I AM IN GET METHOD"); 435 436 HttpClient client = new HttpClient(); 437 438 StringBuilder results = new StringBuilder(); 439 results.append(serSiteURL); 440 List<NameValuePair> fullPairList = getCombinedPairList(nvPairList); 441 442 if (fullPairList.size() > 0) { 443 444 results.append("?"); 445 446 int pairListSize = fullPairList.size(); 447 for (int j = 0; j < pairListSize; j++) { 448 NameValuePair nvPair = fullPairList.get(j); 449 results.append(nvPair.getName()).append( 450 ServiceUtils.EQUALDELIMITER).append(nvPair.getValue()); 451 if (j < pairListSize - 1) { 452 results.append("&"); 453 } 454 455 } 456 } 457 if (_debugging) { 458 _debug("RESULTS :" + results.toString()); 459 } 460 461 // Create a method instance. 462 GetMethod method = new GetMethod(results.toString()); 463 InputStream rstream = null; 464 StringBuilder resultsForDisplay = new StringBuilder(); 465 466 try { 467 468 messageBldr = new StringBuilder(); 469 messageBldr.append("In excuteGetMethod, communicating with service: "). 470 append(serSiteURL).append(" STATUS Code: "); 471 472 int statusCode = client.executeMethod(method); 473 messageBldr.append(statusCode); 474 475 log.debug(messageBldr.toString()); 476 if(_debugging) { 477 _debug(messageBldr.toString()); 478 } 479 480 481 // if(statusCode == 201){ 482 // System.out.println("Success -- " + statusCode + 483 // ServiceUtils.ANEMPTYSPACE + method.getResponseBodyAsString()); 484 // }else{ 485 // System.out.println("Failure -- " + statusCode + 486 // ServiceUtils.ANEMPTYSPACE + method.getResponseBodyAsString()); 487 // } 488 489 rstream = method.getResponseBodyAsStream(); 490 BufferedReader br = new BufferedReader(new InputStreamReader( 491 rstream)); 492 493 String s; 494 while ((s = br.readLine()) != null) { 495 resultsForDisplay.append(s).append(ServiceUtils.LINESEP); 496 } 497 498 } catch (HttpException httpe) { 499 if (_debugging) { 500 _debug("Fatal protocol violation: " + httpe.getMessage()); 501 } 502 httpe.printStackTrace(); 503 throw new IllegalActionException(this, httpe, "Fatal Protocol Violation: " 504 + httpe.getMessage()); 505 } catch (ConnectException conExp) { 506 if (_debugging) { 507 _debug("Perhaps service '"+ serSiteURL + "' is not reachable: " + conExp.getMessage()); 508 } 509 conExp.printStackTrace(); 510 throw new IllegalActionException(this, conExp, "Perhaps service '"+ serSiteURL + "' is not reachable: " 511 + conExp.getMessage()); 512 } catch (IOException ioe) { 513 if (_debugging) { 514 _debug("IOException: " + ioe.getMessage()); 515 } 516 // System.err.println("Fatal transport error: " + e.getMessage()); 517 ioe.printStackTrace(); 518 throw new IllegalActionException(this, ioe, "IOException: " + ioe.getMessage()); 519 } catch (Exception e) { 520 if (_debugging) { 521 _debug("Fatal transport error: " + e.getMessage()); 522 } 523 // System.err.println("Fatal transport error: " + e.getMessage()); 524 e.printStackTrace(); 525 throw new IllegalActionException(this, e, "Error: " + e.getMessage()); 526 } finally { 527 // Release the connection. 528 method.releaseConnection(); 529 client = null; 530 // close InputStream; 531 if (rstream != null) 532 try { 533 rstream.close(); 534 } catch (IOException e) { 535 e.printStackTrace(); 536 throw new IllegalActionException(this, e, "InputStream Close Exception: " + e.getMessage()); 537 } 538 } 539 540 return resultsForDisplay.toString(); 541 542 } 543 544 /** 545 * 546 * @param nmvlPairList 547 * NameValue pair List of the parameters user has provided 548 * through paramInputPort as comma separated pairs. Pairs are 549 * separated by '='. 550 * @return 551 */ 552 public List<NameValuePair> getCombinedPairList( 553 List<NameValuePair> nmvlPairList) throws IllegalActionException{ 554 List<NameValuePair> combinedPairList = new ArrayList<NameValuePair>(); 555 List<NameValuePair> nameValuePairList = getPortValuePairs(); 556 if (nameValuePairList != null && nameValuePairList.size() > 0) { 557 combinedPairList.addAll(nameValuePairList); 558 } 559 if (nmvlPairList != null && nmvlPairList.size() > 0) { 560 combinedPairList.addAll(nmvlPairList); 561 } 562 return combinedPairList; 563 564 } 565 566 /** 567 * File & regular parameters are passed as two separate lists and they are 568 * treated little differently. If flPairList is not null or empty then this 569 * method uses Part Object else no. 570 * 571 * @param pmPairList 572 * List of the name and value parameters that user has provided 573 * @param flPairList 574 * List of the name and value (full file path)of file parameters. 575 * It is essentially a list of files that user wishes to attach. 576 * @return the results after executing the Post service. 577 */ 578 public String executePostMethod(List<NameValuePair> pmPairList, 579 List<NameValuePair> flPairList, String serSiteURL) 580 throws IllegalActionException { 581 582 if (_debugging) { 583 _debug("I AM IN POST METHOD"); 584 } 585 586 //log.debug("I AM IN POST METHOD"); 587 String postAddress = serSiteURL; 588 589 HttpClient client = new HttpClient(); 590 MultipartPostMethod method = new MultipartPostMethod(postAddress); 591 List<NameValuePair> fullNameValueList = getCombinedPairList(pmPairList); 592 if (flPairList != null && flPairList.size() > 0) { 593 fullNameValueList.addAll(flPairList); 594 int totalSize = fullNameValueList.size(); 595 Part[] parts = new Part[totalSize]; 596 597 try { 598 599 for (int i = 0; i < parts.length; i++) { 600 601 String nm = fullNameValueList.get(i).getName(); 602 String vl = fullNameValueList.get(i).getValue(); 603 604 if (i > totalSize - flPairList.size() - 1) { 605 System.out.println("FILE NAME: " + nm); 606 File file = getFileObject(vl); 607 // System.out.println("FILE NAME: " + file.getName()); 608 parts[i] = new FilePart(nm, file); 609 method.addPart(parts[i]); 610 System.out.println("PARTS: " + i + " " 611 + parts[i].getName()); 612 System.out.println("file Name: " + vl); 613 614 } else { 615 616 System.out.println("PARAMETER NAME: " + nm); 617 System.out.println("PARAMETER Value: " + vl); 618 parts[i] = new StringPart(nm, vl); 619 method.addPart(parts[i]); 620 621 } 622 if (_debugging) { 623 _debug("Value of i: " + i); 624 } 625 626 } 627 628 } catch (FileNotFoundException fnfe) { 629 if (_debugging) { 630 _debug("File Not Exception: " + fnfe.getMessage()); 631 } 632 fnfe.printStackTrace(); 633 throw new IllegalActionException(this, fnfe, "File Not Found: " + 634 fnfe.getMessage()); 635 } 636 } else { 637 for (NameValuePair nmPair : fullNameValueList) { 638 method.addParameter(nmPair.getName(), nmPair.getValue()); 639 } 640 } 641 642 InputStream rstream = null; 643 StringBuilder results = new StringBuilder(); 644 try { 645 646 messageBldr = new StringBuilder(); 647 messageBldr.append("In excutePostMethod, communicating with service: "). 648 append(serSiteURL).append(" STATUS Code: "); 649 650 int statusCode = client.executeMethod(method); 651 messageBldr.append(statusCode); 652 653 log.debug("DEBUG: " + messageBldr.toString()); 654 System.out.println(messageBldr.toString()); 655 656 // if(statusCode == 201){ 657 // System.out.println("Succuess -- " + statusCode + 658 // ServiceUtils.ANEMPTYSPACE + method.getResponseBodyAsString()); 659 // }else{ 660 // System.out.println("Failure -- " + statusCode + 661 // ServiceUtils.ANEMPTYSPACE + method.getResponseBodyAsString()); 662 // } 663 rstream = method.getResponseBodyAsStream(); 664 BufferedReader br = new BufferedReader(new InputStreamReader( 665 rstream)); 666 667 log.debug("BEFORE WHILE LOOP"); 668 String s; 669 while ((s = br.readLine()) != null) { 670 results.append(s).append(ServiceUtils.LINESEP); 671 } 672 673 } catch (HttpException e) { 674 if (_debugging) { 675 _debug("Fatal protocol violation: " + e.getMessage()); 676 } 677 e.printStackTrace(); 678 return "Protocol Violation"; 679 } catch (ConnectException conExp) { 680 if (_debugging) { 681 _debug("Perhaps service '"+ serSiteURL + "' is not reachable: " + conExp.getMessage()); 682 } 683 conExp.printStackTrace(); 684 throw new IllegalActionException(this, conExp, "Perhaps service '"+ serSiteURL + "' is not reachable: " 685 + conExp.getMessage()); 686 } catch (IOException ioe) { 687 if (_debugging) { 688 _debug("Fatal transport error: " + ioe.getMessage()); 689 } 690 // System.err.println("Fatal transport error: " + e.getMessage()); 691 ioe.printStackTrace(); 692 throw new IllegalActionException(this, ioe, "IOException: Perhaps could not" + 693 " connect to the service '"+ serSiteURL + "'. " + ioe.getMessage()); 694 } catch (Exception e) { 695 if (_debugging) { 696 _debug("Error: " + e.getMessage()); 697 } 698 // System.err.println("Fatal transport error: " + e.getMessage()); 699 e.printStackTrace(); 700 throw new IllegalActionException(this, e, "Error: " + e.getMessage()); 701 } finally { 702 // Release the connection. 703 method.releaseConnection(); 704 client = null; 705 // close InputStream; 706 if (rstream != null) 707 try { 708 rstream.close(); 709 } catch (IOException e) { 710 e.printStackTrace(); 711 throw new IllegalActionException(this, e, "InputStream Close Exception: " + e.getMessage()); 712 } 713 } 714 return results.toString(); 715 } 716 717 /** 718 * 719 * @param val 720 * @return the File object for the supplied String 721 */ 722 private File getFileObject(String val) throws IllegalActionException { 723 if(val.startsWith("file:")){ 724 725 URI uri = null; 726 try{ 727 uri = new URI(val); 728 }catch(URISyntaxException synE){ 729 synE.printStackTrace(); 730 throw new IllegalActionException(this, synE, "Error: " + synE.getMessage()); 731 } 732 return new File(uri); 733 }else{ 734 return new File(val); 735 } 736 } 737 738 739 // public boolean postfire() { 740 // return false; 741 // } 742 743}