Subversion Repositories SmartDukaan

Rev

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

Rev 29496 Rev 29710
Line 15... Line 15...
15
import org.apache.http.client.ClientProtocolException;
15
import org.apache.http.client.ClientProtocolException;
16
import org.apache.http.client.HttpClient;
16
import org.apache.http.client.HttpClient;
17
import org.apache.http.client.config.RequestConfig;
17
import org.apache.http.client.config.RequestConfig;
18
import org.apache.http.client.entity.UrlEncodedFormEntity;
18
import org.apache.http.client.entity.UrlEncodedFormEntity;
19
import org.apache.http.client.methods.HttpGet;
19
import org.apache.http.client.methods.HttpGet;
-
 
20
import org.apache.http.client.methods.HttpPatch;
20
import org.apache.http.client.methods.HttpPost;
21
import org.apache.http.client.methods.HttpPost;
21
import org.apache.http.client.methods.HttpUriRequest;
22
import org.apache.http.client.methods.HttpUriRequest;
22
import org.apache.http.conn.HttpHostConnectException;
23
import org.apache.http.conn.HttpHostConnectException;
23
import org.apache.http.entity.ContentType;
24
import org.apache.http.entity.ContentType;
24
import org.apache.http.entity.StringEntity;
25
import org.apache.http.entity.StringEntity;
Line 246... Line 247...
246
		for (Map.Entry<String, String> entry : headers.entrySet()) {
247
		for (Map.Entry<String, String> entry : headers.entrySet()) {
247
			request.setHeader(entry.getKey(), entry.getValue());
248
			request.setHeader(entry.getKey(), entry.getValue());
248
		}
249
		}
249
		request.setEntity(requestEntity);
250
		request.setEntity(requestEntity);
250
		return this.executeJson(request);
251
		return this.executeJson(request);
-
 
252
	}
-
 
253
	
-
 
254
	public String patchJson(String url, Object object, Map<String, String> headers)
-
 
255
			throws ProfitMandiBusinessException, HttpHostConnectException {
-
 
256
		String jsonString;
-
 
257
		try {
-
 
258
			if (object.getClass().equals(String.class)) {
-
 
259
				jsonString = (String) object;
-
 
260
			} else {
-
 
261
				jsonString = objectMapper.writeValueAsString(object);
-
 
262
			}
-
 
263
			LOGGER.info("JSON String - {}", jsonString);
-
 
264
		} catch (Exception e) {
-
 
265
			e.printStackTrace();
-
 
266
			throw new ProfitMandiBusinessException("Json Object", object.toString(), "Could not write as String");
-
 
267
		}
-
 
268
		StringEntity requestEntity = new StringEntity(jsonString, ContentType.APPLICATION_JSON);
-
 
269
		
-
 
270
		UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
-
 
271
		
-
 
272
		HttpPatch request = new HttpPatch(builder.build().encode().toUri());
-
 
273
		for (Map.Entry<String, String> entry : headers.entrySet()) {
-
 
274
			request.setHeader(entry.getKey(), entry.getValue());
-
 
275
		}
-
 
276
		request.setEntity(requestEntity);
-
 
277
		return this.executeJson(request);
251
	}
278
	}
252
 
279
 
253
	private String toString(InputStream inputStream) {
280
	private String toString(InputStream inputStream) {
254
		BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
281
		BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
255
		StringBuilder responseString = new StringBuilder();
282
		StringBuilder responseString = new StringBuilder();