You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Gill Bates <gi...@gmail.com> on 2008/12/16 01:06:36 UTC

file path after transfer in cxf

Hi all,
I've recently implement a method transfer byte[] through webservice  
and then write it to the file at my server side.
But then here comes the problem.
If it's in web controller action, I could use  
request.getSession().getServletContext().getRealPath() to get the path  
of webroot.
But in cxf there's no such request object.
What if I want to transfer the file to WebRoot/upload directory?
I tried something like MyClass.class.getResources("/").getPath() to  
get the path of current class , and then append some strings to get  
the real path of WebRoot/upload, but it looks different in different  
web containers.

Anyone has an better idea?

Yours
Yanchuan Li

Re: file path after transfer in cxf

Posted by Sergey Beryozkin <se...@progress.com>.
You can get it in your jaxws application like this :
@Resource WebServiceContext context;

HttpServletRequest request = (HttpServletRequest)context.getMessageContext()
          .get(MessageContext.SERVLET_REQUEST);

Cheers, Sergey

----- Original Message ----- 
From: "Gill Bates" <gi...@gmail.com>
To: <de...@cxf.apache.org>
Sent: Tuesday, December 16, 2008 12:06 AM
Subject: file path after transfer in cxf


> Hi all,
> I've recently implement a method transfer byte[] through webservice  
> and then write it to the file at my server side.
> But then here comes the problem.
> If it's in web controller action, I could use  
> request.getSession().getServletContext().getRealPath() to get the path  
> of webroot.
> But in cxf there's no such request object.
> What if I want to transfer the file to WebRoot/upload directory?
> I tried something like MyClass.class.getResources("/").getPath() to  
> get the path of current class , and then append some strings to get  
> the real path of WebRoot/upload, but it looks different in different  
> web containers.
> 
> Anyone has an better idea?
> 
> Yours
> Yanchuan Li

Re: file path after transfer in cxf

Posted by Daniel Kulp <dk...@apache.org>.
Is your server a JAX-WS service?   If so, this is part of the standard.

If you do:
@Resource
WebServiceContext context;
to get the context, then in your method, you can do:

ServletContext servCtx = context.getMessageContext()
                     .get(MessageContext.SERVLET_CONTEXT);

Dan



On Monday 15 December 2008 7:06:36 pm Gill Bates wrote:
> Hi all,
> I've recently implement a method transfer byte[] through webservice
> and then write it to the file at my server side.
> But then here comes the problem.
> If it's in web controller action, I could use
> request.getSession().getServletContext().getRealPath() to get the path
> of webroot.
> But in cxf there's no such request object.
> What if I want to transfer the file to WebRoot/upload directory?
> I tried something like MyClass.class.getResources("/").getPath() to
> get the path of current class , and then append some strings to get
> the real path of WebRoot/upload, but it looks different in different
> web containers.
>
> Anyone has an better idea?
>
> Yours
> Yanchuan Li



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