Subversion Repositories SmartDukaan

Rev

Rev 27179 | Rev 29496 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27179 Rev 28653
Line 66... Line 66...
66
	}
66
	}
67
 
67
 
68
	public String get(String url, Map<String, String> params, Map<String, String> headers)
68
	public String get(String url, Map<String, String> params, Map<String, String> headers)
69
			throws ProfitMandiBusinessException, HttpHostConnectException {
69
			throws ProfitMandiBusinessException, HttpHostConnectException {
70
		UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
70
		UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
-
 
71
		if(params!=null) {
71
		Set<String> keys = params.keySet();
72
			Set<String> keys = params.keySet();
72
		for (String key : keys) {
73
			for (String key : keys) {
73
			builder.queryParam(key, params.get(key));
74
				builder.queryParam(key, params.get(key));
-
 
75
			}
74
		}
76
		}
75
		HttpGet request = new HttpGet(builder.build().encode().toUri());
77
		HttpGet request = new HttpGet(builder.build().encode().toUri());
76
		for (Map.Entry<String, String> entry : headers.entrySet()) {
78
		for (Map.Entry<String, String> entry : headers.entrySet()) {
77
			request.setHeader(entry.getKey(), entry.getValue());
79
			request.setHeader(entry.getKey(), entry.getValue());
78
		}
80
		}
Line 201... Line 203...
201
 
203
 
202
		return this.execute(request);
204
		return this.execute(request);
203
 
205
 
204
	}
206
	}
205
 
207
 
-
 
208
	public String post(String url, String body, Map<String, String> headers)
-
 
209
			throws ProfitMandiBusinessException, HttpHostConnectException {
-
 
210
		HttpPost request = new HttpPost(url);
-
 
211
		for (Map.Entry<String, String> entry : headers.entrySet()) {
-
 
212
			request.setHeader(entry.getKey(), entry.getValue());
-
 
213
		}
-
 
214
 
-
 
215
		try {
-
 
216
			request.setEntity(new StringEntity(body));
-
 
217
		} catch (UnsupportedEncodingException unsupportedEncodingException) {
-
 
218
			LOGGER.error("Encoding error : ", unsupportedEncodingException);
-
 
219
			throw new RuntimeException(ResponseCodeHolder.getMessage("GE_1006"));
-
 
220
		}
-
 
221
 
-
 
222
		return this.execute(request);
-
 
223
 
-
 
224
	}
-
 
225
 
206
	public String postJson(String url, Object object, Map<String, String> headers)
226
	public String postJson(String url, Object object, Map<String, String> headers)
207
			throws ProfitMandiBusinessException, HttpHostConnectException {
227
			throws ProfitMandiBusinessException, HttpHostConnectException {
208
		String jsonString;
228
		String jsonString;
209
		try {
229
		try {
-
 
230
			if (object.getClass().equals(String.class)) {
-
 
231
				jsonString = (String) object;
-
 
232
			} else {
210
			jsonString = objectMapper.writeValueAsString(object);
233
				jsonString = objectMapper.writeValueAsString(object);
-
 
234
			}
211
			LOGGER.info("JSON String - {}", jsonString);
235
			LOGGER.info("JSON String - {}", jsonString);
212
		} catch (Exception e) {
236
		} catch (Exception e) {
213
			e.printStackTrace();
237
			e.printStackTrace();
214
			throw new ProfitMandiBusinessException("Json Object", object.toString(), "Could not write as String");
238
			throw new ProfitMandiBusinessException("Json Object", object.toString(), "Could not write as String");
215
		}
239
		}