You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by lsacco <oc...@gmail.com> on 2009/09/02 21:18:01 UTC

How to consume SharePoint Service Response (Java/.NET interop)?

We would like to connect a Java Web services CXF client to the SharePoint
List service.  After overcoming the NTLM issue, we see that the response is
not being properly returned to the client (it returns null).  We used the
Maven cxf-codegen-plugin wsdl2java to create the client stub classes that
would represent the results but we get back NULL every time. 

Here's the code to make the call and return the result (this all works
except for the return value is an empty list):

	public static GetListCollectionResult getListCollection(NTLMAuthenticator
auth, String endPoint) {
		Lists lists = new Lists();
		ListsSoap stub = lists.getListsSoap();

		BindingProvider bindProvider = (BindingProvider) stub;
		bindProvider.getRequestContext().put(
				BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);
		Authenticator.setDefault(auth);
		setConduit(stub);
                return stub.getListCollection();        
	}

Here is the sample output that repeats the List element that we can retrieve
using C#:

<Lists xmlns="http://schemas.microsoft.com/sharepoint/soap/">
	<List DocTemplateUrl="" DefaultViewUrl="/Lists/Audited Root Task
List/AllItems.aspx"
		MobileDefaultViewUrl="" ID="{AAAABEE6-CSDD-4C70-8AD0-567372066760}"
		Title="Audited Root Task List" Description=""
		ImageUrl="/_layouts/images/ittask.gif"
Name="{AAAABEE6-CSDD-4C70-8AD0-567372066760}"
		BaseType="0" FeatureId="00bfea71-a83e-497e-9ba0-7a5c597d0107"
		ServerTemplate="107" Created="20090805 06:31:27" Modified="20090818
06:09:13"
		LastDeleted="20090805 07:23:22" Version="35" Direction="none"
		ThumbnailSize="" WebImageWidth="" WebImageHeight="" Flags="549457920"
		ItemCount="5" AnonymousPermMask="0" RootFolder="" ReadSecurity="1"
		WriteSecurity="1" Author="55" EventSinkAssembly="" EventSinkClass=""
		EventSinkData="" EmailInsertsFolder="" EmailAlias="" WebFullUrl="/"
		WebId="2bdcc5a2-563f-477c-b6d9-cf26c0067b36" SendToLocation=""
		ScopeId="ca78103c-95d7-4ffd-8cf1-77eb3b9a37ae" MajorVersionLimit="0"
		MajorWithMinorVersionsLimit="0" WorkFlowId="" HasUniqueScopes="False"
		AllowDeletion="True" AllowMultiResponses="False" EnableAttachments="True"
		EnableModeration="False" EnableVersioning="False" Hidden="False"
		MultipleDataList="False" Ordered="False" ShowUser="True"
		EnableMinorVersion="False" RequireCheckout="False" />
...

Here is the generated wsdl2java class for JAXB binding of the response:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "getListCollectionResult"
})
@XmlRootElement(name = "GetListCollectionResponse")
public class GetListCollectionResponse {

    @XmlElement(name = "GetListCollectionResult")
    protected GetListCollectionResponse.GetListCollectionResult
getListCollectionResult;

    public GetListCollectionResponse.GetListCollectionResult
getGetListCollectionResult() {
        return getListCollectionResult;
    }

    public void
setGetListCollectionResult(GetListCollectionResponse.GetListCollectionResult
value) {
        this.getListCollectionResult = value;
    }

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "content"
    })
    public static class GetListCollectionResult {

        @XmlMixed
        @XmlAnyElement(lax = true)
        protected List content;

        public List getContent() {
            if (content == null) {
                content = new ArrayList();
            }
            return this.content;
        }
    }
}

Any ideas on how to bind the CAML formatted output from the SP Web service
so the response can be unmarshalled properly by JAXB?

TIA!
Lou
-- 
View this message in context: http://www.nabble.com/How-to-consume-SharePoint-Service-Response-%28Java-.NET-interop%29--tp25263932p25263932.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to consume SharePoint Service Response (Java/.NET interop)?

Posted by csaban <cs...@yahoo.ca>.
Yes, you need to add additional code to parse the XML yourself.
This interceptor just allows you to capture the XML, it won't fix/change the
returned List value.

But now that you have the XML you can extract what you need to process it.


Mike SP wrote:
> 
> I tried this interceptor below.  I added some printlns and saw that the
> originalXML string was being set correctly.  However, that string is not
> used anywhere so I'm not sure if this is missing some code or not.  The
> end result is that even though I can see that the correct data is
> available in the handleMessage, using that code below, it doesn't work
> still.  I still get the null List object back.  Is there additional code
> beyond this that is needed to make it work?  
> 
> 
> csaban wrote:
>> 
>> 
>> <code>
>> 	static class MyInterceptor extends AbstractPhaseInterceptor<Message> {
>> 		
>> 		public MyInterceptor() {
>> 			super(Phase.POST_STREAM);
>> 			
>> 			getBefore().add(StaxInInterceptor.class.getName());
>> 		}
>> 		
>> 		public void handleMessage(Message msg) throws
>> org.apache.cxf.interceptor.Fault {
>> 			InputStream is = msg.getContent(InputStream.class);
>>                         assert is != null;
>> 						
>> 			try {
>> 				byte[] byteContent = IOUtils.readBytesFromStream(is);
>> 				msg.setContent(InputStream.class, new
>> ByteArrayInputStream(byteContent));
>> 				String encoding = (String) msg.get(Message.ENCODING);
>> 				String originalXML = new String(byteContent,encoding);
>> 			} catch(Exception e) {
>> 				//FIXME: handle exception
>> 				e.printStackTrace();
>> 			}
>> 			
>> 		}
>> 	}
>> </code>
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-consume-SharePoint-Service-Response-%28Java-.NET-interop%29--tp25263932p28296456.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to consume SharePoint Service Response (Java/.NET interop)?

Posted by Mike SP <m....@monsanto.com>.
I tried this interceptor below.  I added some printlns and saw that the
originalXML string was being set correctly.  However, that string is not
used anywhere so I'm not sure if this is missing some code or not.  The end
result is that even though I can see that the correct data is available in
the handleMessage, using that code below, it doesn't work still.  I still
get the null List object back.  Is there additional code beyond this that is
needed to make it work?  


csaban wrote:
> 
> Oh yes, forgot to mention, another way would be with JAXB is to add an
> interceptor and process the stream before the StaxInInterceptor does.
> 
> eg:
> 
> <code>
> 	static class MyInterceptor extends AbstractPhaseInterceptor<Message> {
> 		
> 		public MyInterceptor() {
> 			super(Phase.POST_STREAM);
> 			
> 			getBefore().add(StaxInInterceptor.class.getName());
> 		}
> 		
> 		public void handleMessage(Message msg) throws
> org.apache.cxf.interceptor.Fault {
> 			InputStream is = msg.getContent(InputStream.class);
>                         assert is != null;
> 						
> 			try {
> 				byte[] byteContent = IOUtils.readBytesFromStream(is);
> 				msg.setContent(InputStream.class, new
> ByteArrayInputStream(byteContent));
> 				String encoding = (String) msg.get(Message.ENCODING);
> 				String originalXML = new String(byteContent,encoding);
> 			} catch(Exception e) {
> 				//FIXME: handle exception
> 				e.printStackTrace();
> 			}
> 			
> 		}
> 	}
> </code>
> 
> 
> csaban wrote:
>> 
>> Probably this is late now, but I was facing the same issue. (Sharepoint,
>> NTLMv2, List[null])
>> 
>> Using JAXB GetList always returned null, but switching to XMLBEANS I do
>> get the xml content of the getList response.
>> 
>> Hope this helps someone.
>> 
>> --
>> Csaba
>> 
>> 
>> mmule wrote:
>>> 
>>> Hello,
>>> 
>>> Do you have a solution for this yet? I am facing a similar issue. The
>>> CXF is returning null.
>>> 
>>> Please share if you have the solution.
>>> 
>>> Thanks
>>> M
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-consume-SharePoint-Service-Response-%28Java-.NET-interop%29--tp25263932p28288043.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to consume SharePoint Service Response (Java/.NET interop)?

Posted by csaban <cs...@yahoo.ca>.
Oh yes, forgot to mention, another way would be with JAXB is to add an
interceptor and process the stream before the StaxInInterceptor does.

eg:

<code>
	static class MyInterceptor extends AbstractPhaseInterceptor<Message> {
		
		public MyInterceptor() {
			super(Phase.POST_STREAM);
			
			getBefore().add(StaxInInterceptor.class.getName());
		}
		
		public void handleMessage(Message msg) throws
org.apache.cxf.interceptor.Fault {
			InputStream is = msg.getContent(InputStream.class);
                        assert is != null;
						
			try {
				byte[] byteContent = IOUtils.readBytesFromStream(is);
				msg.setContent(InputStream.class, new
ByteArrayInputStream(byteContent));
				String encoding = (String) msg.get(Message.ENCODING);
				String originalXML = new String(byteContent,encoding);
			} catch(Exception e) {
				//FIXME: handle exception
				e.printStackTrace();
			}
			
		}
	}
</code>


csaban wrote:
> 
> Probably this is late now, but I was facing the same issue. (Sharepoint,
> NTLMv2, List[null])
> 
> Using JAXB GetList always returned null, but switching to XMLBEANS I do
> get the xml content of the getList response.
> 
> Hope this helps someone.
> 
> --
> Csaba
> 
> 
> mmule wrote:
>> 
>> Hello,
>> 
>> Do you have a solution for this yet? I am facing a similar issue. The CXF
>> is returning null.
>> 
>> Please share if you have the solution.
>> 
>> Thanks
>> M
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-consume-SharePoint-Service-Response-%28Java-.NET-interop%29--tp25263932p28087647.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to consume SharePoint Service Response (Java/.NET interop)?

Posted by csaban <cs...@yahoo.ca>.
Probably this is late now, but I was facing the same issue. (Sharepoint,
NTLMv2, List[null])

Using JAXB GetList always returned null, but switching to XMLBEANS I do get
the xml content of the getList response.

Hope this helps someone.

--
Csaba


mmule wrote:
> 
> Hello,
> 
> Do you have a solution for this yet? I am facing a similar issue. The CXF
> is returning null.
> 
> Please share if you have the solution.
> 
> Thanks
> M
> 

-- 
View this message in context: http://old.nabble.com/How-to-consume-SharePoint-Service-Response-%28Java-.NET-interop%29--tp25263932p28087549.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to consume SharePoint Service Response (Java/.NET interop)?

Posted by mmule <mp...@harrisinteractive.com>.
Hello,

Do you have a solution for this yet? I am facing a similar issue. The CXF is
returning null.

Please share if you have the solution.

Thanks
M
-- 
View this message in context: http://www.nabble.com/How-to-consume-SharePoint-Service-Response-%28Java-.NET-interop%29--tp25263932p25812619.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: How to consume SharePoint Service Response (Java/.NET interop)?

Posted by Daniel Kulp <dk...@apache.org>.
USUALLY, this kind of error is a result of the message not actually matching 
the schema in the wsdl.  Normally, that is due to the schema not saying 
elementFormDefault="qualified" and then sending a message like you have below 
that qualifies everything.    I would double check the wsdl that was used to 
generate the code.

If using CXF 2.2.3, you can try add -xjc-npa  to the wsdl2java flags that 
would cause more information to be output in the annoations.   You  should 
expect to see namespace attributes on almost everything.

Dan


On Wed September 2 2009 3:18:01 pm lsacco wrote:
> We would like to connect a Java Web services CXF client to the SharePoint
> List service.  After overcoming the NTLM issue, we see that the response is
> not being properly returned to the client (it returns null).  We used the
> Maven cxf-codegen-plugin wsdl2java to create the client stub classes that
> would represent the results but we get back NULL every time.
> 
> Here's the code to make the call and return the result (this all works
> except for the return value is an empty list):
> 
> 	public static GetListCollectionResult getListCollection(NTLMAuthenticator
> auth, String endPoint) {
> 		Lists lists = new Lists();
> 		ListsSoap stub = lists.getListsSoap();
> 
> 		BindingProvider bindProvider = (BindingProvider) stub;
> 		bindProvider.getRequestContext().put(
> 				BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);
> 		Authenticator.setDefault(auth);
> 		setConduit(stub);
>                 return stub.getListCollection();
> 	}
> 
> Here is the sample output that repeats the List element that we can
>  retrieve using C#:
> 
> <Lists xmlns="http://schemas.microsoft.com/sharepoint/soap/">
> 	<List DocTemplateUrl="" DefaultViewUrl="/Lists/Audited Root Task
> List/AllItems.aspx"
> 		MobileDefaultViewUrl="" ID="{AAAABEE6-CSDD-4C70-8AD0-567372066760}"
> 		Title="Audited Root Task List" Description=""
> 		ImageUrl="/_layouts/images/ittask.gif"
> Name="{AAAABEE6-CSDD-4C70-8AD0-567372066760}"
> 		BaseType="0" FeatureId="00bfea71-a83e-497e-9ba0-7a5c597d0107"
> 		ServerTemplate="107" Created="20090805 06:31:27" Modified="20090818
> 06:09:13"
> 		LastDeleted="20090805 07:23:22" Version="35" Direction="none"
> 		ThumbnailSize="" WebImageWidth="" WebImageHeight="" Flags="549457920"
> 		ItemCount="5" AnonymousPermMask="0" RootFolder="" ReadSecurity="1"
> 		WriteSecurity="1" Author="55" EventSinkAssembly="" EventSinkClass=""
> 		EventSinkData="" EmailInsertsFolder="" EmailAlias="" WebFullUrl="/"
> 		WebId="2bdcc5a2-563f-477c-b6d9-cf26c0067b36" SendToLocation=""
> 		ScopeId="ca78103c-95d7-4ffd-8cf1-77eb3b9a37ae" MajorVersionLimit="0"
> 		MajorWithMinorVersionsLimit="0" WorkFlowId="" HasUniqueScopes="False"
> 		AllowDeletion="True" AllowMultiResponses="False" EnableAttachments="True"
> 		EnableModeration="False" EnableVersioning="False" Hidden="False"
> 		MultipleDataList="False" Ordered="False" ShowUser="True"
> 		EnableMinorVersion="False" RequireCheckout="False" />
> ...
> 
> Here is the generated wsdl2java class for JAXB binding of the response:
> 
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
>     "getListCollectionResult"
> })
> @XmlRootElement(name = "GetListCollectionResponse")
> public class GetListCollectionResponse {
> 
>     @XmlElement(name = "GetListCollectionResult")
>     protected GetListCollectionResponse.GetListCollectionResult
> getListCollectionResult;
> 
>     public GetListCollectionResponse.GetListCollectionResult
> getGetListCollectionResult() {
>         return getListCollectionResult;
>     }
> 
>     public void
> setGetListCollectionResult(GetListCollectionResponse.GetListCollectionResul
> t value) {
>         this.getListCollectionResult = value;
>     }
> 
>     @XmlAccessorType(XmlAccessType.FIELD)
>     @XmlType(name = "", propOrder = {
>         "content"
>     })
>     public static class GetListCollectionResult {
> 
>         @XmlMixed
>         @XmlAnyElement(lax = true)
>         protected List content;
> 
>         public List getContent() {
>             if (content == null) {
>                 content = new ArrayList();
>             }
>             return this.content;
>         }
>     }
> }
> 
> Any ideas on how to bind the CAML formatted output from the SP Web service
> so the response can be unmarshalled properly by JAXB?
> 
> TIA!
> Lou
> 

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog