You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tuscany.apache.org by ZhiYong Mao <zm...@us.ibm.com> on 2008/08/27 06:10:59 UTC
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: zmao@us.ibm.com
Willis C
White/Poughkeepsi
e/IBM To
ZhiYong Mao/Somers/Contr/IBM
2008-08-26 10:23 cc
Subject
Re: requests(Document link: ZhiYong
Mao)
Jacky
this way of doing things is fine but if you are going to change the Tuscany
source code you must documents it.
1. overview of the changes you made
2. list of source files you changed and diff's for each
3. detailed comments in the code.
If the source code is going to change, I would like it checked into Tuscany
project so we can keep up the new release without having to make a lot of
changes.
Would you prefer to send the changes to Luciano Resende and he put them
into Tuscany or do you want to deal with the Tuscany community yourself?
Willis C White III
IQ Technology
Projects
IBM CIO Technology &
Innovation
Poughkeepsie, NY
12601
Home office 845
331-5134
Cell 845 853-3827
ZhiYong
Mao/Somers/Contr/
IBM To
Willis C
08/25/2008 05:41 White/Poughkeepsie/IBM@IBMUS
AM cc
Subject
Re: requests(Document link: Willis
C White)
Hi Willis
We have fixed all the changes including opening task hierarchy if there
are five or less tasks in it, pls check it on test server.
I also resolved getting HTTP request problem: inject HTTP request by
modifying the Tuscany source code, you could take a look at
http://9.186.46.171/InnovationMarketplace/test/testTuscany.jsp, you can run
the steps as follows for testing.
(1)Click "Test Get My Tasks" button then it will popup "You must sign in
first!".
(2)Login through logon.jsp or clicking "Test Login" button.
(3)Click "Test Get My Tasks" button then it will popup "The count for
tasks created by me:<number>".
[Note]: If you click "Test Login" button then logged user is me
(zmao@us.ibm.com).
If you think it is ok, pls copy all the jars in the war sent from you
into <WAS_HOME>/lib/ext on test server, and then copy all the files in the
following package to <WAS_HOME>/lib/ext for covering some files:
(See attached file: tuscany-1.2.1-fix.zip),
After that restart Websphere application server, so I can deploy the
latest code on test server rapidly because of local bad network, thanks.
Best regards!
Jacky Mao , Software Engineer
IBM GPSG Wuhan Perform Center
Tel : 0086-027-87406266-1212
E-Mail: zmao@us.ibm.com
Willis C
White/Poughkeepsi
e/IBM To
ZhiYong Mao/Somers/Contr/IBM
2008-08-25 08:20 cc
Subject
requests
Changes to make
Make the tables on the personal page 5 rows instead of 6 rows tall
on the interest page, the pop up that shows the peoples names should
have a link “I am interested in this topic” if the person is not
already in the list. If the person is in the list the link should say
“I am not interested in the topic anymore”. These links should create
or delete a subscription.
What information do you need to implement the LogOn() method and the rest
of the methods with Tuscany? What do you need the sample to do,
specifically? In other words, what part the of process don't you understand
and need an example of?
Willis C White III
IQ Technology
Projects
IBM CIO Technology &
Innovation
Poughkeepsie, NY
12601
Home office 845
331-5134
Cell 845 853-3827
Re: I have tried to inject HTTP request or session into service Java bean
Posted by Luciano Resende <lu...@gmail.com>.
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 <zm...@us.ibm.com> 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: zmao@us.ibm.com
> "Luciano Resende" <lu...@gmail.com>
>
>
> "Luciano Resende" <lu...@gmail.com>
>
> 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 <en...@gmail.com> 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: zmao@us.ibm.com
>> 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/
Re: I have tried to inject HTTP request or session into service Java bean
Posted by ZhiYong Mao <zm...@us.ibm.com>.
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: zmao@us.ibm.com
"Luciano Resende"
<luckbr1975@gmail
.com> To
user@tuscany.apache.org
2008-08-27 14:35 cc
Subject
Please respond to Re: I have tried to inject HTTP
user@tuscany.apac request or session into service
he.org 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 <en...@gmail.com> 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: zmao@us.ibm.com
> Willis C White/Poughkeepsie/IBM
>
>
>
>
--
Luciano Resende
Apache Tuscany Committer
http://people.apache.org/~lresende
http://lresende.blogspot.com/
Re: I have tried to inject HTTP request or session into service Java bean
Posted by Willis C White <wh...@us.ibm.com>.
Luciano
Then chances of our system using anything else besides HTTP are very small
(likely worth the risk locking into this kind of transport protocol).
How much work would it be to get policies working for web 2.0 bindings?
We will look into the userContext way of doing it.
Willis C White III
IQ Technology Projects
IBM CIO Technology & Innovation
Poughkeepsie, NY 12601
Home office 845 331-5134
Cell 845 853-3827
Re: I have tried to inject HTTP request or session into service Java bean
Posted by Luciano Resende <lu...@gmail.com>.
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 <en...@gmail.com> 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: zmao@us.ibm.com
> Willis C White/Poughkeepsie/IBM
>
>
>
>
--
Luciano Resende
Apache Tuscany Committer
http://people.apache.org/~lresende
http://lresende.blogspot.com/
Re: I have tried to inject HTTP request or session into service Java bean
Posted by Raymond Feng <en...@gmail.com>.
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: zmao@us.ibm.com
Willis C White/Poughkeepsie/IBM