Hi
I need to be using Microsoft's Exchange Web Services from Java - so I looked
at the C# samples and started porting. The autodiscovery bit is the most
disturbing.. lots of AD lookups and then there's a webservice that is none..
you do XML posts alright but there's no schema and no wsdl.
There's a C# sample in the SDK which contains classes that represent the
schema, including xml annotations so they can be serialized / deserialized
appropriately. So I figured the Java equivalent would be JAXB and started
building my own classes. That worked fine for the request itself (which only
has two parameters), but parsing the response proved to be an unsolvable
challenge (well.. there's obviously a workaround which is parsing manually).
Here's how the response looks like:
<Autodiscover
xmlns="
http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
<Response
xmlns="
http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
<User>
..
</User>
<Account>
..
<Protocol>
..
</Protocol>
<Protocol>
..
</Protocol>
</Account>
</Response>
</Autodiscover>
(I left out the simple elements inside the complex elements).
In case of an error
<Autodiscover
xmlns="
http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
<Response>
<Error Time="" Id="">
</Error>
</Response>
</Autodiscover>
So far I've looked at the error part since it's simpler.
My class hierarchy is AutoDiscoverResponse(AutoDiscover),
ErrorResponse(Response), Error(Error) for the error and
AutoDiscoveryResponse, OutlookData (Response), User(User), Account(Account),
Protocol (Protocol) for the normal case.
If I parse, I get the AutoDiscoverResponse and ErrorResponse.. Error remains
null.
So I went the reverse way.. .filled my objects, then serialized which gives
me the following:
<ns3:Autodiscover
xmlns:ns3="
http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006"
xmlns:ns2="
http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a"/>
<ns3:Response>
<Error Time="" Id="">
</Error>
</ns3:Response>
</ns3:Autodiscover>
So I'm wondering why there's an ns2 that is not used. If I take that string
above (fully filled out of course) and remove the xlmns:ns2=... attribute
from the AutoDiscover, deserialization still works. If I remove the ns3
prefix from Response tag.. I get an empty Error class inside of the
ErrorResponse class again. Even if I add the
xmlns="
http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006"
to the Response tag (so <Response
xmlns=""
http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">...</Response>)
which I figure should be correct, I still get an empty error class.
So I'm wondering.. is the XML that Exchange is sending me incorrect? If so,
why is the changed version just above still not properly parsed? Is it still
invalid, or is my class representation valid, am I not using JAXB properly
or is there an issue with JAXB?
BTW I've tried taking out the namespace out of the XmlRootElement
annotations for ErrorResponse / Error but to no avail.. and if I take it out
of the AutoDiscoverResponse, I get nothing parsed anymore).
Below you'll find the AutoDiscoveryResponse, ErrorResponse and Error classes
.
Regards
Stephan
@XmlRootElement(name="Autodiscover",
namespace="
http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006")
@XmlType(propOrder = {"outlookData", "errorResponse"})
public class AutoDiscoverResponse
{
private OutlookData outlookData;
private ErrorResponse errorResponse;
public AutoDiscoverResponse()
{
}
/**
* @return the outlookData
*/
@XmlElement(name="Response",
namespace="
http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a")
public OutlookData getOutlookData() {
return outlookData;
}
/**
* @param outlookData the outlookData to set
*/
public void setOutlookData(OutlookData outlookData) {
this.outlookData = outlookData;
}
/**
* @return the errorResponse
*/
@XmlElement(name="Response",
namespace="
http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006")
public ErrorResponse getErrorResponse() {
return errorResponse;
}
/**
* @param errorResponse the errorResponse to set
*/
public void setErrorResponse(ErrorResponse errorResponse) {
this.errorResponse = errorResponse;
}
}
@XmlRootElement(name="Response",
namespace="
http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006")
public class ErrorResponse
{
private Error error;
public ErrorResponse()
{
error = null;
}
/**
* @return the error
*/
@XmlElement(name="Error")
public Error getError() {
return error;
}
/**
* @param error the error to set
*/
public void setError(Error error) {
this.error = error;
}
}
@XmlRootElement(name="Error",
namespace="
http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006")
@XmlType(propOrder = {"errorCode", "message", "debugData"})
public class Error
{
private String time;
private String id;
private String errorCode;
private String message;
private String debugData;
public Error()
{
}
/**
* @return the time
*/
@XmlAttribute(name="Time")
public String getTime() {
return time;
}
/**
* @param time the time to set
*/
public void setTime(String time) {
this.time = time;
}
/**
* @return the id
*/
@XmlAttribute(name="Id")
public String getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the errorCode
*/
@XmlElement(name="ErrorCode")
public String getErrorCode() {
return errorCode;
}
/**
* @param errorCode the errorCode to set
*/
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
/**
* @return the message
*/
@XmlElement(name="Message")
public String getMessage() {
return message;
}
/**
* @param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}
/**
* @return the debugData
*/
@XmlElement(name="DebugData")
public String getDebugData() {
return debugData;
}
/**
* @param debugData the debugData to set
*/
public void setDebugData(String debugData) {
this.debugData = debugData;
}
}
--
View this message in context: http://www.nabble.com/Deserializion-issue-with-self-generated-and-annotated-classes-tp24640491p24640491.html
Sent from the java.net - jaxb dev mailing list archive at Nabble.com.