Ask Your Question

Jersey JAVA REST Client giving Error 500 “BAD Request” for POST request, while POSTMAN is able POST to same SDC REST API

asked 2018-01-17 07:09:56 -0600

Vijay Shekhawat gravatar image

updated 2018-01-18 02:56:23 -0600

I am trying to post form data through a JAVA Jersey REST client but i receive the response code 500 and an according exception:

java.lang.RuntimeException: Failed with HTTP error code : 500

The same request from POSTMAN(Chrome Extention) works successfully.

I am making a POST request to StreamSets Data Collector API.

My POM.xml is

   <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="" xmlns:xsi="
 instance" xsi:schemaLocation="
<!-- Jersey core Servlet 2.x implementation -->

<!-- Jersey Multipart entity providers support module -->

Below is my Code

import java.util.Base64;
import org.glassfish.jersey.client.ClientConfig;

public static String testUploadService(String httpURL, File filePath)  throws Exception {

// local variables
ClientConfig clientConfig = null;
Client client = null;
WebTarget webTarget = null;
Invocation.Builder invocationBuilder = null;
Response response = null;
FileDataBodyPart fileDataBodyPart = null;
FormDataMultiPart formDataMultiPart = null;
int responseCode;
String responseMessageFromServer = null;
String responseString = null;
  String name = "*******";
String password = "*******";
String authString = name + ":" + password;
String sdc="sdc";
byte[] encoding = Base64.getEncoder().encode(authString.getBytes());
byte[] encoding2 = Base64.getEncoder().encode(sdc.getBytes());
String USER_PASS = new String(encoding);
String auth2=new String(encoding2);


    ClientConfig cc = new ClientConfig();

    try {
    client = new JerseywithSSL().initClient(cc);
    } catch (KeyManagementException e) {
    } catch (NoSuchAlgorithmException e) { 
    webTarget =;

    // set file upload values
    fileDataBodyPart = new FileDataBodyPart("uploadFile", filePath, MediaType.MULTIPART_FORM_DATA_TYPE);
    formDataMultiPart = new FormDataMultiPart();

    // invoke service
    invocationBuilder = webTarget.request();
              invocationBuilder.header("Authorization", "Basic " + USER_PASS);
              invocationBuilder.header("X-Requested-By","SDC"); //Additional Header requiered by Streamsets RestAPI
             invocationBuilder.header("Content-type", "multipart/form-data");
    response =, MediaType.MULTIPART_FORM_DATA));

    // get response code
    responseCode = response.getStatus();
    System.out.println("Response code: " + responseCode);

    if (response.getStatus() != 200) {
        throw new RuntimeException("Failed with HTTP error code : " + responseCode);

    // get response message ...
edit retag flag offensive close merge delete


Can you add your imports? It's really hard to compile and run your example without them.

metadaddy gravatar imagemetadaddy ( 2018-01-17 13:46:25 -0600 )edit

@metadaddy Please have a look at updated question, I have included the all the imports and error stack trace .

Vijay Shekhawat gravatar imageVijay Shekhawat ( 2018-01-18 02:55:03 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-01-17 12:46:55 -0600

jeff gravatar image

To clarify, you are writing some code that will post to the SDC API? The most straightforward way to see what's going wrong is to check the sdc.log on the SDC instance that is handling the request. Failing that, you can probably enable logging in your client code to show the full response headers/payload, which should shed some more light on what the server reports as being the error. Here is how you do that in Jersey, for example (it's not clear to me what client you're using from the snippet above).

edit flag offensive delete link more


Yes, I am Indeed trying to POST pipelines to SDC API and I am using Jersey for the same. Have a look at my updated question.

Vijay Shekhawat gravatar imageVijay Shekhawat ( 2018-01-18 02:55:32 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-01-17 07:09:56 -0600

Seen: 74 times

Last updated: Jan 18