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.ws.addressing;
019:
020: import java.util.List;
021: import java.util.logging.Level;
022: import java.util.logging.Logger;
023:
024: import javax.xml.ws.Endpoint;
025:
026: import org.apache.cxf.Bus;
027: import org.apache.cxf.BusFactory;
028: import org.apache.cxf.bus.spring.SpringBusFactory;
029: import org.apache.cxf.interceptor.Interceptor;
030: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
031:
032: public class Server extends AbstractBusTestServerBase implements
033: VerificationCache {
034: static final String ADDRESS = "http://localhost:9008/SoapContext/SoapPort";
035:
036: private String verified;
037:
038: protected void run() {
039:
040: SpringBusFactory factory = new SpringBusFactory();
041: Bus bus = factory
042: .createBus("org/apache/cxf/systest/ws/addressing/wsa_interceptors.xml");
043: BusFactory.setDefaultBus(bus);
044: setBus(bus);
045:
046: addVerifiers();
047:
048: GreeterImpl implementor = new GreeterImpl();
049: implementor.verificationCache = this ;
050: Endpoint.publish(ADDRESS, implementor);
051: }
052:
053: protected void addVerifiers() {
054: MAPVerifier mapVerifier = new MAPVerifier();
055: mapVerifier.verificationCache = this ;
056: HeaderVerifier headerVerifier = new HeaderVerifier();
057: headerVerifier.verificationCache = this ;
058: Interceptor[] interceptors = { mapVerifier, headerVerifier };
059: addInterceptors(getBus().getInInterceptors(), interceptors);
060: addInterceptors(getBus().getInFaultInterceptors(), interceptors);
061: addInterceptors(getBus().getOutInterceptors(), interceptors);
062: addInterceptors(getBus().getOutFaultInterceptors(),
063: interceptors);
064: }
065:
066: private void addInterceptors(List<Interceptor> chain,
067: Interceptor[] interceptors) {
068: for (int i = 0; i < interceptors.length; i++) {
069: chain.add(interceptors[i]);
070: }
071: }
072:
073: public static void main(String[] args) {
074: try {
075: Server s = new Server();
076: s.start();
077: } catch (Exception ex) {
078: ex.printStackTrace();
079: System.exit(-1);
080: } finally {
081: System.out.println("done!");
082: }
083: }
084:
085: public void put(String verification) {
086: if (verification != null) {
087: verified = verified == null ? verification : verified
088: + "; " + verification;
089: }
090: }
091:
092: /**
093: * Used to facilitate assertions on server-side behaviour.
094: *
095: * @param log logger to use for diagnostics if assertions fail
096: * @return true if assertions hold
097: */
098: protected boolean verify(Logger log) {
099: if (verified != null) {
100: System.out.println("MAP/Header verification failed: "
101: + verified);
102: log.log(Level.WARNING,
103: "MAP/Header verification failed: {0}", verified);
104: }
105: return verified == null;
106: }
107: }
|