I'd say this is a good example to use policy, but while we don't have
this available for the web 2.0 bindings, maybe you should have your
method receiving the userContext rather then HTTP specific model
objects.

On Wed, Aug 27, 2008 at 12:00 AM, ZhiYong Mao <[EMAIL PROTECTED]> wrote:
> Hi
> So how to get context(such as login information) from HTTP request? We need
> it for remote call by JSON-RPC because of security, we can not allow anybody
> to use our services, which are just for logged users.
>
> As I knew, JSON-RPC supports HTTP request parameter, why not support it in
> Tuscany?
>
> Best regards!
>
> Jacky Mao , Software Engineer
> IBM GPSG Wuhan Perform Center
> Tel : 0086-027-87406266-1212
> E-Mail: [EMAIL PROTECTED]
> "Luciano Resende" <[EMAIL PROTECTED]>
>
>
> "Luciano Resende" <[EMAIL PROTECTED]>
>
> 2008-08-27 14:35
>
> Please respond to
> user@tuscany.apache.org
>
> To
> user@tuscany.apache.org
> cc
>
> Subject
> Re: I have tried to inject HTTP request or session into service Java bean
> One of the SCA goals is to allow developers to concentrate in the
> business logic, and leave the infrastructure details for the runtime.
> The idea is that you can have your component implementation and then
> use SCA Bindings to expose it's services using multiple protocols (e.g
> using json-rpc, rmi or jms).
>
> Based on this, could you please elaborate on your
> requirements/scenarios to pass HTTP specific objects to the business
> interface. Also, what if you need to start exposing your service via a
> different binding that does not understand HTTP, and all your logic is
> based on the HTTP specific objects ? My guess is that all your
> services will stop working... and this will not be good.
>
> On Tue, Aug 26, 2008 at 9:29 PM, Raymond Feng <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> Thank you for contributing the fixes back to Tuscany. A bit more help from
>> you will be greatly appreciated:
>>
>> 1) Open a JIRA at https://issues.apache.org/jira/browse/TUSCANY
>> 2) Create a svn patch (you can run "svn diff > xyz.patch" command under
>> sca/
>> folder)
>> 3) Attach the patch the JIRA and grant Apache license to it
>>
>> Thanks,
>> Raymond
>>
>> From: ZhiYong Mao
>> Sent: Tuesday, August 26, 2008 9:10 PM
>> To: user@tuscany.apache.org
>> Subject: I have tried to inject HTTP request or session into service Java
>> bean
>>
>>
>> ***********************
>> Warning: Your file, tuscany-1.2.1-fix.zip, contains more than 32 files
>> after
>> decompression and cannot be scanned.
>> Warning: Your file, tuscany-1.2.1-fix.zip, contains more than 32 files
>> after
>> decompression and cannot be scanned.
>> ***********************
>>
>>
>>
>> Hi
>>
>> I have tried to inject HTTP request or session into service Java bean and
>> it
>> works fine now, here are the latest binary package and source code changed
>> by us:
>> (See attached file: tuscany-1.2.1-fix.zip)(See attached file:
>> tuscany-1.2.1-fix-src.zip)
>> The details changed are as follows:
>>
>> 1.===============org.apache.tuscany.sca.databinding.json.JSON2JavaBean.java====================
>> (1)Line 55:
>> SerializerState state = new SerializerState();
>> return serializer.unmarshall(state,
>> context.getTargetDataType().getPhysical(), source);
>> =======>:
>> /**************modify by Jacky Mao******************************
>> * Inject HttpServletRequest or HttpSession into parameters in methods
>> * So it is not necessary to transform these 2 parameter types
>> */
>> if(source instanceof javax.servlet.http.HttpServletRequest ||
>> source instanceof javax.servlet.http.HttpSession){
>> return source;
>> }else{
>> SerializerState state = new SerializerState();
>> return serializer.unmarshall(state,
>> context.getTargetDataType().getPhysical(), source);
>> }
>>
>> 2.========org.apache.tuscany.sca.binding.jsonrpc.JSONRPCServiceServlet.java==========
>> (1)Line 181:
>> JSONRPCBridge jsonrpcBridge = new JSONRPCBridge();
>> jsonrpcBridge.registerObject("Service", serviceInstance,
>> serviceInterface);
>> session.setAttribute("JSONRPCBridge", jsonrpcBridge);
>> ========>(I think it is better like this):
>> JSONRPCBridge jsonrpcBridge = (JSONRPCBridge)
>> session.getAttribute("JSONRPCBridge");
>> if(jsonrpcBridge==null){
>> jsonrpcBridge=new JSONRPCBridge();
>> session.setAttribute("JSONRPCBridge", jsonrpcBridge);
>> }
>> jsonrpcBridge.registerObject("Service", serviceInstance,
>> serviceInterface);
>> (2)Line 217:
>> // Extract the arguments
>> JSONArray array = jsonReq.getJSONArray("params");
>> args = new Object[array.length()];
>> for (int i = 0; i < args.length; i++) {
>> args[i] = array.get(i);
>> }
>> =======>(add HttpServletRequest or HttpSession into args array at
>> appropriate position)
>> /*****************modify by Jacky Mao********************************
>> * Inject HttpServletRequest or HttpSession into parameters in methods
>> *******************************************************************/
>> //1.find current method
>> Method methods[]=serviceInterface.getMethods();
>> Method currentMethod=null;
>> for(int i=0;i<methods.length;i++){
>> if(method.equals("Service."+methods[i].getName())){
>> currentMethod=methods[i];
>> break;
>> }
>> }
>> //2.find index of the parameter which is HttpServletRequest or HttpSession
>> int paramIndex=-1;
>> Object paramValue=null;
>> if(currentMethod!=null){
>> Class<?>[] clazz=currentMethod.getParameterTypes();
>> LocalArgResolver lar=new LocalArgResolver();
>> for(int i=0;i<clazz.length;i++){
>> Object obj=lar.getArgValue(clazz[i], request);
>> if(obj!=null){
>> paramIndex=i;
>> paramValue=obj;
>> break;//just support one(HttpServletRequest or HttpSession)
>> }
>> }
>> }
>> //3.Extract the arguments and add HttpServletRequest or HttpSession
>> // into arguments if it is necessary.
>> JSONArray array = jsonReq.getJSONArray("params");
>> if(paramIndex>=0){
>> args = new Object[array.length()+1];
>> }else{
>> args = new Object[array.length()];
>> }
>> boolean added=false;
>> for (int i = 0; i < args.length; i++) {
>> if(i==paramIndex){
>> args[i]=paramValue;
>> added=true;
>> }else{
>> if(added){
>> args[i] = array.get(i-1);
>> }else{
>> args[i] = array.get(i);
>> }
>> }
>> }
>>
>> /*****************************************************************************/
>> (3)Line 244
>> jsonResponse.put("error", e.getCause());
>> =======>(It is for fixing a small bug:"error parsing result")
>> /*****modify by Jacky Mao************************
>> * add json error object into error so that
>> * the client javascript can parse them correctly.
>> */
>> Throwable t=e.getCause();
>> JSONObject jsonError = new JSONObject();
>> jsonError.put("code", response.SC_INTERNAL_SERVER_ERROR);
>> jsonError.put("msg", t.getMessage());
>> jsonError.put("trace", t.getClass().getName());
>> jsonResponse.put("error", jsonError);
>> /************************************************/
>>
>> 3.========org.apache.tuscany.sca.binding.jsonrpc.LocalArgResolver.java==========
>> It is a new file created by me.
>>
>> I have added some comments into source code, you can aslo see the
>> difference
>> by comparing source code.
>>
>> Best regards!
>>
>> Jacky Mao , Software Engineer
>> IBM GPSG Wuhan Perform Center
>> Tel : 0086-027-87406266-1212
>> E-Mail: [EMAIL PROTECTED]
>> Willis C White/Poughkeepsie/IBM
>>
>>
>>
>>
>
>
>
> --
> Luciano Resende
> Apache Tuscany Committer
> http://people.apache.org/~lresende
> http://lresende.blogspot.com/
>
>



-- 
Luciano Resende
Apache Tuscany Committer
http://people.apache.org/~lresende
http://lresende.blogspot.com/

Reply via email to