1

I have sent a GET REST call to "http://services.enterprisecloud.terremark.com/cloudapi/ecloud/organizations/" and the response is:

HTTP/1.1 200 OK Content-Length: 1373 Content-Type: application/vnd.tmrk.cloud.organization; type=collection x-tmrk-currentuser: /cloudapi/ecloud/admin/users/101 x-tmrk-token: cloud-F2A27F74-C04B-4566-AB53-CCC06DA2F798 Date: Thu, 12 May 2011 19:09:13 GMT 
<Organizations href="/cloudapi/ecloud/organizations" type="application/vnd.tmrk.cloud.organization; type=collection" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
.....
.....

There is an XSD given by the vendor which didn't generate any class of type Organization or Organizations. The Organization related class generated by JAXB is ArrayOfOrganization which looks like:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfOrganizationType", propOrder = {
    "organization"
})
public class ArrayOfOrganizationType {

    @XmlElement(name = "Organization", nillable = true)
    protected List<OrganizationType> organization;
....
....

When I try to use the following code:

ResponseEntity exchange = template.exchange(URL, 
                    HttpMethod.GET, 
                    new HttpEntity(operation.getInput(), operation.getHeader()), 
                    ArrayOfOrganizationType.class, 
                    urlVariables);

The error I get is:

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [com.trmk.dto.ArrayOfOrganizationType] and content type [application/vnd.tmrk.cloud.organization;type=collection]

In spring-dispatcher.xml, I have following:

<!-- Rest client -->
<bean id="httpClient" class="org.apache.http.impl.client.DefaultHttpClient">
    <constructor-arg>
        <bean class="org.apache.http.impl.conn.PoolingClientConnectionManager" />
    </constructor-arg>
</bean>

<bean id="restClient" class="com.transport.ext.RestClient">
</bean>

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
    <property name="messageConverters">
        <list>
           <bean id="marshallingHttpMessageConverter" 
            class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"
            p:marshaller-ref="jaxb2Marshaller" p:unmarshaller-ref="jaxb2Marshaller"
            p:supportedMediaTypes="application/vnd.tmrk.cloud.organization" />
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
        </list>
    </property>
</bean>

<bean id="jaxb2Marshaller" class="com.util.DefaultJaxb2Marshaller">
    <property name="classesToBeBound">
        <list>
            <value>java.lang.String</value>
    <value>com.trmk.dto.ArrayOfOrganizationType</value>
        </list>
    </property>
</bean>
<!-- End of Rest client -->

Any recommendation on how to proceed will be highly helpful as I have run out of ideas to solve this problem

1 Answer 1

1

You can try adding @XmlRootElement(name="Organizations") to ArrayOfOrganizationType although obviously that's not ideal since you'd need to re-add it each time you regenerate the JAXB classes.

Sign up to request clarification or add additional context in comments.

1 Comment

Good suggestion but for the time being I got it resolved by using the xml response I see in Terremark Cloud API explorer and then generating xsd from this xml (of course this xml is partial in the sense that it only deals with one operation). I then used this single operation xsd to generate JAXB classes and the whole thing works with the spring-dispatcher posted above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.