Fornax-Platform
Forum

Remote service calls (help with a special-cases.xpt ?)

View: New views
4 Messages — Rating Filter:   Alert me  

Remote service calls (help with a special-cases.xpt ?)

by Ryan Gardner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The way Flex calls remote services is that it calls them "directly"  
and passes the necessary parameters in over the remote call. The  
default Sculptor services have the ServiceContext as the first  
parameter - but for me to specify that inside the client and have the  
client tell the server who it is and what it's session ID is seems  
wrong.

When the methods get invoked on the server, I have access to the  
request and I can get the necessary information to inject a  
ServiceContext object into an instance of my remote service that gets  
used in processing that request.

So if I can create a remote service that doesn't require the  
ServiceContext parameter, I can expose that service to my remote  
clients. In my implentation of that, I can delegate all of my service  
calls to other services which DO take a ServiceContext parameter to  
handle the auditing / logging etc.

There is the property to turn off the serviceContext all together, but  
in my case I want it on all but a few of my services - so I think this  
is a case where I could write a specialCases.xpt to use AOP to wrap  
the generation and have it turn off the ServiceContext generation for  
those methods only.

I'm new to the XPT templates, so I'm not quite sure where to start. It  
looks like things that are defined inside of <<DEFINE>> blocks you can  
wrap around fairly easily.

I was hoping that I would get lucky and there would be some magic code  
in there that already handles the parameter generation based on that  
property that indicates whether or not to use ServiceContexts - and  
that I could just work on the syntax to map my specific class (say...  
any service with the name "Remote" in it has the ServiceContexts  
turned off for its generation) - but I can't quite figure out how to  
do that.

Any ideas on where I should start looking for that?

Ryan



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Re: Remote service calls (help with a special-cases.xpt ?)

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ryan,

The ServiceContext parameter is added by the Transformation.ext. Therefore you don't see anything in the templates.

Since you are working on the flex support I don't think you need to involve SpecialCases.xpt. You can do this directly in the templates, Service.xpt.

This is how I would do it (not complete). This will create an interface without the service context parameter in the methods.

In Service.xpt add the following

«DEFINE service FOR Service»
    «EXPAND serviceInterface»
    «EXPAND clientServiceInterface»
...

«DEFINE clientServiceInterface FOR Service»
    «FILE javaFileName(getServiceapiPackage() + "." + name + "Client")»
package «getServiceapiPackage()»;

«IF formatJavaDoc() == "" -»
/**
 * Generated client interface for the Service «name».
 */
«ELSE -»
«formatJavaDoc()»
«ENDIF -»
public interface «name»Client {
     
    «EXPAND clientInterfaceMethod FOREACH operations.select(op | op.isPublicVisibility())»
                 
}
    «ENDFILE»    
«ENDDEFINE»

«DEFINE clientInterfaceMethod FOR ServiceOperation»
    «formatJavaDoc()»
    public «getTypeName()» «name»(«EXPAND paramTypeAndName FOREACH parametersWithoutServiceContext() SEPARATOR ","») «
    EXPAND Exception::throws»;
«ENDDEFINE»

In helper.ext add the following:

List[Parameter] parametersWithoutServiceContext(ServiceOperation operation) :
        isServiceContextToBeGenerated() ?
                operation.parameters.reject(p | p.type == getProperty("framework.serviceContextClass")) :
                operation.parameters;



In the web client we use a servlet filter and then when invoking the services we just do ServiceContextStore.get() to fetch the ServiceContext instance. I agree that the more this can be hidden by AOP the better. We might change to your design in the web client also.

/Patrik


Re: Remote service calls (help with a special-cases.xpt ?)

by deepshar027 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Patrik,

Is there a good/better way of acheiving the "No ServiceContext" parameter for a few Service methods?
I am using Spring/Hibernate-JPA to connect from Flex client.

Here is your earlier quote...

"In the web client we use a servlet filter and then when invoking the services we just do ServiceContextStore.get() to fetch the ServiceContext instance. I agree that the more this can be hidden by AOP the better. We might change to your design in the web client also."

I am not sure if I can so something in my Spring Configuration file to insert the servicecontext???

Any help will be great!!

Thanks,
Deepak.


Patrik Nordwall wrote:
Hi Ryan,

The ServiceContext parameter is added by the Transformation.ext. Therefore you don't see anything in the templates.

Since you are working on the flex support I don't think you need to involve SpecialCases.xpt. You can do this directly in the templates, Service.xpt.

This is how I would do it (not complete). This will create an interface without the service context parameter in the methods.

In Service.xpt add the following

«DEFINE service FOR Service»
    «EXPAND serviceInterface»
    «EXPAND clientServiceInterface»
...

«DEFINE clientServiceInterface FOR Service»
    «FILE javaFileName(getServiceapiPackage() + "." + name + "Client")»
package «getServiceapiPackage()»;

«IF formatJavaDoc() == "" -»
/**
 * Generated client interface for the Service «name».
 */
«ELSE -»
«formatJavaDoc()»
«ENDIF -»
public interface «name»Client {
     
    «EXPAND clientInterfaceMethod FOREACH operations.select(op | op.isPublicVisibility())»
                 
}
    «ENDFILE»    
«ENDDEFINE»

«DEFINE clientInterfaceMethod FOR ServiceOperation»
    «formatJavaDoc()»
    public «getTypeName()» «name»(«EXPAND paramTypeAndName FOREACH parametersWithoutServiceContext() SEPARATOR ","») «
    EXPAND Exception::throws»;
«ENDDEFINE»

In helper.ext add the following:

List[Parameter] parametersWithoutServiceContext(ServiceOperation operation) :
        isServiceContextToBeGenerated() ?
                operation.parameters.reject(p | p.type == getProperty("framework.serviceContextClass")) :
                operation.parameters;



In the web client we use a servlet filter and then when invoking the services we just do ServiceContextStore.get() to fetch the ServiceContext instance. I agree that the more this can be hidden by AOP the better. We might change to your design in the web client also.

/Patrik

Re: Remote service calls (help with a special-cases.xpt ?)

by Patrik Nordwall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sure, you can turn it off completely with generator property generate.serviceContext=false

or you can control it on method level by overwriting the transformation, which adds the parameter.

It is in Transformation.ext
modifyServiceContextParameter(Service service)
modifyServiceContextParameter(ServiceOperation operation)

See http://fornax.itemis.de/confluence/display/fornax/7.+Developer%27s+Guide+(CSC)#7.Developer%27sGuide(CSC)-CustomizetheTransformations

/Patrik


deepshar027 wrote:
Is there a good/better way of acheiving the "No ServiceContext" parameter for a few Service methods?
I am using Spring/Hibernate-JPA to connect from Flex client.