Project

General

Profile

Revision 6611

use SSL to get content from stream

View differences:

src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
577 577
                                            "&action=readdata&docid="+accNumber;
578 578
      readDataURLString = MetacatUtil.replaceWhiteSpaceForURL(readDataURLString);
579 579
      URL u = new URL(readDataURLString);
580
      InputStream input = u.openStream();
580
      InputStream input = ReplicationService.getURLStream(u);
581 581
      //register data file into xml_documents table and wite data file
582 582
      //into file system
583 583
      if ( input != null)
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
838 838
				String datafilePath = PropertyService
839 839
						.getProperty("application.datafilepath");
840 840

  
841
				InputStream inputStream = getURLStream(url);
842
				
841 843
				Exception writeException = null;
842 844
				//register data file into xml_documents table and wite data file
843 845
				//into file system
844 846
				try {
845
					DocumentImpl.writeDataFileInReplication(url.openStream(),
847
					DocumentImpl.writeDataFileInReplication(inputStream,
846 848
							datafilePath, docName, docType, docid, null, docHomeServer,
847 849
							server, DocumentImpl.DOCUMENTTABLE, false, createdDate,
848 850
							updatedDate);
......
2040 2042
	 * @throws java.io.IOException
2041 2043
	 */
2042 2044
	public static String getURLContent(URL u) throws java.io.IOException {
2043
	    logReplication.info("Getting url content from " + u.toString());
2044 2045
		char istreamChar;
2045 2046
		int istreamInt;
2046
		logReplication.info("ReplicationService.getURLContent - Before sending request to: " + u.toString());
2047
		// use httpclient to set up SSL
2048
		RestClient client = getSSLClient();
2049
		HttpResponse response = client.doGetRequest(u.toString());
2050 2047
		// get the response content
2051
		InputStream input = response.getEntity().getContent();
2048
		InputStream input = getURLStream(u);
2052 2049
		logReplication.info("ReplicationService.getURLContent - After getting response from: " + u.toString());
2053 2050
		InputStreamReader istream = new InputStreamReader(input);
2054 2051
		StringBuffer serverResponse = new StringBuffer();
......
2063 2060
	}
2064 2061
	
2065 2062
	/**
2063
	 * This method returns the InputStream after opening a url
2064
	 * @param u the url to return the content from
2065
	 * @return a InputStream representing the content of the url
2066
	 * @throws java.io.IOException
2067
	 */
2068
	public static InputStream getURLStream(URL u) throws java.io.IOException {
2069
	    logReplication.info("Getting url stream from " + u.toString());
2070
		logReplication.info("ReplicationService.getURLStream - Before sending request to: " + u.toString());
2071
		// use httpclient to set up SSL
2072
		RestClient client = getSSLClient();
2073
		HttpResponse response = client.doGetRequest(u.toString());
2074
		// get the response content
2075
		InputStream input = response.getEntity().getContent();
2076
		logReplication.info("ReplicationService.getURLStream - After getting response from: " + u.toString());
2077
		
2078
		return input;		
2079
	}
2080
	
2081
	/**
2066 2082
	 * Sets up an HttpClient with SSL connection.
2067 2083
	 * Sends client certificate to the server when doing the request.
2068 2084
	 * @return

Also available in: Unified diff