You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by fa...@br.ibm.com on 2010/07/19 21:21:21 UTC

jsonp ported to version 1.x and error appears when passing a jsonp object on the URL

Hi,

I have ported the jsonp binding from version 2.0 to version 1.4 and have 
declared the following service:

   <component name="ExpLocComponentP">
        <implementation.java 
class="com.service.explocp.ExpLocServiceImpl"/>
        <service name="ExpLocService">
            <tuscany:binding.jsonp uri="/API/locatorp"/>
        </service>
    </component>


The class has the following method I want to reach:

package com.service.explocp;
import java.util.ArrayList;

public class ExpLocServiceImpl implements ExpLocService {
...
   @Override
   public void submitQuestion (QuestionDTO qDTO) throws Exception{
     try {
         qDTO.setSite("EL");
         ExpLocCommon.submitQuestion(qDTO) ; 
     } catch (Throwable _ex) {
         LOGGER.error(_ex);
     }    
   }

Remembering that the ExpLocService has the annotation:

@Remotable
public interface ExpLocService {
 

Now, debugging the error presented when executing the URL:

http://localhost:8080/eed/API/locatorp/submitQuestion?1=[{"userEmailId":"
gg@us.exa.com","expertEmailId":"gg@us.exa.com
","subject":"hello","question":"test   test  test  test  
","isST":"true","searchKeyword":"","expertiseId":"","site":"test"}] 

It will go into the code for class JSONPServlet: 
...
 @Override
    public void service(ServletRequest servletRequest, ServletResponse 
servletResponse) throws ServletException, IOException {

        String jsonRequest = getJSONRequest(servletRequest);
        Object[] args = jsonToObjects(jsonRequest);
        Object response = invokeService(args);  <--- the chain of requests 
that will return into error starts here      
        String jsonResponse = getJSONResponse(servletRequest, response);
        servletResponse.getOutputStream().println(jsonResponse);
   ...

later in the class : 

package 
org.apache.tuscany.sca.implementation.java.invocation.JavaImplementationInvoker


Message invoker(Message msg){
            ....
            Object ret;
            if (payload != null && !payload.getClass().isArray()) {
                ret = imethod.invoke(instance, payload);
            } else {
                ret = imethod.invoke(instance, (Object[])payload); 
<-------------------------- 
            }
           
     The imethod has a reference for the method 
                     submitQuestion which is the method invoked from the 
URL 
                                (at this point the payload variable has 
the following value in the array index 0 : [{userEmailId=gg@us.exa.com, 
expertEmailId=gg@us.exa.com, subject=hello, question=test   test  test  
test  , isST=true, searchKeyword=, expertiseId=, site=test}] ) 
 

     and payload has the values passed on the URL but in as Array format 
instead of the Object questionDTO required by the method. 
     at this moment the payload comes with the following value:
                    [{userEmailId=gg@us.exa.com, expertEmailId=
gg@us.exa.com, subject=hello, question=test   test  test  test  , 
isST=true, searchKeyword=, expertiseId=, site=test}]


     So I Think that for some reason in the middle of everything the json 
object was not converted into the object type required by the method, or 
it should go into the imethod.invoke(instance, payload).

     At the end I got the following error:

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

description The server encountered an internal error () that prevented it 
from fulfilling this request.
exception 
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
 
org.apache.tuscany.sca.binding.jsonp.runtime.JSONPServlet.invokeService(JSONPServlet.java:159)
 
org.apache.tuscany.sca.binding.jsonp.runtime.JSONPServlet.service(JSONPServlet.java:61)
 
org.apache.tuscany.sca.host.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:107)
 
org.apache.tuscany.sca.host.webapp.TuscanyServletFilter.doFilter(TuscanyServletFilter.java:93)

     

Thanks & Regards,
____________________________________________ 


Fabiano Amorim Oliveira
IT Specialist - J2EE Developer
IBM Global Business Services
Sun Certified Java Programmer 6
WebSphere Application Server 7.0 Admin. Certified 

  E-mail: fabianoa@br.ibm.com
  Phone: +55 41 2141-4864
  Tie-line: 732-4864
  Mobile: +55 41 8861-9212
Please consider the environment before printing this email P

Re: jsonp ported to version 1.x and error appears when passing a jsonp object on the URL

Posted by Simon Laws <si...@googlemail.com>.
Hi

At revision: 980366 I checked in a few changes to delegate the data
transformation to the databinding layer which has a better view of the
details of the parameter and return types. Can you apply this to your
code base and give it a spin. I've closed TUSCANY-3635 for not but if
you still see problems please re-open it.

I've left the old code in but commented out to give you a better idea
of what I did. I'll remove this once we have a working solution.

Regards

Simon

-- 
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com

Re: jsonp ported to version 1.x and error appears when passing a jsonp object on the URL

Posted by Simon Laws <si...@googlemail.com>.
On Thu, Jul 22, 2010 at 5:08 PM, Luciano Resende <lu...@gmail.com> wrote:
>
>
> On Mon, Jul 19, 2010 at 12:21 PM, <fa...@br.ibm.com> wrote:
>>
>>
>>
>> Hi,
>>
>> I have ported the jsonp binding from version 2.0 to version 1.4 and have
>> declared the following service:
>>
>>    <component name="ExpLocComponentP">
>>         <implementation.java
>> class="com.service.explocp.ExpLocServiceImpl"/>
>>         <service name="ExpLocService">
>>             <tuscany:binding.jsonp uri="/API/locatorp"/>
>>         </service>
>>     </component>
>>
>>
>> The class has the following method I want to reach:
>>
>> package com.service.explocp;
>> import java.util.ArrayList;
>>
>> public class ExpLocServiceImpl implements ExpLocService {
>> ...
>>    @Override
>>    public void submitQuestion (QuestionDTO qDTO) throws Exception{
>>      try {
>>          qDTO.setSite("EL");
>>          ExpLocCommon.submitQuestion(qDTO) ;
>>      } catch (Throwable _ex) {
>>          LOGGER.error(_ex);
>>      }
>>    }
>>
>> Remembering that the ExpLocService has the annotation:
>>
>> @Remotable
>> public interface ExpLocService {
>>
>>
>> Now, debugging the error presented when executing the URL:
>>
>>
>> http://localhost:8080/eed/API/locatorp/submitQuestion?1=[{"userEmailId":"gg@us.exa.com","expertEmailId":"gg@us.exa.com","subject":"hello","question":"test
>> test  test  test
>> ","isST":"true","searchKeyword":"","expertiseId":"","site":"test"}]
>>
>> It will go into the code for class JSONPServlet:
>> ...
>>  @Override
>>     public void service(ServletRequest servletRequest, ServletResponse
>> servletResponse) throws ServletException, IOException {
>>
>>         String jsonRequest = getJSONRequest(servletRequest);
>>         Object[] args = jsonToObjects(jsonRequest);
>>         Object response = invokeService(args);  <--- the chain of requests
>> that will return into error starts here
>>         String jsonResponse = getJSONResponse(servletRequest, response);
>>         servletResponse.getOutputStream().println(jsonResponse);
>>    ...
>>
>> later in the class :
>>
>> package
>> org.apache.tuscany.sca.implementation.java.invocation.JavaImplementationInvoker
>>
>> Message invoker(Message msg){
>>             ....
>>             Object ret;
>>             if (payload != null && !payload.getClass().isArray()) {
>>                 ret = imethod.invoke(instance, payload);
>>             } else {
>>                 ret = imethod.invoke(instance, (Object[])payload);
>> <--------------------------
>>             }
>>
>>      The imethod has a reference for the method
>>                      submitQuestion which is the method invoked from the
>> URL
>>                                 (at this point the payload variable has
>> the following value in the array index 0 : [{userEmailId=gg@us.exa.com,
>> expertEmailId=gg@us.exa.com, subject=hello, question=test   test  test
>> test  , isST=true, searchKeyword=, expertiseId=, site=test}] )
>>
>>
>>      and payload has the values passed on the URL but in as Array format
>> instead of the Object questionDTO required by the method.
>>      at this moment the payload comes with the following value:
>>                     [{userEmailId=gg@us.exa.com,
>> expertEmailId=gg@us.exa.com, subject=hello, question=test   test  test
>> test  , isST=true, searchKeyword=, expertiseId=, site=test}]
>>
>>
>>      So I Think that for some reason in the middle of everything the json
>> object was not converted into the object type required by the method, or it
>> should go into the imethod.invoke(instance, payload).
>>
>>      At the end I got the following error:
>>
>>
>> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>
>> description The server encountered an internal error () that prevented it
>> from fulfilling this request.
>>
>> exception
>>
>> java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
>>
>> org.apache.tuscany.sca.binding.jsonp.runtime.JSONPServlet.invokeService(JSONPServlet.java:159)
>>
>> org.apache.tuscany.sca.binding.jsonp.runtime.JSONPServlet.service(JSONPServlet.java:61)
>>
>> org.apache.tuscany.sca.host.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:107)
>>
>> org.apache.tuscany.sca.host.webapp.TuscanyServletFilter.doFilter(TuscanyServletFilter.java:93)
>>
>>
>
> Fabiano,
>
>    Nice to see that you have ported the JSONP binding to 1.x, any chance you
> want to share this with the community so other users of the 1.x code stream
> could also take advantage of the binding ?
>
>    As for your issue, It's hard for us to try to reproduce a problem on a
> ported binding that is not available for the community, as it make things
> harder to guess what the problem is without debugging it.  If you could
> provide a sample unit test where one could reproduce the problem, that would
> be very helpful, this could be done in the 2.x as there is already a JSONP
> binding there, or it could be done after you provide a patch with a version
> of the 1.x ported binding.
>
>
> --
> Luciano Resende
> http://people.apache.org/~lresende
> http://twitter.com/lresende1975
> http://lresende.blogspot.com/
>

To move this along a little I've done a couple of initial things....

1/ I raised JIRA TUSCANY-3635
(https://issues.apache.org/jira/browse/TUSCANY-3635) to record any
progress we make against this issue. It's generally a good idea to
raise a JIRA so that we can tie any code changes and investigations to
the problem being reported.

2/ Added a new test to the 2.x JSONP binding to try passing complex
types. I note from the OP that the target service has an interface
that uses a complex type. It's not clear how complex that type is as
it's not provided so for now I just created a simple bean with a few
fields. Needless to say it doesn't work so the next step is to look at
what's happening.

If your type is simple a quick work around may be to use separate
parameters for the individual fields but I'm assuming that there are
no other issues in the way that the binding has been ported to 1.x

I think the approach we should take is to investigate further on 2.x
and make sure that we are satisfied with our understanding of what's
going one. We can either then fix any issues we see or document the
level of support the binding provided.

If you then need help to apply any fixes to the 1.x port we really
need to get the port into the Tuscany code base, along with suitable
tests, so that we can all see it.

Regards

Simon

-- 
Apache Tuscany committer: tuscany.apache.org
Co-author of a book about Tuscany and SCA: tuscanyinaction.com

Re: jsonp ported to version 1.x and error appears when passing a jsonp object on the URL

Posted by Luciano Resende <lu...@gmail.com>.
On Mon, Jul 19, 2010 at 12:21 PM, <fa...@br.ibm.com> wrote:

>
>
>
> Hi,
>
> I have ported the jsonp binding from version 2.0 to version 1.4 and have
> declared the following service:
> *
>    <component name="ExpLocComponentP">
>         <implementation.java
> class="com.service.explocp.ExpLocServiceImpl"/>
>         <service name="ExpLocService">
>             <tuscany:binding.jsonp uri="/API/locatorp"/>
>         </service>
>     </component>*
>
>
> The class has the following method I want to reach:
>
> package com.service.explocp;
> import java.util.ArrayList;
>
> public class ExpLocServiceImpl implements ExpLocService {
> ...*
>    @Override
>    public void submitQuestion (QuestionDTO qDTO) throws Exception{
>      try {
>          qDTO.setSite("EL");
>          ExpLocCommon.submitQuestion(qDTO) ;
>      } catch (Throwable _ex) {
>          LOGGER.error(_ex);
>      }
>    }*
>
> Remembering that the ExpLocService has the annotation:
> *
> @Remotable
> public interface ExpLocService {
>  *
>
> Now, debugging the error presented when executing the URL:
> *
> **http://localhost:8080/eed/API/locatorp/submitQuestion?1=[{*<http://localhost:8080/eed-sca-services/API/locatorp/submitQuestion?1=[%7B>
> *"userEmailId":"**gg@us.exa.com* <gg...@us.ibm.com>
> *gg@us.exa.com* <gg...@us.ibm.com>*","subject":"hello","question":"test
> test  test  test
> ","isST":"true","searchKeyword":"","expertiseId":"","site":"test"}]*
>
> It will go into the code for class *JSONPServlet*:
> ...
> * @Override*
>     public void service(ServletRequest servletRequest, ServletResponse
> servletResponse) throws ServletException, IOException {
>
>         String jsonRequest = getJSONRequest(servletRequest);
>         Object[] args = jsonToObjects(jsonRequest);
>         *Object response = invokeService(args);  <--- the chain of
> requests that will return into error starts here      *
>         String jsonResponse = getJSONResponse(servletRequest, response);
>         servletResponse.getOutputStream().println(jsonResponse);
>    ...
>
> later in the class :
> *
> package
> org.apache.tuscany.sca.implementation.java.invocation.JavaImplementationInvoker
> *
>
> Message invoker(Message msg){
>             ....
>             Object ret;
>             if (payload != null && !payload.getClass().isArray()) {
>                 ret = imethod.invoke(instance, payload);
>             } else {
>                 ret = imethod.invoke(instance, (Object[])payload);
> <--------------------------
>             }
>
>      The *imethod *has a reference for the method
>                      *submitQuestion *which *is* the method invoked from
> the URL
>                                 (at this point the payload variable has the
> following value in the array index 0 : [{userEmailId=*gg@us.exa.com*<gg...@us.ibm.com>,
> expertEmailId=*gg@us.exa.com* <gg...@us.ibm.com>, subject=hello,
> question=test   test  test  test  , isST=true, searchKeyword=, expertiseId=,
> site=test}] )
>
>
>      and *payload* has the values passed on the URL but in as Array format
> instead of the Object *questionDTO* required by the method.
>      at this moment the payload comes with the following value:
>                     [{userEmailId=*gg@us.exa.com* <gg...@us.ibm.com>,
> expertEmailId=*gg@us.exa.com* <gg...@us.ibm.com>, subject=hello,
> question=test   test  test  test  , isST=true, searchKeyword=, expertiseId=,
> site=test}]
>
>
>      So I Think that for some reason in the middle of everything the json
> object was not converted into the object type required by the method, or it
> should go into the imethod.invoke(instance, payload).
>
>      At the end I got the following error:
>
>
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> *description* *The server encountered an internal error () that prevented
> it from fulfilling this request.*
>
> *exception*
>
> java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
>
> org.apache.tuscany.sca.binding.jsonp.runtime.JSONPServlet.invokeService(JSONPServlet.java:159)
>
> org.apache.tuscany.sca.binding.jsonp.runtime.JSONPServlet.service(JSONPServlet.java:61)
>
> org.apache.tuscany.sca.host.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:107)
>
> org.apache.tuscany.sca.host.webapp.TuscanyServletFilter.doFilter(TuscanyServletFilter.java:93)
>
>
>

Fabiano,

   Nice to see that you have ported the JSONP binding to 1.x, any chance you
want to share this with the community so other users of the 1.x code stream
could also take advantage of the binding ?

   As for your issue, It's hard for us to try to reproduce a problem on a
ported binding that is not available for the community, as it make things
harder to guess what the problem is without debugging it.  If you could
provide a sample unit test where one could reproduce the problem, that would
be very helpful, this could be done in the 2.x as there is already a JSONP
binding there, or it could be done after you provide a patch with a version
of the 1.x ported binding.


-- 
Luciano Resende
http://people.apache.org/~lresende
http://twitter.com/lresende1975
http://lresende.blogspot.com/