Categories
Mastering Development

Post Json Array in Json Object via Resttemplate in Spring Boot

Im trying to post Json array in json object using Rest Template { “update”: { “name”: “xyz”, “id”: “C2”, “Description”: “aaaaaa”, “members”: [ “abc”, “xyz” ] } } Here is my Postmapping Controller @PostMapping(value = “/update”) public Update update(@RequestBody Update update) { String url = “”; HttpHeaders headers = createHttpHeaders(“username”, “passowrd”); JSONObject jsonObject = new […]

Categories
Development

How to fix the error No serializer found for class java.util.logging.SimpleFormatter and no properties discovered to create BeanSerializer

In java, I am trying to access a Spring Boot Microservice using the following code: try { CircularsSaveParams circularsSaveParams; circularsSaveParams= new CircularsSaveParams( request, principal, session, locale, mav,souqBean); //creating microservice params HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<?> entity = new HttpEntity<Object>(circularsSaveParams,headers); ResponseEntity<Boolean> responseEntity = restTemplate.exchange(“http://localhost:8084/circular-save”, HttpMethod.POST, entity, Boolean.class); //String employeeDivision= restTemplate.getForObject(“http://employee-division-service/”+id+d, String.class); status= responseEntity.getBody(); } […]

Categories
Development

OAuth2RestOperations: java.lang.IllegalArgumentException: URI is not absolute

I am trying to use OAuth2RestOperations to call an api like below and getting “java.lang.IllegalArgumentException: URI is not absolute” exception. What am I missing? public void sendSMS(String message, String destination) { String messageUrl = “http://baseurl/uri” System.out.println(“Message url: ” + messageUrl); JSONObject messageObject = new JSONObject() .put(“message”, message) .put(“destination”, destination); HttpHeaders headers = new HttpHeaders(); headers.add(“Content-Type”, […]

Categories
Development

Spring Rest Template 400 Bad Request but Successful on PostMan

Basically, I made a post call to get access token and got “400 Bad Request” using RestTemplate. Same call made via Postman can out successful with exactly the same parameters. private String getTokenString(@NonNull String code) { String tokenUrl = AZURE_BASE_URL + tenantId + “/oauth2/token”; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.set(“Authorization”, “Bearer “+code); JSONObject […]

Categories
Development

How to generate the proper RestTemplate usage from curl?

I have a working curl command that is below: curl -v -H “Content-Type:application/octet-stream” \ -H “x-amz-server-side-encryption:aws:kms” \ -H “x-amz-server-side-encryption-aws-kms-key-id:abcdef81-abcd-4c85-b1d8-ee540d0a5f5d” \ –upload-file /Users/fd/Downloads/video.mp4 \ ‘https://video-uploads-prod.s3-accelerate.amazonaws.com/ABCDEAQGZHEhM55fvvA/ads-aws_userUploadedVideo?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20200106T165718Z&X-Amz-SignedHeaders=content-type%3Bhost%3Bx-amz-server-side-encryption%3Bx-amz-server-side-encryption-aws-kms-key-id&X-Amz-Expires=86400&X-Amz-Credential=ABCDEFHLWTCWZ2MUPPBQ%2F20200106%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=037949abcd1234b063c75d3d505dd9120dd3fa9250c1ababa152e91fee123ca0′ The curl is working properly: * We are completely uploaded and fine < HTTP/1.1 200 OK However, when I try to use RestTemplate (i’m using spring boot 1.5.6) I’m not able […]

Categories
Development HTTP Java

Java Spring – No HttpMessageConverter for LinkedMultiValueMap and content type “application/x-www-form-urlencoded”

I am trying to send a POST request in Spring Boot using the restTemplate with “application/x-www-form-urlencoded” header. When I execute my code it gives the following error: org.springframework.web.client.RestClientException: No HttpMessageConverter for org.springframework.util.LinkedMultiValueMap and content type “application/x-www-form-urlencoded” Here is my code: String requestUrl = “hidden”; HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); httpHeaders.add(“Authorization”, “Basic hidden”); MultiValueMap<String, String> […]

Categories
API Development

spring boot resttemplate api call by passing username and password

i want get data from rest api .. in backend iam using spring boot RestInterceptor Error–<302,[Location:”/TicketingSystem/Index.html”, Content-Length:”0″, Date:”Tue, 19 Nov 2019 11:07:00 GMT”]> final String uri = “http://localhost:9090/TicketingSystem/caselogcontroller/getAppIds“; RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.setBasicAuth(“USER1”, “123”); HttpEntity entity = new HttpEntity(null, headers); System.out.println(“ENTITY=<>=”+entity.toString()); ResponseEntity<String> result = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class); […]

Categories
Development Unity

How to fix “Exception of type ‘Unity.Exceptions.InvalidRegistrationException’ was thrown”

I try to login my application but it is throwing this exception. I left it with proper correctly running application. After 2 days i started work back on this so now it is giving this exception. I have applied unit of work 2 days before. Now today before checking application i tried to add validation […]

Categories
Development MVC MySQL

spring JPA to post in API request

Here im trying to fetch the data row by row from mysql db with findby function and it worked fine, but the next step I’m trying to access an API to fill the needed data from my table to API throught http POST and change the processDate to current date , but im getting an […]

Categories
Development

uploading base64 image to server

I have over 50 + images stored in local storage of browser using base64 encoding. I want to upload them to server but it fails. public async uploadImages() { this.request.images.forEach((subject: any) => { subject.list.map(image=> { image.base64.map(async sub => { let result = sub.base64Image; if (result) { this.filePath= await result.replace(/^data:image\/[a-z]+;base64,/, “”); this.filename = `image_${Date.now()}` const options: […]