Hi Bill (bstephens),
Thanks for your reply.
Please find below my answers-
- "Target host is not specified": "https://paxataurl:portnumber" is not a valid host/port combination. You need to substitute your actual Paxata server name and port. - Yes. I replaced my actual server url and port number with some random text while posting my question here.
- The "-F" entry is specific to curl. This won't work from Java. - Thanks. I removed -F
- Your SQL query string needs to be URL Encoded - Thanks. I did this.
I did get the error
The method encodeBase64(byte[]) is undefined for the type Base64 when using
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("UTF-8")));
As an alternative, I used below method-
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(Charset.forName("UTF-8")));
Here is my complete java code.
@RestController
public class Test {
@RequestMapping(value = "/query", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "This API posts a new dataset in paxata against a query")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Successfully added new dataset details in paxata"),
@ApiResponse(code = 404, message = "Unable to add new dataset details in paxata"),
@ApiResponse(code = 500, message = "Internal server error") })
@ResponseBody
public InputStream DatasourceImport(String name, String dataSourceId, String query) throws ClientProtocolException,Exception {
dataSourceId="1234567890";
query = "select * from empschema.employee_table";
name = "Testing_dataset";
String encodedQuery = URLEncoder.encode(query, StandardCharsets.UTF_8.toString());
String url = "https://paxataurl:portnumber/rest/datasource/imports/" + dataSourceId + "?name=" + name + "&query=" + encodedQuery;
HttpClient client = HttpClientBuilder.create().build();
HttpPost postRequest = new HttpPost(url);
postRequest.addHeader("Content-Type", "application/json");
String auth = ":12345678";
byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(Charset.forName("UTF-8")));
String authHeader = "Basic " + new String(encodedAuth);
postRequest.addHeader(HttpHeaders.AUTHORIZATION, authHeader);
HttpResponse response = client.execute(postRequest);
HttpEntity entity = new BufferedHttpEntity(response.getEntity());
return entity.getContent();
}
}
Now, I am getting error as below-
DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type '' not supported]
Even after setting Content-Type error is not resolved.
Kindly help.
Regards,
Abhijeet