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.jaxws;
019:
020: import java.net.URL;
021:
022: import org.w3c.dom.Node;
023:
024: import org.apache.cxf.binding.soap.SoapFault;
025: import org.apache.cxf.binding.soap.SoapMessage;
026: import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
027: import org.apache.cxf.frontend.ServerFactoryBean;
028: import org.apache.cxf.interceptor.Fault;
029: import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
030: import org.apache.cxf.phase.Phase;
031: import org.apache.cxf.service.Service;
032: import org.apache.cxf.service.factory.ReflectionServiceFactoryBean;
033: import org.apache.cxf.service.invoker.BeanInvoker;
034: import org.apache.cxf.transport.local.LocalTransportFactory;
035: import org.apache.hello_world_soap_http.GreeterImpl;
036: import org.junit.Before;
037: import org.junit.Test;
038:
039: public class SoapFaultTest extends AbstractJaxWsTest {
040:
041: private Service service;
042:
043: @Before
044: public void setUp() throws Exception {
045: super .setUpBus();
046:
047: ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
048: URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
049: assertNotNull(resource);
050: bean.setWsdlURL(resource.toString());
051: bean.setBus(bus);
052: bean.setServiceClass(GreeterImpl.class);
053:
054: GreeterImpl greeter = new GreeterImpl();
055: BeanInvoker invoker = new BeanInvoker(greeter);
056: bean.setInvoker(invoker);
057:
058: service = bean.create();
059:
060: ServerFactoryBean svrFactory = new ServerFactoryBean();
061: svrFactory.setBus(bus);
062: svrFactory.setServiceFactory(bean);
063:
064: svrFactory.create();
065: }
066:
067: @Test
068: public void testInterceptorThrowingSoapFault() throws Exception {
069: service.getInInterceptors().add(new FaultThrowingInterceptor());
070:
071: Node response = invoke(
072: "http://localhost:9000/SoapContext/SoapPort",
073: LocalTransportFactory.TRANSPORT_ID,
074: "GreeterMessage.xml");
075:
076: assertNotNull(response);
077:
078: assertValid(
079: "/s:Envelope/s:Body/s:Fault/faultstring[text()='I blame Hadrian.']",
080: response);
081: }
082:
083: /**
084: * We need to get the jaxws fault -> soap fault conversion working for this
085: * @throws Exception
086: */
087: @Test
088: public void testWebServiceException() throws Exception {
089: Node response = invoke(
090: "http://localhost:9000/SoapContext/SoapPort",
091: LocalTransportFactory.TRANSPORT_ID,
092: "GreeterGetFaultMessage.xml");
093:
094: assertNotNull(response);
095:
096: assertValid(
097: "/s:Envelope/s:Body/s:Fault/faultstring[text()='TestBadRecordLit']",
098: response);
099: assertValid("/s:Envelope/s:Body/s:Fault/detail", response);
100: }
101:
102: public class FaultThrowingInterceptor extends
103: AbstractSoapInterceptor {
104: public FaultThrowingInterceptor() {
105: super (Phase.USER_LOGICAL);
106: }
107:
108: public void handleMessage(SoapMessage message) throws Fault {
109: throw new SoapFault("I blame Hadrian.", message
110: .getVersion().getSender());
111: }
112:
113: }
114: }
|