nightfixed
nightfixed

Reputation: 841

Cannot deserialize SOAP response using SimpleXML?

I am working on a library for UPnP connection with a local device. I get the following exception, when trying to parse response from one of the actions:

Problem: org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.Element(data=false, name=s:Body, required=true, type=class com.stuff.AssignedRolesResponseBody) on field 'responseBody' private com.stuff.AssignedRolesResponseBody com.stuff.AssignedRolesResponseEnvelope.responseBody for class com.stuff.AssignedRolesResponseEnvelope at line 1

Raw response that I am trying to parse:

<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <s:Body>
        <u:GetAssignedRolesResponse xmlns:u="urn:schemas-upnp-org:service:DeviceProtection:1">
            <RoleList>{something_here?}</RoleList>
        </u:GetAssignedRolesResponse>
    </s:Body>
</s:Envelope>

These are my POJOs:

ResponseEnvelope:

@Root(name = "s:Envelope")
@NamespaceList({
        @Namespace(prefix = "s", reference = "http://schemas.xmlsoap.org/soap/envelope/")
})
public class AssignedRolesResponseEnvelope extends XMLBaseResponse {

  @Element(name = "s:Body", type = AssignedRolesResponseBody.class)//I tried without specifiying the type here - no difference
  private AssignedRolesResponseBody responseBody;

  public AssignedRolesResponseBody getResponseBody() {
    return responseBody;
  }

  public void setResponseBody(AssignedRolesResponseBody responseBody) {
    this.responseBody = responseBody;
  }
}

Body:

public class AssignedRolesResponseBody {

  @Element(name = "u:GetAssignedRolesResponse")
  @NamespaceList({
          @Namespace(prefix = "u", reference = "urn:schemas-upnp-org:service:DeviceProtection:1")
  })
  private AssignedRolesResponseAction action;

  public AssignedRolesResponseAction getAction() {
    return action;
  }

  public void setAction(AssignedRolesResponseAction action) {
    this.action = action;
  }
}

Action:

public class AssignedRolesResponseAction {

  @Element(name = "RoleList")
  List<String> roleList;

  public List<String> getRoleList() {
    return roleList;
  }

  public void setRoleList(List<String> roleList) {
    this.roleList = roleList;
  }
}

Any input is much appreciated.

Upvotes: 1

Views: 150

Answers (1)

nightfixed
nightfixed

Reputation: 841

I will answer my own question. I made 3 changes to fix this:

1). Mapped the encodyngStyle as well, like this:

  @Attribute(name = "encodingStyle")
  public String encodingStyle;

2). Mapped the other entities without the prefix:

  @Element(name = "Body")
  private AssignedRolesResponseBody responseBody;

  @Element(name = "GetAssignedRolesResponse")
  private AssignedRolesResponseAction action;

3). Mapped the root of the Action:

@Root(name = "u:GetAssignedRolesResponse")
@Namespace(reference = "urn:schemas-upnp-org:service:DeviceProtection:1", prefix = "u")
public class AssignedRolesResponseAction {}

Upvotes: 1

Related Questions