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.provider.datasource;
19:
20: import java.io.ByteArrayInputStream;
21: import java.io.ByteArrayOutputStream;
22: import java.util.logging.Logger;
23:
24: import javax.activation.DataSource;
25: import javax.mail.internet.MimeMultipart;
26: import javax.mail.util.ByteArrayDataSource;
27: import javax.xml.ws.BindingType;
28: import javax.xml.ws.Provider;
29: import javax.xml.ws.Service;
30: import javax.xml.ws.ServiceMode;
31: import javax.xml.ws.WebServiceContext;
32: import javax.xml.ws.WebServiceProvider;
33:
34: import org.apache.cxf.helpers.IOUtils;
35:
36: @WebServiceProvider(serviceName="ModelProvider")
37: @BindingType(value="http://cxf.apache.org/bindings/xformat")
38: @ServiceMode(value=Service.Mode.MESSAGE)
39: public class TestProvider extends AbstractProvider<DataSource>
40: implements Provider<DataSource> {
41:
42: static final Logger LOG = Logger.getLogger(TestProvider.class
43: .getName());
44:
45: @javax.annotation.Resource
46: public void setWebServiceContext(WebServiceContext wsc) {
47: super .setWebServiceContext(wsc);
48: }
49:
50: @Override
51: public DataSource invoke(DataSource req) {
52: return super .invoke(req);
53: }
54:
55: protected DataSource post(DataSource req) {
56: String msg;
57: try {
58: LOG.info("content type: " + req.getContentType());
59:
60: ByteArrayOutputStream baos = new ByteArrayOutputStream();
61: IOUtils.copy(req.getInputStream(), baos);
62: LOG.info("body [" + new String(baos.toByteArray()) + "]");
63: ByteArrayInputStream bais = new ByteArrayInputStream(baos
64: .toByteArray());
65: msg = "<ok/>";
66:
67: MimeMultipart multipart = DataSourceProviderTest
68: .readAttachmentParts(req.getContentType(), bais);
69: LOG.info("found " + multipart.getCount() + " parts");
70: return new ByteArrayDataSource(baos.toByteArray(), req
71: .getContentType());
72: } catch (Exception e) {
73: e.printStackTrace();
74: msg = "<fail/>";
75: }
76: return new ByteArrayDataSource(msg.getBytes(), "text/xml");
77: }
78:
79: @Override
80: protected DataSource get(DataSource req) {
81: String msg = "<doc><response>Hello</response></doc>";
82: return new ByteArrayDataSource(msg.getBytes(),
83: "application/octet-stream");
84: }
85:
86: }
|