Changeset 1495 for MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
- Timestamp:
- 08/25/11 20:21:23 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/GenericProxyAction.java
r1491 r1495 26 26 27 27 import org.apache.struts2.interceptor.ServletRequestAware; 28 29 28 import com.opensymphony.xwork2.ActionSupport; 30 31 29 import eu.clarin.cmdi.mdservice.model.Diagnostics; 32 30 33 31 /** 34 * main Struts 2 controller35 * responds to requests (collections, model, recordset)36 * by dispatching the requests to appropriate internal methods and filling the inputStream with the result32 * main Struts2 controller (ie implemenets the struts' execute()-method), all other Actions are derived from. 33 * Defines the methods used for retrieving the data 34 * and provides basic implementation where possible. 37 35 * 38 36 * @author vronk 39 *40 37 */ 41 38 public class GenericProxyAction extends ActionSupport … … 69 66 private String repository; 70 67 //private Map<String,Object> session; 71 private HttpServletRequest request; 72 private long duration = 0; 73 68 private HttpServletRequest request; 69 private long duration = 0; 70 private InputStream resultStream; 71 private InputStream sourceStream; 72 protected URL base_url ; 73 74 74 public GenericProxyAction(){ 75 75 super(); … … 198 198 } 199 199 200 /** 201 * is used in struts.xml to dynamically set the mime-type of the result, depending on the format-parameter 202 * @return 203 */ 200 204 public String getActionContentType() { 201 205 if (format.toLowerCase().startsWith("html")) { … … 269 273 270 274 /** 271 * primitiveidentification of the target-proxy272 * base for finding the right base_url in the prop s275 * internal identification of the target-proxy 276 * base for finding the right base_url in the properties 273 277 * subclass has to override with its specific proxykey 274 * @return 278 * @return the key identifying this type of proxy 275 279 */ 276 280 public String getProxyKey() { … … 278 282 } 279 283 284 /** 285 * TODO: check what this does, where it is used? 286 * @return 287 */ 280 288 public String getUserMsg() { 281 289 return userMsg; … … 286 294 } 287 295 296 /** 297 * TODO: check what this does, where it is used? 298 * @return 299 */ 288 300 @Override 289 301 public void setServletRequest(HttpServletRequest arg0) { … … 294 306 return request; 295 307 } 296 297 298 private InputStream resultStream;299 private InputStream sourceStream;300 308 301 309 /** … … 335 343 } 336 344 337 protected URL base_url ; 338 345 /** 346 * Reads URI from the configuration (mdservice.properties) based on the proxy-key 347 * @return the base-URI of the target repository or registry 348 */ 349 public String getBaseURI() { 350 String uri =Admin.getConfig().getProperty(getProxyKey() + ".uri"); 351 return uri; 352 } 353 354 /** 355 * Provides the base-URL specific to given target repository or registry 356 * @return 357 * @throws MalformedURLException 358 */ 339 359 public URL getBaseURL() throws MalformedURLException { 340 360 if (base_url == null) { … … 344 364 } 345 365 346 public String getBaseURI() { 347 String uri =Admin.getConfig().getProperty(getProxyKey() + ".uri"); 348 return uri; 349 } 350 351 366 /** 367 * Constructs the actual URL to be send to the target repository/registry 368 * It has to be overridden by the subclasses 369 * as every target service has a different request-pattern. 370 * @return URL of the target request 371 * @throws IOException 372 */ 352 373 public URL getTargetRequest() throws IOException { 353 // URL targetURL =new URL( base_url, compname + ".xml"); 354 URL targetURL = getBaseURL(); 355 374 URL targetURL = getBaseURL(); 356 375 return targetURL; 357 376 } 358 377 359 /* 360 public String getRequestKey() { 361 String key=""; 362 if (getActionkey()!=null) { 363 key += getActionkey() + "//-" ; 364 } 365 if (getQ()!=null) { 366 key += getQ() + "//-" ; 367 } 368 if (getCollection()!=null) { 369 key += getCollection(); 370 } 371 372 return key; 373 } 374 */ 375 378 /** 379 * Constructs an unambiguous key for the request (encoding all the parameters). 380 * This is used as identifier for caching 381 * @return key unambiguously encoding the request 382 */ 383 376 384 public String getRequestKey() { 377 385 String key=""; … … 416 424 }else{ 417 425 key +="//-" ; 418 } 419 426 } 420 427 421 return key; 422 } 428 return key; 429 } 430 431 423 432 public InputStream getSourceStream() throws IOException, NoStylesheetException { 424 433 return getTargetRequest().openStream(); 425 // Admin.notifyUser(getProxyKey() + ".getSourceStream() - unable to open stream: " + getTargetRequest(); 426 } 427 434 435 } 436 437 /* 438 * TODO: this should go to Utilities! 439 */ 428 440 public static String convertStreamToString(InputStream is) { 429 441 … … 677 689 } 678 690 691 /** 692 * This is the work-horse function. 693 * It does two things: 694 * a) check if the source data is already in cache (based on cache-key that is constructed from the request parameters) 695 * b) if format-parameter provided, invokes the transformation. 696 * at the end the data to be returned as result is contained in the resultStream 697 * If format is xml, then the data from sourceStream is passed further as resultStream. 698 * 699 * @throws Exception This is handled by struts (is mapped to some result in struts.xml based on the Exception-Class) 700 */ 679 701 680 702 public void prepare() throws Exception { … … 716 738 resultStream = sourceStream; 717 739 }else { 740 MDTransformer transformer = new MDTransformer(); 718 741 // set URL as srcFile (for MDTransformer to pass to xsl-scripts) 719 MDTransformer transformer = new MDTransformer();742 // TODO: WHY?? 720 743 transformer.setSrcFile(getTargetRequest()); 721 // getColumns722 // Admin.notifyUser("GPA.getRepository, before xsl:" + getRepository());723 744 transformer.setParams(createTransformerParams()); 724 725 resultStream = transformer.transformXML(sourceStream); //, getFullFormat(), getColumns(), getStartRecord(), getMaximumRecords(),getLang(),getQ(),String.valueOf(getRepository()));745 // here the transformation is invoked 746 resultStream = transformer.transformXML(sourceStream); 726 747 } 727 748 … … 730 751 731 752 /** 732 * default Action method 753 * default Action method that gets called by Struts. Everything interesting happens in prepare() 733 754 */ 734 755 public String execute() throws Exception {
Note: See TracChangeset
for help on using the changeset viewer.