01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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;
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 org.w3c.dom.DocumentFragment;
28: import org.w3c.dom.Element;
29:
30: import junit.framework.TestCase;
31:
32: import org.apache.commons.logging.Log;
33: import org.apache.commons.logging.LogFactory;
34: import org.apache.servicemix.client.DefaultServiceMixClient;
35: import org.apache.servicemix.jbi.container.JBIContainer;
36: import org.apache.servicemix.jbi.jaxp.SourceTransformer;
37: import org.apache.servicemix.jbi.jaxp.StringSource;
38: import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
39: import org.apache.servicemix.jbi.resolver.URIResolver;
40: import org.apache.servicemix.tck.ReceiverComponent;
41:
42: public class HttpURITest extends TestCase {
43: private static Log logger = LogFactory.getLog(HttpURITest.class);
44:
45: private JBIContainer jbi;
46:
47: protected void setUp() throws Exception {
48: jbi = new JBIContainer();
49: jbi.setEmbedded(true);
50: jbi.setUseMBeanServer(false);
51: jbi.init();
52: jbi.start();
53: }
54:
55: protected void tearDown() throws Exception {
56: jbi.shutDown();
57: }
58:
59: public void testResolveEndpoint() throws Exception {
60: HttpComponent http = new HttpComponent();
61: HttpEndpoint ep = new HttpEndpoint();
62: ep.setRole(MessageExchange.Role.CONSUMER);
63: ep.setService(ReceiverComponent.SERVICE);
64: ep.setEndpoint(ReceiverComponent.ENDPOINT);
65: ep.setLocationURI("http://localhost:8192/");
66: ep.setDefaultMep(MessageExchangeSupport.IN_ONLY);
67: http.setEndpoints(new HttpEndpoint[] { ep });
68: jbi.activateComponent(http, "servicemix-http");
69:
70: ReceiverComponent receiver = new ReceiverComponent();
71: jbi.activateComponent(receiver, "receiver");
72:
73: DefaultServiceMixClient client = new DefaultServiceMixClient(
74: jbi);
75: DocumentFragment epr = URIResolver
76: .createWSAEPR("http://localhost:8192/?http.soap=true");
77: ServiceEndpoint se = client.getContext()
78: .resolveEndpointReference(epr);
79: assertNotNull(se);
80:
81: InOnly inonly = client.createInOnlyExchange();
82: inonly.setEndpoint(se);
83: inonly.getInMessage().setContent(
84: new StringSource("<hello>world</hello>"));
85: client.sendSync(inonly);
86:
87: assertEquals(ExchangeStatus.DONE, inonly.getStatus());
88: receiver.getMessageList().assertMessagesReceived(1);
89: List msgs = receiver.getMessageList().flushMessages();
90: NormalizedMessage msg = (NormalizedMessage) msgs.get(0);
91: Element elem = new SourceTransformer().toDOMElement(msg);
92: assertEquals("http://www.w3.org/2003/05/soap-envelope", elem
93: .getNamespaceURI());
94: assertEquals("env:Envelope", elem.getNodeName());
95: logger.info(new SourceTransformer().contentToString(msg));
96: }
97:
98: }
|