Getting bad request from an API using RestEasyWebTarget












0















I am trying to connect to an api using RestEasyWebTarget, and I dont have a problem when I use get to some endpoints, but now I want to connect to a POST and PUT endpoint and I am getting some bad request . I think I might be doing this wrong.



I tried this with curl and it works



curl -u backendserver:password -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/ramona/instances/_definst_/streamrecorders/jdc -d '
{
"instanceName": "",
"fileVersionDelegateName": "",
"serverName": "",
"recorderName": "jdc",
"currentSize": 0,
"segmentSchedule": "",
"startOnKeyFrame": true,
"outputPath": "",
"currentFile": "",
"saveFieldList": [
""
],
"recordData": false,
"applicationName": "",
"moveFirstVideoFrameToZero": false,
"recorderErrorString": "",
"segmentSize": 0,
"defaultRecorder": false,
"splitOnTcDiscontinuity": false,
"version": "",
"baseFile": "",
"segmentDuration": 0,
"recordingStartTime": "",
"fileTemplate": "",
"backBufferTime": 0,
"segmentationType": "",
"currentDuration": 0,
"fileFormat": "",
"recorderState": "",
"option": ""
}
'


{"success":true,"message":"Recorder Created","data":null}



So I tried to mimic this with resteasy.
This is my code



public void grabar(final String streamName) throws InterruptedException {
System.out.println("Empezar a grabar");
clientREST = new ResteasyClientBuilder().build();
clientREST.register(new BasicAuthentication(userWowza, passWowza));
String targetStr = "http://" + host + ":" + portEndpoint + endPoint + app + "/instances/_definst_/streamrecorders/"+streamName;
//http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/streamrecorders/myStream
System.out.println("target: " + targetStr);

ResteasyWebTarget target = clientREST.target(targetStr);

target.register(new BasicAuthentication(userWowza, passWowza));

StreamRecorderConfigDTO recorder = new StreamRecorderConfigDTO();

recorder.setRecorderName(streamName);
recorder.setCurrentSize(0);
recorder.setStartOnKeyFrame(true);
recorder.setRecordData(false);
recorder.setSegmentSize(0);
recorder.setDefaultRecorder(false);
recorder.setMoveFirstVideoFrameToZero(false);
recorder.setSplitOnTcDiscontinuity(false);
recorder.setSegmentDuration(0);
recorder.setBackBufferTime(0);
recorder.setCurrentDuration(0);
recorder.setFileFormat("MP4");
recorder.setApplicationName("ramona");
recorder.setBaseFile(streamName+".mp4");


Response response = target.request().
post(Entity.entity(recorder, "application/json; charset=utf-8"));

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

response.close();

}


But every time I get 400 bad request. So I guess everything points out that I am not passing correctly my StreamRecorderConfigDTO object. Should I post my StreamRecorderConfigDTO class too?



*****Update



I changed the target to add the headers



Response response = target.request().header("Content-Type", "application/json; charset=utf-8").accept(MediaType.APPLICATION_JSON).post(Entity.entity(recorder, MediaType.APPLICATION_JSON));
int status = response.getStatus();

response.close();

if (status != 200) {
throw new RuntimeException("Failed : HTTP error code : " + status);
}









share|improve this question

























  • post the error message with stack trace

    – Deadpool
    Oct 3 '18 at 23:56











  • Seems that you are missing headers

    – rpax
    Oct 4 '18 at 5:18











  • @rpax post(Entity.entity(recorder, "application/json; charset=utf-8")); isnt this in the headers i also had target.request().accept("application/json").

    – Juan Diego
    Oct 4 '18 at 16:40











  • @rpax I updated my question with headers I still get the same error.

    – Juan Diego
    Nov 21 '18 at 21:46
















0















I am trying to connect to an api using RestEasyWebTarget, and I dont have a problem when I use get to some endpoints, but now I want to connect to a POST and PUT endpoint and I am getting some bad request . I think I might be doing this wrong.



I tried this with curl and it works



curl -u backendserver:password -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/ramona/instances/_definst_/streamrecorders/jdc -d '
{
"instanceName": "",
"fileVersionDelegateName": "",
"serverName": "",
"recorderName": "jdc",
"currentSize": 0,
"segmentSchedule": "",
"startOnKeyFrame": true,
"outputPath": "",
"currentFile": "",
"saveFieldList": [
""
],
"recordData": false,
"applicationName": "",
"moveFirstVideoFrameToZero": false,
"recorderErrorString": "",
"segmentSize": 0,
"defaultRecorder": false,
"splitOnTcDiscontinuity": false,
"version": "",
"baseFile": "",
"segmentDuration": 0,
"recordingStartTime": "",
"fileTemplate": "",
"backBufferTime": 0,
"segmentationType": "",
"currentDuration": 0,
"fileFormat": "",
"recorderState": "",
"option": ""
}
'


{"success":true,"message":"Recorder Created","data":null}



So I tried to mimic this with resteasy.
This is my code



public void grabar(final String streamName) throws InterruptedException {
System.out.println("Empezar a grabar");
clientREST = new ResteasyClientBuilder().build();
clientREST.register(new BasicAuthentication(userWowza, passWowza));
String targetStr = "http://" + host + ":" + portEndpoint + endPoint + app + "/instances/_definst_/streamrecorders/"+streamName;
//http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/streamrecorders/myStream
System.out.println("target: " + targetStr);

ResteasyWebTarget target = clientREST.target(targetStr);

target.register(new BasicAuthentication(userWowza, passWowza));

StreamRecorderConfigDTO recorder = new StreamRecorderConfigDTO();

recorder.setRecorderName(streamName);
recorder.setCurrentSize(0);
recorder.setStartOnKeyFrame(true);
recorder.setRecordData(false);
recorder.setSegmentSize(0);
recorder.setDefaultRecorder(false);
recorder.setMoveFirstVideoFrameToZero(false);
recorder.setSplitOnTcDiscontinuity(false);
recorder.setSegmentDuration(0);
recorder.setBackBufferTime(0);
recorder.setCurrentDuration(0);
recorder.setFileFormat("MP4");
recorder.setApplicationName("ramona");
recorder.setBaseFile(streamName+".mp4");


Response response = target.request().
post(Entity.entity(recorder, "application/json; charset=utf-8"));

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

response.close();

}


But every time I get 400 bad request. So I guess everything points out that I am not passing correctly my StreamRecorderConfigDTO object. Should I post my StreamRecorderConfigDTO class too?



*****Update



I changed the target to add the headers



Response response = target.request().header("Content-Type", "application/json; charset=utf-8").accept(MediaType.APPLICATION_JSON).post(Entity.entity(recorder, MediaType.APPLICATION_JSON));
int status = response.getStatus();

response.close();

if (status != 200) {
throw new RuntimeException("Failed : HTTP error code : " + status);
}









share|improve this question

























  • post the error message with stack trace

    – Deadpool
    Oct 3 '18 at 23:56











  • Seems that you are missing headers

    – rpax
    Oct 4 '18 at 5:18











  • @rpax post(Entity.entity(recorder, "application/json; charset=utf-8")); isnt this in the headers i also had target.request().accept("application/json").

    – Juan Diego
    Oct 4 '18 at 16:40











  • @rpax I updated my question with headers I still get the same error.

    – Juan Diego
    Nov 21 '18 at 21:46














0












0








0








I am trying to connect to an api using RestEasyWebTarget, and I dont have a problem when I use get to some endpoints, but now I want to connect to a POST and PUT endpoint and I am getting some bad request . I think I might be doing this wrong.



I tried this with curl and it works



curl -u backendserver:password -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/ramona/instances/_definst_/streamrecorders/jdc -d '
{
"instanceName": "",
"fileVersionDelegateName": "",
"serverName": "",
"recorderName": "jdc",
"currentSize": 0,
"segmentSchedule": "",
"startOnKeyFrame": true,
"outputPath": "",
"currentFile": "",
"saveFieldList": [
""
],
"recordData": false,
"applicationName": "",
"moveFirstVideoFrameToZero": false,
"recorderErrorString": "",
"segmentSize": 0,
"defaultRecorder": false,
"splitOnTcDiscontinuity": false,
"version": "",
"baseFile": "",
"segmentDuration": 0,
"recordingStartTime": "",
"fileTemplate": "",
"backBufferTime": 0,
"segmentationType": "",
"currentDuration": 0,
"fileFormat": "",
"recorderState": "",
"option": ""
}
'


{"success":true,"message":"Recorder Created","data":null}



So I tried to mimic this with resteasy.
This is my code



public void grabar(final String streamName) throws InterruptedException {
System.out.println("Empezar a grabar");
clientREST = new ResteasyClientBuilder().build();
clientREST.register(new BasicAuthentication(userWowza, passWowza));
String targetStr = "http://" + host + ":" + portEndpoint + endPoint + app + "/instances/_definst_/streamrecorders/"+streamName;
//http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/streamrecorders/myStream
System.out.println("target: " + targetStr);

ResteasyWebTarget target = clientREST.target(targetStr);

target.register(new BasicAuthentication(userWowza, passWowza));

StreamRecorderConfigDTO recorder = new StreamRecorderConfigDTO();

recorder.setRecorderName(streamName);
recorder.setCurrentSize(0);
recorder.setStartOnKeyFrame(true);
recorder.setRecordData(false);
recorder.setSegmentSize(0);
recorder.setDefaultRecorder(false);
recorder.setMoveFirstVideoFrameToZero(false);
recorder.setSplitOnTcDiscontinuity(false);
recorder.setSegmentDuration(0);
recorder.setBackBufferTime(0);
recorder.setCurrentDuration(0);
recorder.setFileFormat("MP4");
recorder.setApplicationName("ramona");
recorder.setBaseFile(streamName+".mp4");


Response response = target.request().
post(Entity.entity(recorder, "application/json; charset=utf-8"));

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

response.close();

}


But every time I get 400 bad request. So I guess everything points out that I am not passing correctly my StreamRecorderConfigDTO object. Should I post my StreamRecorderConfigDTO class too?



*****Update



I changed the target to add the headers



Response response = target.request().header("Content-Type", "application/json; charset=utf-8").accept(MediaType.APPLICATION_JSON).post(Entity.entity(recorder, MediaType.APPLICATION_JSON));
int status = response.getStatus();

response.close();

if (status != 200) {
throw new RuntimeException("Failed : HTTP error code : " + status);
}









share|improve this question
















I am trying to connect to an api using RestEasyWebTarget, and I dont have a problem when I use get to some endpoints, but now I want to connect to a POST and PUT endpoint and I am getting some bad request . I think I might be doing this wrong.



I tried this with curl and it works



curl -u backendserver:password -X POST --header 'Accept:application/json; charset=utf-8' --header 'Content-Type:application/json; charset=utf-8' http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/ramona/instances/_definst_/streamrecorders/jdc -d '
{
"instanceName": "",
"fileVersionDelegateName": "",
"serverName": "",
"recorderName": "jdc",
"currentSize": 0,
"segmentSchedule": "",
"startOnKeyFrame": true,
"outputPath": "",
"currentFile": "",
"saveFieldList": [
""
],
"recordData": false,
"applicationName": "",
"moveFirstVideoFrameToZero": false,
"recorderErrorString": "",
"segmentSize": 0,
"defaultRecorder": false,
"splitOnTcDiscontinuity": false,
"version": "",
"baseFile": "",
"segmentDuration": 0,
"recordingStartTime": "",
"fileTemplate": "",
"backBufferTime": 0,
"segmentationType": "",
"currentDuration": 0,
"fileFormat": "",
"recorderState": "",
"option": ""
}
'


{"success":true,"message":"Recorder Created","data":null}



So I tried to mimic this with resteasy.
This is my code



public void grabar(final String streamName) throws InterruptedException {
System.out.println("Empezar a grabar");
clientREST = new ResteasyClientBuilder().build();
clientREST.register(new BasicAuthentication(userWowza, passWowza));
String targetStr = "http://" + host + ":" + portEndpoint + endPoint + app + "/instances/_definst_/streamrecorders/"+streamName;
//http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/live/instances/_definst_/streamrecorders/myStream
System.out.println("target: " + targetStr);

ResteasyWebTarget target = clientREST.target(targetStr);

target.register(new BasicAuthentication(userWowza, passWowza));

StreamRecorderConfigDTO recorder = new StreamRecorderConfigDTO();

recorder.setRecorderName(streamName);
recorder.setCurrentSize(0);
recorder.setStartOnKeyFrame(true);
recorder.setRecordData(false);
recorder.setSegmentSize(0);
recorder.setDefaultRecorder(false);
recorder.setMoveFirstVideoFrameToZero(false);
recorder.setSplitOnTcDiscontinuity(false);
recorder.setSegmentDuration(0);
recorder.setBackBufferTime(0);
recorder.setCurrentDuration(0);
recorder.setFileFormat("MP4");
recorder.setApplicationName("ramona");
recorder.setBaseFile(streamName+".mp4");


Response response = target.request().
post(Entity.entity(recorder, "application/json; charset=utf-8"));

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

response.close();

}


But every time I get 400 bad request. So I guess everything points out that I am not passing correctly my StreamRecorderConfigDTO object. Should I post my StreamRecorderConfigDTO class too?



*****Update



I changed the target to add the headers



Response response = target.request().header("Content-Type", "application/json; charset=utf-8").accept(MediaType.APPLICATION_JSON).post(Entity.entity(recorder, MediaType.APPLICATION_JSON));
int status = response.getStatus();

response.close();

if (status != 200) {
throw new RuntimeException("Failed : HTTP error code : " + status);
}






java resteasy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 21:45







Juan Diego

















asked Oct 3 '18 at 19:53









Juan DiegoJuan Diego

74331342




74331342













  • post the error message with stack trace

    – Deadpool
    Oct 3 '18 at 23:56











  • Seems that you are missing headers

    – rpax
    Oct 4 '18 at 5:18











  • @rpax post(Entity.entity(recorder, "application/json; charset=utf-8")); isnt this in the headers i also had target.request().accept("application/json").

    – Juan Diego
    Oct 4 '18 at 16:40











  • @rpax I updated my question with headers I still get the same error.

    – Juan Diego
    Nov 21 '18 at 21:46



















  • post the error message with stack trace

    – Deadpool
    Oct 3 '18 at 23:56











  • Seems that you are missing headers

    – rpax
    Oct 4 '18 at 5:18











  • @rpax post(Entity.entity(recorder, "application/json; charset=utf-8")); isnt this in the headers i also had target.request().accept("application/json").

    – Juan Diego
    Oct 4 '18 at 16:40











  • @rpax I updated my question with headers I still get the same error.

    – Juan Diego
    Nov 21 '18 at 21:46

















post the error message with stack trace

– Deadpool
Oct 3 '18 at 23:56





post the error message with stack trace

– Deadpool
Oct 3 '18 at 23:56













Seems that you are missing headers

– rpax
Oct 4 '18 at 5:18





Seems that you are missing headers

– rpax
Oct 4 '18 at 5:18













@rpax post(Entity.entity(recorder, "application/json; charset=utf-8")); isnt this in the headers i also had target.request().accept("application/json").

– Juan Diego
Oct 4 '18 at 16:40





@rpax post(Entity.entity(recorder, "application/json; charset=utf-8")); isnt this in the headers i also had target.request().accept("application/json").

– Juan Diego
Oct 4 '18 at 16:40













@rpax I updated my question with headers I still get the same error.

– Juan Diego
Nov 21 '18 at 21:46





@rpax I updated my question with headers I still get the same error.

– Juan Diego
Nov 21 '18 at 21:46












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52634724%2fgetting-bad-request-from-an-api-using-resteasywebtarget%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52634724%2fgetting-bad-request-from-an-api-using-resteasywebtarget%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?