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.handlers;
019:
020: import java.util.ArrayList;
021: import java.util.List;
022: import javax.annotation.Resource; //import javax.jws.HandlerChain;
023: import javax.jws.HandlerChain;
024: import javax.jws.WebService;
025: import javax.xml.namespace.QName;
026: import javax.xml.soap.SOAPException;
027: import javax.xml.soap.SOAPFactory;
028: import javax.xml.soap.SOAPFault;
029: import javax.xml.ws.WebServiceContext;
030: import javax.xml.ws.WebServiceException;
031: import javax.xml.ws.handler.MessageContext;
032: import javax.xml.ws.soap.SOAPFaultException;
033:
034: import org.apache.cxf.helpers.CastUtils;
035: import org.apache.handler_test.HandlerTest;
036: import org.apache.handler_test.PingException;
037: import org.apache.handler_test.types.PingFaultDetails;
038:
039: @WebService(serviceName="HandlerTestService",portName="SoapPort",endpointInterface="org.apache.handler_test.HandlerTest",targetNamespace="http://apache.org/handler_test",wsdlLocation="testutils/handler_test.wsdl")
040: @HandlerChain(file="./handlers_invocation.xml",name="TestHandlerChain")
041: public class HandlerTestImpl implements HandlerTest {
042:
043: private WebServiceContext context;
044:
045: public final List<String> ping() {
046:
047: try {
048: List<String> handlerInfoList = getHandlersInfo(context
049: .getMessageContext());
050: handlerInfoList.add("servant");
051: context.getMessageContext().remove("handler.info");
052: System.out.println(">> servant returning list: "
053: + handlerInfoList);
054: return handlerInfoList;
055:
056: } catch (Exception e) {
057: e.printStackTrace();
058:
059: }
060: return null;
061: }
062:
063: public final void pingOneWay() {
064: }
065:
066: public final List<String> pingWithArgs(String handlerCommand)
067: throws PingException {
068:
069: List<String> ret = new ArrayList<String>();
070: ret.add(handlerCommand);
071: ret.addAll(getHandlersInfo(context.getMessageContext()));
072:
073: if (handlerCommand.contains("servant throw exception")) {
074: PingFaultDetails details = new PingFaultDetails();
075: details.setDetail(ret.toString());
076: throw new PingException("from servant", details);
077: } else if (handlerCommand
078: .contains("servant throw RuntimeException")) {
079: throw new RuntimeException("servant throw RuntimeException");
080: } else if (handlerCommand
081: .contains("servant throw SOAPFaultException")) {
082: throw createSOAPFaultException("servant throws SOAPFaultException");
083: } else if (handlerCommand
084: .contains("servant throw WebServiceException")) {
085: RuntimeException re = new RuntimeException(
086: "servant throws RuntimeException");
087: throw new WebServiceException(
088: "RemoteException with nested RuntimeException", re);
089: }
090:
091: return ret;
092: }
093:
094: private SOAPFaultException createSOAPFaultException(
095: String faultString) {
096: try {
097: SOAPFault fault = SOAPFactory.newInstance().createFault();
098: fault.setFaultString(faultString);
099: fault.setFaultCode(new QName(
100: "http://cxf.apache.org/faultcode", "Server"));
101: return new SOAPFaultException(fault);
102: } catch (SOAPException e) {
103: // do nothing
104: }
105: return null;
106: }
107:
108: @Resource
109: public void setWebServiceContext(WebServiceContext ctx) {
110: context = ctx;
111: }
112:
113: private List<String> getHandlersInfo(MessageContext ctx) {
114: List<String> ret = CastUtils.cast((List) ctx
115: .get("handler.info"));
116: if (ret == null) {
117: ret = new ArrayList<String>();
118: }
119: return ret;
120: }
121:
122: }
|