You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by glsilverman <gl...@pssd.com> on 2013/08/23 21:29:36 UTC

How can I configure and use SearchContext in CXFRS

I'm trying to configure a SearchContextProvider to use FIQL searches in my
CXFRS Restful application in OSGi using blueprint. There is documentation on
how to do this for straight CXF Restul services. For example, one can
register the provider in a <jaxrs:service> and use @Context to inject a
SerchContext., but I'm using <cxf:rsServer>, and a pass-through controller
class:

public class ControllerService {

@GET
@Path("/accounts")
@Produces("application/json")
public String getAccounts(){
 return null;
}

In my blueprint file, i tried this:

<cxf:rsServer id="restServer"
		address="http://${rest.server}:${port}/api"
serviceClass="com.dsi.edispense.cxf.ControllerService"
		loggingFeatureEnabled="true" loggingSizeLimit="200" >
		<cxf:providers>
			<bean id="searchContextProvider"
class="org.apache.cxf.jaxrs.ext.search.SearchContextProvider"/> 
		</cxf:providers>
	</cxf:rsServer>

<bean id="accountmanager' class=....AccountManager"/>

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
           <route id="accounts" streamCache="false">
			<from uri="cxfrs:bean:restServer?bindingStyle=SimpleConsumer" />
			<recipientList>
				<simple>direct:${header.operationName}</simple>
			</recipientList>
		</route>

		<route>
			<from uri="direct:getAccount" />
			<bean ref="accountmanager" method="getAccounts" />
		</route>

</camelContext>

When I try to inject a ServiceContext into my AccountManager class and use
it, I get a Exception: java.lang.NullPointerException.

Has anyone tried to use FIQL in Camel CXFRS and if so, how can I get it to
work?





--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-configure-and-use-SearchContext-in-CXFRS-tp5737843.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I configure and use SearchContext in CXFRS

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 03/09/13 19:48, glsilverman wrote:
> I think the problem with using Camel CXFRS for CXF configuration in blueprint
> is exactly how can one inject a SearchContext object when all you have is a
> SearchContextProvider, which acts as a factory for creating a SearchContext
> from a CXF message. There is no SearchContext bean that one can configure in
> blueprint, at least not that I can determine.
>
> If I use camel for routing my Restful calls, I can use @PathParam("id"), for
> example, and extract the id parameter from Camel message header, like so:
>
> @Header("id") String id
>
> But I don't have access to @Context as a parameter for my Restful methods,
> and even if I did, how would it be extracted from a Camel exchange. Would it
> show up as a Header, and if so, what would it be named?
>


I wonder if it would be simpler to use jaxrs:server directly in Camel 
context and use Camel Transport to route to it.

Cheers, Sergey


>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-configure-and-use-SearchContext-in-CXFRS-tp5737843p5738611.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



Re: How can I configure and use SearchContext in CXFRS

Posted by glsilverman <gl...@pssd.com>.
I think the problem with using Camel CXFRS for CXF configuration in blueprint
is exactly how can one inject a SearchContext object when all you have is a
SearchContextProvider, which acts as a factory for creating a SearchContext
from a CXF message. There is no SearchContext bean that one can configure in
blueprint, at least not that I can determine.

If I use camel for routing my Restful calls, I can use @PathParam("id"), for
example, and extract the id parameter from Camel message header, like so:

@Header("id") String id

But I don't have access to @Context as a parameter for my Restful methods,
and even if I did, how would it be extracted from a Camel exchange. Would it
show up as a Header, and if so, what would it be named?



--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-configure-and-use-SearchContext-in-CXFRS-tp5737843p5738611.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I configure and use SearchContext in CXFRS

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 26/08/13 16:11, glsilverman wrote:
> Thanks for your reply. I'm using Camel 2.11.1 and CXF version 2.7.5. The key
> dependency, as I nderstand it, is on cxf-rt-rs-extension-search, which is
> available. I'm running Karaf 2.3.2. I'm sure it's a configuration issue in
> blueprint and whether I have to do more than simply register
> SearchContextProvider as a cxf provider in order be able to inject a
> SerachContext object.
I'm only aware of the following issue resolved awhile back:
https://issues.apache.org/jira/browse/CXF-4508,

I've also seen users reporting Null contexts returned by the runtime 
when an actual FIQL expression contains the properties which can not be 
mapped to a bean; returning null in such cases seemed reasonable to me 
at a time because typically the users won't get an HTTP error back when 
mistyping some query - so please double check the expression can be 
mapped. Consider a workaround:  add SearchContext as method parameter, 
if it is still null then it is most likely not Camel CXFRS or Blueprint 
related issue

Other than that I've no idea what may be causing the issue - please 
consider creating a simple Camel-based test project and I will 
investigate further;

thanks, Sergey
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-configure-and-use-SearchContext-in-CXFRS-tp5737843p5737980.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


Re: How can I configure and use SearchContext in CXFRS

Posted by glsilverman <gl...@pssd.com>.
Thanks for your reply. I'm using Camel 2.11.1 and CXF version 2.7.5. The key
dependency, as I nderstand it, is on cxf-rt-rs-extension-search, which is
available. I'm running Karaf 2.3.2. I'm sure it's a configuration issue in
blueprint and whether I have to do more than simply register
SearchContextProvider as a cxf provider in order be able to inject a
SerachContext object.



--
View this message in context: http://camel.465427.n5.nabble.com/How-can-I-configure-and-use-SearchContext-in-CXFRS-tp5737843p5737980.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How can I configure and use SearchContext in CXFRS

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

I recall there was a related issue to do with injecting CXF 
SearchContext in OSGI applications, it was caused by some missing 
import-package statements but was fixed.

Which Camel version do you work with ? And as far as standalone CXF is 
concerned, which version did you use ?

Cheers, Sergey

On 23/08/13 22:29, glsilverman wrote:
> I'm trying to configure a SearchContextProvider to use FIQL searches in my
> CXFRS Restful application in OSGi using blueprint. There is documentation on
> how to do this for straight CXF Restul services. For example, one can
> register the provider in a <jaxrs:service> and use @Context to inject a
> SerchContext., but I'm using <cxf:rsServer>, and a pass-through controller
> class:
>
> public class ControllerService {
>
> @GET
> @Path("/accounts")
> @Produces("application/json")
> public String getAccounts(){
>   return null;
> }
>
> In my blueprint file, i tried this:
>
> <cxf:rsServer id="restServer"
> 		address="http://${rest.server}:${port}/api"
> serviceClass="com.dsi.edispense.cxf.ControllerService"
> 		loggingFeatureEnabled="true" loggingSizeLimit="200" >
> 		<cxf:providers>
> 			<bean id="searchContextProvider"
> class="org.apache.cxf.jaxrs.ext.search.SearchContextProvider"/>
> 		</cxf:providers>
> 	</cxf:rsServer>
>
> <bean id="accountmanager' class=....AccountManager"/>
>
> <camelContext xmlns="http://camel.apache.org/schema/blueprint">
>             <route id="accounts" streamCache="false">
> 			<from uri="cxfrs:bean:restServer?bindingStyle=SimpleConsumer" />
> 			<recipientList>
> 				<simple>direct:${header.operationName}</simple>
> 			</recipientList>
> 		</route>
>
> 		<route>
> 			<from uri="direct:getAccount" />
> 			<bean ref="accountmanager" method="getAccounts" />
> 		</route>
>
> </camelContext>
>
> When I try to inject a ServiceContext into my AccountManager class and use
> it, I get a Exception: java.lang.NullPointerException.
>
> Has anyone tried to use FIQL in Camel CXFRS and if so, how can I get it to
> work?
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-can-I-configure-and-use-SearchContext-in-CXFRS-tp5737843.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>