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: */
19: package org.apache.axis2.jaxws.provider.source;
20:
21: import org.apache.axis2.jaxws.TestLogger;
22:
23: import java.io.ByteArrayInputStream;
24: import java.io.InputStream;
25: import java.io.StringWriter;
26:
27: import javax.xml.transform.Result;
28: import javax.xml.transform.Source;
29: import javax.xml.transform.Transformer;
30: import javax.xml.transform.TransformerConfigurationException;
31: import javax.xml.transform.TransformerException;
32: import javax.xml.transform.TransformerFactory;
33: import javax.xml.transform.TransformerFactoryConfigurationError;
34: import javax.xml.transform.stream.StreamResult;
35: import javax.xml.transform.stream.StreamSource;
36: import javax.xml.ws.Provider;
37: import javax.xml.ws.WebServiceException;
38: import javax.xml.ws.WebServiceProvider;
39:
40: @WebServiceProvider()
41: public class SourceProvider implements Provider<Source> {
42:
43: // Same logic as StringProvider
44: public Source invoke(Source source) {
45:
46: TestLogger.logger
47: .debug(">> SourceProvider: Request received.\n");
48: if (source == null) {
49: return source;
50: }
51:
52: // Non-null source
53:
54: StringWriter writer = new StringWriter();
55: try {
56: Transformer t = TransformerFactory.newInstance()
57: .newTransformer();
58: Result result = new StreamResult(writer);
59: t.transform(source, result);
60: } catch (TransformerConfigurationException e) {
61: throw new WebServiceException(e);
62: } catch (TransformerFactoryConfigurationError e) {
63: throw new WebServiceException(e);
64: } catch (TransformerException e) {
65: throw new WebServiceException(e);
66: }
67: String text = writer.getBuffer().toString();
68: TestLogger.logger.debug(">> Source Request on Server: \n"
69: + text);
70:
71: if (text != null && text.contains("throwWebServiceException")) {
72: throw new WebServiceException("provider");
73: }
74:
75: ByteArrayInputStream stream = new ByteArrayInputStream(text
76: .getBytes());
77: Source srcStream = new StreamSource((InputStream) stream);
78: return srcStream;
79:
80: }
81:
82: }
|