Jaxb unmarshal works on debug but not in runtime

267 views Asked by At

I'm trying to use the ACS (Cisco Secure Access Control System) to manage users in the network equipment using code. I've downloaded the examples provided with the product and built upon that, my code.

When I test it in debug mode, everything works great but when I put my .class files in Jboss Web Server and try to execute the main method from another application, I get this error:

unexpected element (uri:identity.rest.mgmt.acs.nm.cisco.com", local:"user"). Expected elements are (none)

my code is:

private static User getUserByName(RestFacade restFacade, String name)  
{
    User user = null;
    String url = "/Rest/Identity/User/name/";
    url = url.concat(name);
    HttpResponse response = restFacade.get(url);
    try {
        byte buffer[] = new byte[8192];
        int read = 0;
        StringBuffer responseBody = new StringBuffer();
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream content = response.getEntity().getContent();
            while ((read = content.read(buffer)) != -1) {
                responseBody.append(new String(buffer, 0, read));
            }
        }

        ByteArrayInputStream bais = new ByteArrayInputStream(responseBody
                .toString().getBytes());

        Unmarshaller unmarshaller = JAXBContext.newInstance(User.class).createUnmarshller();
        user = (User) unmarshaller.unmarshal(bais);

        } catch (Exception e) {
            e.printStackTrace();
        }
    return user;
}

Almost every solution I found for such an error, said to change something in the Rest method I'm trying to invoke or change the xsd, but I don't have access to those..

The weird thing is that it works when I debug from Eclipse but not on runtime. Maybe there's a different version to JAXB I'm using? How can I be sure which jar loads up?

Thank you, Igor.

1

There are 1 answers

1
Thomas Uebel On

That sounds like your development environment you use to debug and your target application server have a different version of either the JAXB classes / library and/or the used XSDs.

The documentation (http://www.cisco.com/c/en/us/td/docs/net_mgmt/cisco_secure_access_control_system/5-3/sdk/acs_sdk/rest.html) specifies the three XSDs (Common, Identity and Query).

Have you verified the version you have (or have downloaded) match the generated JAXB classes on the target application server?