001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.systest.factory_pattern;
019:
020: import java.lang.reflect.InvocationHandler;
021: import java.lang.reflect.Proxy;
022: import java.util.HashMap;
023: import java.util.Map;
024:
025: import javax.xml.ws.BindingProvider;
026: import javax.xml.ws.Endpoint;
027: import javax.xml.ws.Service;
028:
029: import org.apache.cxf.factory_pattern.IsEvenResponse;
030: import org.apache.cxf.factory_pattern.Number;
031: import org.apache.cxf.factory_pattern.NumberFactory;
032: import org.apache.cxf.factory_pattern.NumberFactoryService;
033: import org.apache.cxf.factory_pattern.NumberService;
034: import org.apache.cxf.jaxws.ServiceImpl;
035: import org.apache.cxf.jaxws.support.ServiceDelegateAccessor;
036: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
037: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
038: import org.apache.cxf.ws.addressing.EndpointReferenceType;
039:
040: import org.junit.BeforeClass;
041: import org.junit.Test;
042:
043: /*
044: * exercise with multiplexWithAddress config rather than ws-a headers
045: */
046: public class MultiplexHttpAddressClientServerTest extends
047: AbstractBusClientServerTestBase {
048:
049: public static class Server extends AbstractBusTestServerBase {
050:
051: protected void run() {
052: Object implementor = new HttpNumberFactoryImpl();
053: Endpoint.publish(NumberFactoryImpl.FACTORY_ADDRESS,
054: implementor);
055: }
056:
057: public static void main(String[] args) {
058: try {
059: Server s = new Server();
060: s.start();
061: } catch (Exception ex) {
062: ex.printStackTrace();
063: System.exit(-1);
064: } finally {
065: System.out.println("done!");
066: }
067: }
068: }
069:
070: @BeforeClass
071: public static void startServers() throws Exception {
072: // no need for ws-a, just enable multiplexWithAddress on server
073: Map<String, String> props = new HashMap<String, String>();
074: props.put("cxf.config.file",
075: "org/apache/cxf/systest/factory_pattern/cxf.xml");
076: assertTrue("server did not launch correctly", launchServer(
077: Server.class, props, null));
078: }
079:
080: @Test
081: public void testWithGetPortExtensionHttp() throws Exception {
082:
083: NumberFactoryService service = new NumberFactoryService();
084: NumberFactory factory = service.getNumberFactoryPort();
085:
086: NumberService numService = new NumberService();
087: ServiceImpl serviceImpl = ServiceDelegateAccessor
088: .get(numService);
089:
090: EndpointReferenceType numberTwoRef = factory.create("20");
091: assertNotNull("reference", numberTwoRef);
092:
093: Number num = (Number) serviceImpl.getPort(numberTwoRef,
094: Number.class);
095: assertTrue("20 is even", num.isEven().isEven());
096:
097: EndpointReferenceType numberTwentyThreeRef = factory
098: .create("23");
099: num = (Number) serviceImpl.getPort(numberTwentyThreeRef,
100: Number.class);
101: assertTrue("23 is not even", !num.isEven().isEven());
102: }
103:
104: @Test
105: public void testWithManualMultiplexEprCreation() throws Exception {
106:
107: Service numService = Service
108: .create(NumberFactoryImpl.NUMBER_SERVICE_QNAME);
109: Number num = (Number) numService.getPort(Number.class);
110:
111: InvocationHandler handler = Proxy.getInvocationHandler(num);
112: BindingProvider bp = (BindingProvider) handler;
113: bp.getRequestContext().put(
114: BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
115: NumberFactoryImpl.NUMBER_SERVANT_ADDRESS_ROOT + "103");
116:
117: IsEvenResponse numResp = num.isEven();
118: assertTrue("103 is not even", Boolean.FALSE.equals(numResp
119: .isEven()));
120: }
121: }
|