You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by smixuser <cl...@compuware.com> on 2007/07/31 16:20:23 UTC

Looking for Example of 2 JSR181 Service Units Invoking Each Other

Does anyone have a working example of having 2 JSR 181 Service Units which
can invoke each other within the JBI bus or instructions on how this can be
done?  Thanks.
-- 
View this message in context: http://www.nabble.com/Looking-for-Example-of-2-JSR181-Service-Units-Invoking-Each-Other-tf4193293s12049.html#a11925020
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Looking for Example of 2 JSR181 Service Units Invoking Each Other

Posted by vinnu <vi...@gmail.com>.
Try this code and tell me...import appropriate jar files.

import javax.jbi.component.ComponentContext;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.InOut;
import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.xml.namespace.QName;

import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.w3c.dom.Document;

public class Service {
	
	private String request;
	private String req_Country;
	private String req_App;
	private String part_Schema_typ;
	private ComponentContext context;
	private boolean isSchemaValid = false;
	private boolean isManField = false;
	private InOut exchange;
	private NormalizedMessage in_msg;
	

	SourceTransformer sourceTransformer = new SourceTransformer();
	
	
	
	
	public PA_Service(String request, ComponentContext context){
		this.request = request;
		this.context = context;
	}
	
	
	public Document process(){
		String serviceURI = "10.20.30.123:8192";
		String serviceName = "anotherservice";//anotherservice can be jsr181 or it
can be any other service.
		Document outDoc = null;
		
		//Schema validation
		doSchemaValidation();
		
		//Mandatory field validation
		doMandatoryFieldValidation();
		
		if (isSchemaValid && isManField){
//			form_Req_XML(inputParams);
			
			request = "<ROOT>"+removeXMLProlog(request)+"</ROOT>";
			StringSource source = new StringSource(request);
			try{
				
				DeliveryChannel channel = context.getDeliveryChannel();
				ServiceEndpoint se = context.getEndpoint(new
QName(serviceURI,serviceName),null);
				exchange = channel.createExchangeFactory(se).createInOutExchange();
				exchange.setService(new QName(serviceURI,serviceName));
				in_msg = exchange.createMessage();
				in_msg.setContent(source);
				exchange.setInMessage(in_msg);
				channel.sendSync(exchange);
				NormalizedMessage message = exchange.getMessage("out");
				outDoc = sourceTransformer.toDOMDocument(message);
				String outputt = sourceTransformer.toString(outDoc);
				
				}catch(Exception e){
				//Exception handling should be done here
				System.out.println("The exception in second stage"+e);
			}
		}
		return outDoc;
	}
	
	public void doSchemaValidation(){
		this.isSchemaValid = true;
	}
	
	public void doMandatoryFieldValidation(){
		this.isManField = true;
	}
	
	public String removeXMLProlog(String xml) {
        int endIndex = 0;

        if (xml.indexOf("<?") != -1) {
            endIndex = xml.indexOf("?>");

            if (endIndex != -1) {
                xml = xml.substring(endIndex + 2);
            }

            if (xml.startsWith("\r\n")) {
                xml = xml.substring(2);
            }
        }

        return xml;
    }
}




smixuser wrote:
> 
> Hi, 
> 
> I've looked at these pages but I still don't have a clear understanding
> how to implement them.  I'm looking for a complete example or step by step
> instructions on how to invoke a service by accessing the bus.  For
> instance, the page
> http://incubator.apache.org/servicemix/servicemix-jsr181.html has a secion
> Accessing the JBI Bus and says you can If you want to send a request to
> another service from your POJO, you can add the following method on your
> POJO:
> 
> private javax.jbi.component.ComponentContext context;
> 
> public void setContext(javax.jbi.component.ComponentContext context) {
>   this.context = context;
> }
> 
> Well, I tried putting this method in the wsdl-first example and received a
> compile error package javax.jbi.component does not exist when running mvn
> install jbi:projectDeploy.  And what do I need to do after I put this in
> my POJO?  How do I send the request to the other service?  
> 
> That page also has a section on proxies but I didn't get a full
> understanding of what needs to be done from that section.  For example,
> how can I create one for the wsdl-first example.  
> 
> Then I found the page on the client-api
> http://incubator.apache.org/servicemix/client-api.html but is there a full
> working example somewhere on using the client api to invoke a jsr-181
> service unit.  For example, the wsdl-first has a client.html.  But how can
> I use the client-api to invoke it?  I was unclear on the sample code that
> was on that page because I don't know what example it pertains to and if
> there is anything else that needs to be done.  
> 
> Any help is greatly appreciated.  Thanks.
> 
> 
> 
> Adrian Co wrote:
>> 
>> I wonder if you mean the jsr181 proxy.
>> http://incubator.apache.org/servicemix/servicemix-jsr181.html
>> http://incubator.apache.org/servicemix/orchestration-with-jsr181.html
>> 
>> smixuser wrote:
>>> Does anyone have a working example of having 2 JSR 181 Service Units
>>> which
>>> can invoke each other within the JBI bus or instructions on how this can
>>> be
>>> done?  Thanks.
>>>   
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Looking-for-Example-of-2-JSR181-Service-Units-Invoking-Each-Other-tp11925020p17098909.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Looking for Example of 2 JSR181 Service Units Invoking Each Other

Posted by smixuser <cl...@compuware.com>.
Hi, 

I've looked at these pages but I still don't have a clear understanding how
to implement them.  I'm looking for a complete example or step by step
instructions on how to invoke a service by accessing the bus.  For instance,
the page http://incubator.apache.org/servicemix/servicemix-jsr181.html has a
secion Accessing the JBI Bus and says you can If you want to send a request
to another service from your POJO, you can add the following method on your
POJO:

private javax.jbi.component.ComponentContext context;

public void setContext(javax.jbi.component.ComponentContext context) {
  this.context = context;
}

Well, I tried putting this method in the wsdl-first example and received a
compile error package javax.jbi.component does not exist when running mvn
install jbi:projectDeploy.  And what do I need to do after I put this in my
POJO?  How do I send the request to the other service?  

That page also has a section on proxies but I didn't get a full
understanding of what needs to be done from that section.  For example, how
can I create one for the wsdl-first example.  

Then I found the page on the client-api
http://incubator.apache.org/servicemix/client-api.html but is there a full
working example somewhere on using the client api to invoke a jsr-181
service unit.  For example, the wsdl-first has a client.html.  But how can I
use the client-api to invoke it?  I was unclear on the sample code that was
on that page because I don't know what example it pertains to and if there
is anything else that needs to be done.  

Any help is greatly appreciated.  Thanks.



Adrian Co wrote:
> 
> I wonder if you mean the jsr181 proxy.
> http://incubator.apache.org/servicemix/servicemix-jsr181.html
> http://incubator.apache.org/servicemix/orchestration-with-jsr181.html
> 
> smixuser wrote:
>> Does anyone have a working example of having 2 JSR 181 Service Units
>> which
>> can invoke each other within the JBI bus or instructions on how this can
>> be
>> done?  Thanks.
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Looking-for-Example-of-2-JSR181-Service-Units-Invoking-Each-Other-tf4193293s12049.html#a11944203
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Looking for Example of 2 JSR181 Service Units Invoking Each Other

Posted by Adrian Co <ac...@exist.com>.
I wonder if you mean the jsr181 proxy.
http://incubator.apache.org/servicemix/servicemix-jsr181.html
http://incubator.apache.org/servicemix/orchestration-with-jsr181.html

smixuser wrote:
> Does anyone have a working example of having 2 JSR 181 Service Units which
> can invoke each other within the JBI bus or instructions on how this can be
> done?  Thanks.
>