KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > http > HttpURITest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.http;
18
19 import java.util.List JavaDoc;
20
21 import javax.jbi.messaging.ExchangeStatus;
22 import javax.jbi.messaging.InOnly;
23 import javax.jbi.messaging.MessageExchange;
24 import javax.jbi.messaging.NormalizedMessage;
25 import javax.jbi.servicedesc.ServiceEndpoint;
26
27 import junit.framework.TestCase;
28
29 import org.apache.servicemix.client.DefaultServiceMixClient;
30 import org.apache.servicemix.jbi.container.JBIContainer;
31 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
32 import org.apache.servicemix.jbi.jaxp.StringSource;
33 import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
34 import org.apache.servicemix.jbi.resolver.URIResolver;
35 import org.apache.servicemix.tck.ReceiverComponent;
36 import org.w3c.dom.DocumentFragment JavaDoc;
37 import org.w3c.dom.Element JavaDoc;
38
39 public class HttpURITest extends TestCase {
40
41     private JBIContainer jbi;
42
43     protected void setUp() throws Exception JavaDoc {
44         jbi = new JBIContainer();
45         jbi.setEmbedded(true);
46         jbi.setUseMBeanServer(false);
47         jbi.init();
48         jbi.start();
49     }
50
51     protected void tearDown() throws Exception JavaDoc {
52         jbi.shutDown();
53     }
54
55     public void testResolveEndpoint() throws Exception JavaDoc {
56         HttpSpringComponent http = new HttpSpringComponent();
57         HttpEndpoint ep = new HttpEndpoint();
58         ep.setRole(MessageExchange.Role.CONSUMER);
59         ep.setService(ReceiverComponent.SERVICE);
60         ep.setEndpoint(ReceiverComponent.ENDPOINT);
61         ep.setLocationURI("http://localhost:8192/");
62         ep.setDefaultMep(MessageExchangeSupport.IN_ONLY);
63         http.setEndpoints(new HttpEndpoint[] { ep });
64         jbi.activateComponent(http, "servicemix-http");
65
66         ReceiverComponent receiver = new ReceiverComponent();
67         jbi.activateComponent(receiver, "receiver");
68
69         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
70         DocumentFragment JavaDoc epr = URIResolver.createWSAEPR("http://localhost:8192?http.soap=true");
71         ServiceEndpoint se = client.getContext().resolveEndpointReference(epr);
72         assertNotNull(se);
73
74         InOnly inonly = client.createInOnlyExchange();
75         inonly.setEndpoint(se);
76         inonly.getInMessage().setContent(new StringSource("<hello>world</hello>"));
77         client.sendSync(inonly);
78
79         assertEquals(ExchangeStatus.DONE, inonly.getStatus());
80         receiver.getMessageList().assertMessagesReceived(1);
81         List JavaDoc msgs = receiver.getMessageList().flushMessages();
82         NormalizedMessage msg = (NormalizedMessage) msgs.get(0);
83         Element JavaDoc elem = new SourceTransformer().toDOMElement(msg);
84         assertEquals("http://www.w3.org/2003/05/soap-envelope", elem.getNamespaceURI());
85         assertEquals("env:Envelope", elem.getNodeName());
86         System.out.println(new SourceTransformer().contentToString(msg));
87     }
88
89 }
90
Popular Tags