Project

General

Profile

« Previous | Next » 

Revision 7395

include inverted sendParameters() method that uses the keys as values, and the values as keys so that multiple docid parameters can be specified for the zip download. This was a regression when moving to standard httpclient rather than the roll-your-own version we had been using. http://bugzilla.ecoinformatics.org/show_bug.cgi?id=5718

View differences:

src/edu/ucsb/nceas/metacat/clientview/ClientViewHelper.java
1236 1236
                responseMap.put("Content-Disposition", "attachment; filename=" + fNm);
1237 1237
                
1238 1238
                //*** Next, read the file from metacat.
1239
                inStream = metacatClient.sendParameters(args);
1239
                inStream = metacatClient.sendParametersInverted(args);
1240 1240
                
1241 1241
                //*** Then, convert the input stream into an output stream.
1242 1242
                outStream = new ByteArrayOutputStream();
src/edu/ucsb/nceas/metacat/client/MetacatClient.java
1070 1070
     * Send a request to Metacat.  An alternative to the sentData method.
1071 1071
     * Allows for sending multiple parameters with the same name, 
1072 1072
     * different names, or any combo.  Send properties where the entry 
1073
     * key contains the "param key", 
1074
     * and the entry value contains the "param value".  
1075
     * Constraint: no multi-valued parameters are supported
1076
     *
1077
     * @return InputStream as returned by Metacat
1078
     * @param args Properties of the parameters to be sent to Metacat, where,
1079
     *      key = param key
1080
     *      value = param value
1081
     * @throws java.lang.Exception thrown
1082
     */
1083
    synchronized public InputStream sendParameters(Properties prop) throws Exception {
1084
        InputStream result = null;
1085
        try {
1086
        	HttpClient httpclient = new DefaultHttpClient();
1087
            httpclient.getParams().setParameter(
1088
            		CoreProtocolPNames.PROTOCOL_VERSION, 
1089
            	    HttpVersion.HTTP_1_1);
1090
        	httpclient.getParams().setParameter(
1091
        			CoreProtocolPNames.HTTP_CONTENT_CHARSET, 
1092
        			encoding);
1093
            HttpPost post = new HttpPost(metacatUrl);
1094
            //set the params
1095
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
1096
            Enumeration<Object> keys = prop.keys();
1097
            while (keys.hasMoreElements()) {
1098
            	String key = (String) keys.nextElement();
1099
            	String value = prop.getProperty(key);
1100
            	NameValuePair nvp = new BasicNameValuePair(key, value);
1101
            	nameValuePairs.add(nvp);
1102
            }
1103
            post.setEntity(new UrlEncodedFormEntity(nameValuePairs, encoding));
1104
            post.setHeader("Cookie", "JSESSIONID="+ this.sessionId);
1105
            HttpResponse httpResponse = httpclient.execute(post);
1106
            result = httpResponse.getEntity().getContent();
1107
            //httpclient.getConnectionManager().shutdown();
1108
        } catch (Exception e) {
1109
            throw new MetacatInaccessibleException(e.getMessage());
1110
        }
1111
        return result;
1112
    }
1113
    
1114
    /**
1115
     * Send a request to Metacat.  
1116
     * NOTE: Send properties where the entry 
1073 1117
     * key contains the "param value", 
1074 1118
     * and the entry value contains the "param name".  
1075 1119
     * Constraint: param values must be unique.
......
1080 1124
     *      value = param name
1081 1125
     * @throws java.lang.Exception thrown
1082 1126
     */
1083
    synchronized public InputStream sendParameters(Properties prop) throws Exception {
1127
    synchronized public InputStream sendParametersInverted(Properties prop) throws Exception {
1084 1128
        InputStream result = null;
1085 1129
        try {
1086 1130
        	HttpClient httpclient = new DefaultHttpClient();
......
1095 1139
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
1096 1140
            Enumeration<Object> keys = prop.keys();
1097 1141
            while (keys.hasMoreElements()) {
1142
            	// NOTE: using the value as the key for multi-valued parameters
1098 1143
            	String key = (String) keys.nextElement();
1099 1144
            	String value = prop.getProperty(key);
1100
            	NameValuePair nvp = new BasicNameValuePair(key, value);
1145
            	NameValuePair nvp = new BasicNameValuePair(value, key);
1101 1146
            	nameValuePairs.add(nvp);
1102 1147
            }
1103 1148
            post.setEntity(new UrlEncodedFormEntity(nameValuePairs, encoding));

Also available in: Unified diff