Rest - newProjectDescription - bad request

Hi.

 

My TeamCity installation is up-to-date.

Rest debug is set in "Diagnostics":

2019-10-13 03:30:52,090] DEBUG [nio-8080-exec-2] - est.jersey.ExceptionMapperBase - Responding with error, status code: 400 (Bad Request). Details: javax.ws.rs.WebApplicationException: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.microsoft.com/2003/10/Serialization/", local:"string"). Expected elements are <{}VcsCheckStatus>,<{}agent>,<{}agent-requirement>,<{}agent-requirements>,<{}agentPool>,<{}agents>,<{}artifact-dependencies>,<{}artifact-dependency>,<{}authorizedInfo>,<{}booleanStatus>,<{}branch>,<{}branchVersion>,<{}branches>,<{}build>,<{}buildChange>,<{}buildChanges>,<{}buildTriggeringOptions>,<{}buildType>,<{}buildTypes>,<{}builds>,<{}change>,<{}changes>,<{}comment>,<{}compatibilities>,<{}compatibility>,<{}compatibilityPolicy>,<{}datas>,<{}enabledInfo>,<{}entries>,<{}entry>,<{}environment>,<{}feature>,<{}features>,<{}file>,<{}files>,<{}group>,<{}groups>,<{}href>,<{}investigation>,<{}investigations>,<{}issuesUsages>,<{}items>,<{}link>,<{}links>,<{}metaData>,<{}mute>,<{}mutes>,<{}newProjectDescription>,<{}problem>,<{}problemOccurrence>,<{}problemOccurrences>,<{}problems>,<{}progress-info>,<{}project>,<{}projectFeature>,<{}projectFeatures>,<{}projects>,<{}properties>,<{}property>,<{}related>,<{}repositoryState>,<{}requirements>,<{}role>,<{}roles>,<{}snapshot-dependencies>,<{}snapshot-dependency>,<{}step>,<{}steps>,<{}tag>,<{}tags>,<{}test>,<{}testOccurrence>,<{}testOccurrences>,<{}testRunMetadata>,<{}tests>,<{}trigger>,<{}triggers>,<{}type>,<{}typedValue>,<{}user>,<{}users>,<{}vcs-root>,<{}vcs-root-entries>,<{}vcs-root-entry>,<{}vcs-root-instance>,<{}vcs-root-instances>,<{}vcs-roots>,<{}vcsStatus>. Not supported request. Check that URL, HTTP method and transferred data are correct. Request: POST '/app/rest/projects', from client 127.0.0.1:53881, no user-agent, authenticated as 'admin' (Bo Hessner) {id=1}.
javax.ws.rs.WebApplicationException: javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.microsoft.com/2003/10/Serialization/", local:"string"). Expected elements are <{}VcsCheckStatus>,<{}agent>,<{}agent-requirement>,<{}agent-requirements>,<{}agentPool>,<{}agents>,<{}artifact-dependencies>,<{}artifact-dependency>,<{}authorizedInfo>,<{}booleanStatus>,<{}branch>,<{}branchVersion>,<{}branches>,<{}build>,<{}buildChange>,<{}buildChanges>,<{}buildTriggeringOptions>,<{}buildType>,<{}buildTypes>,<{}builds>,<{}change>,<{}changes>,<{}comment>,<{}compatibilities>,<{}compatibility>,<{}compatibilityPolicy>,<{}datas>,<{}enabledInfo>,<{}entries>,<{}entry>,<{}environment>,<{}feature>,<{}features>,<{}file>,<{}files>,<{}group>,<{}groups>,<{}href>,<{}investigation>,<{}investigations>,<{}issuesUsages>,<{}items>,<{}link>,<{}links>,<{}metaData>,<{}mute>,<{}mutes>,<{}newProjectDescription>,<{}problem>,<{}problemOccurrence>,<{}problemOccurrences>,<{}problems>,<{}progress-info>,<{}project>,<{}projectFeature>,<{}projectFeatures>,<{}projects>,<{}properties>,<{}property>,<{}related>,<{}repositoryState>,<{}requirements>,<{}role>,<{}roles>,<{}snapshot-dependencies>,<{}snapshot-dependency>,<{}step>,<{}steps>,<{}tag>,<{}tags>,<{}test>,<{}testOccurrence>,<{}testOccurrences>,<{}testRunMetadata>,<{}tests>,<{}trigger>,<{}triggers>,<{}type>,<{}typedValue>,<{}user>,<{}users>,<{}vcs-root>,<{}vcs-root-entries>,<{}vcs-root-entry>,<{}vcs-root-instance>,<{}vcs-root-instances>,<{}vcs-roots>,<{}vcsStatus>
at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:113) and so on.

 

My code:

 

_client = new HttpClient { BaseAddress = new Uri("http://teamcity:8080/app/rest/latest") };
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Add("Accept","application/xml");
_client.DefaultRequestHeaders.Add("Origin", "http://teamcity");

_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "<my token>");

private HttpResponseMessage Post(string subject, string data)
{
return _client.PostAsXmlAsync(subject, data).GetAwaiter().GetResult();
}

public void Can_Create_A_New_Project()
{
var response = Post("projects", "<newProjectDescription name='Rest Insert No' id='RestInsertNo'> <parentProject locator='id:RestTesting_Creating_Testing' /> </newProjectDescription>");
Assert.IsTrue(response.IsSuccessStatusCode);
}

 

It seems like some xml are missing or not valid - can you help?

 

Regards

/Bo

 

 

0
1 comment
Avatar
Permanently deleted user

Found the problem here:

return _client.PostAsXmlAsync(subject, data).GetAwaiter().GetResult();

 

Replaced with this code:

return _client.PostAsync(subject, new StringContent(data, Encoding.UTF8, "application/xml")).GetAwaiter().GetResult();

 

Was expecting that PostAsXmlAsync would do exactly that, but it dident...

0

Please sign in to leave a comment.