01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.systest.factory_pattern;
19:
20: import javax.jws.WebService;
21: import javax.xml.namespace.QName;
22:
23: import org.apache.cxf.BusFactory;
24: import org.apache.cxf.factory_pattern.NumberFactory;
25: import org.apache.cxf.interceptor.LoggingInInterceptor;
26: import org.apache.cxf.interceptor.LoggingOutInterceptor;
27: import org.apache.cxf.jaxws.EndpointImpl;
28: import org.apache.cxf.ws.addressing.EndpointReferenceType;
29: import org.apache.cxf.wsdl.EndpointReferenceUtils;
30:
31: @WebService(serviceName="NumberFactoryService",portName="NumberFactoryPort",endpointInterface="org.apache.cxf.factory_pattern.NumberFactory",targetNamespace="http://cxf.apache.org/factory_pattern")
32: public class NumberFactoryImpl implements NumberFactory {
33:
34: public static final String FACTORY_ADDRESS = "http://localhost:9006/NumberFactoryService/NumberFactoryPort";
35: public static final String NUMBER_SERVANT_ADDRESS_ROOT = "http://localhost:9006/NumberService/NumberPort/";
36: public static final String FACTORY_NS = "http://cxf.apache.org/factory_pattern";
37: public static final String NUMBER_SERVICE_NAME = "NumberService";
38: public static final String NUMBER_PORT_NAME = "NumberPort";
39:
40: public static final QName NUMBER_SERVICE_QNAME = new QName(
41: FACTORY_NS, NUMBER_SERVICE_NAME);
42: public static final QName NUMBER_PORT_TYPE_QNAME = new QName(
43: FACTORY_NS, NUMBER_PORT_NAME);
44:
45: protected EndpointReferenceType templateEpr;
46: protected NumberImpl servant;
47:
48: public NumberFactoryImpl() {
49: }
50:
51: public EndpointReferenceType create(String id) {
52:
53: manageNumberServantInitialisation();
54: int val = Integer.valueOf(id);
55:
56: // allow clients to drive test scenarios with val
57: String portName = "NumberPort";
58: if (val >= 30) {
59: // use jms transport
60: portName = "NumberPortJMS";
61: }
62: return EndpointReferenceUtils.getEndpointReferenceWithId(
63: NUMBER_SERVICE_QNAME, portName, id, BusFactory
64: .getDefaultBus());
65: }
66:
67: protected synchronized EndpointReferenceType manageNumberServantInitialisation() {
68: if (null == templateEpr) {
69: initDefaultServant();
70: }
71: return templateEpr;
72: }
73:
74: protected void initDefaultServant() {
75:
76: servant = new NumberImpl();
77: String wsdlLocation = "testutils/factory_pattern.wsdl";
78: String bindingId = null;
79:
80: EndpointImpl ep = new EndpointImpl(BusFactory.getDefaultBus(),
81: servant, bindingId, wsdlLocation);
82: ep.setEndpointName(new QName(NUMBER_SERVICE_QNAME
83: .getNamespaceURI(), "NumberPort"));
84: ep.publish();
85: templateEpr = ep.getServer().getDestination().getAddress();
86:
87: // jms port
88: ep = new EndpointImpl(BusFactory.getDefaultBus(), servant,
89: bindingId, wsdlLocation);
90: ep.setEndpointName(new QName(NUMBER_SERVICE_QNAME
91: .getNamespaceURI(), "NumberPortJMS"));
92: ep.publish();
93: ep.getServer().getEndpoint().getInInterceptors().add(
94: new LoggingInInterceptor());
95: ep.getServer().getEndpoint().getOutInterceptors().add(
96: new LoggingOutInterceptor());
97: }
98: }
|