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.binding.http.mtom;
19:
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import javax.activation.DataHandler;
24: import javax.mail.util.ByteArrayDataSource;
25:
26: import org.apache.cxf.binding.BindingFactoryManager;
27: import org.apache.cxf.binding.http.AbstractRestTest;
28: import org.apache.cxf.binding.http.HttpBindingFactory;
29: import org.apache.cxf.endpoint.ServerImpl;
30: import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
31: import org.apache.cxf.person.Person;
32: import org.apache.cxf.service.invoker.BeanInvoker;
33: import org.junit.Test;
34:
35: public class MtomTest extends AbstractRestTest {
36:
37: @Test
38: public void testService() throws Exception {
39: BindingFactoryManager bfm = getBus().getExtension(
40: BindingFactoryManager.class);
41: HttpBindingFactory factory = new HttpBindingFactory();
42: factory.setBus(getBus());
43: bfm.registerBindingFactory(HttpBindingFactory.HTTP_BINDING_ID,
44: factory);
45:
46: PeopleServiceImpl impl = new PeopleServiceImpl();
47:
48: JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
49: sf.setBus(getBus());
50: sf.setBindingId(HttpBindingFactory.HTTP_BINDING_ID);
51: sf.setServiceBean(impl);
52: sf.getServiceFactory().setInvoker(new BeanInvoker(impl));
53: sf.getServiceFactory().setWrapped(true);
54: sf.setAddress("http://localhost:9001/");
55:
56: Map<String, Object> props = new HashMap<String, Object>();
57: props.put("mtom-enabled", Boolean.TRUE);
58: sf.setProperties(props);
59:
60: ServerImpl svr = (ServerImpl) sf.create();
61:
62: // TEST POST/GETs
63:
64: Person p = new Person();
65: p.setName("Dan");
66: DataHandler handler = new DataHandler(new ByteArrayDataSource(
67: "foo".getBytes(), "application/octet-stream"));
68: p.setPhoto(handler);
69: impl.addPerson(p);
70:
71: byte[] res = doMethodBytes("http://localhost:9001/people",
72: null, "GET", null);
73: assertNotNull(res);
74:
75: // TODO: Test response
76: // IOUtils.copy(new ByteArrayInputStream(res), System.out);
77:
78: String ct = "multipart/related; type=\"application/xop+xml\"; "
79: + "start=\"<addPerson.xml>\"; "
80: + "start-info=\"text/xml; charset=utf-8\"; "
81: + "boundary=\"----=_Part_4_701508.1145579811786\"";
82:
83: res = doMethodBytes("http://localhost:9001/people",
84: "addPerson", "POST", ct);
85: assertNotNull(res);
86:
87: // TODO: Test response
88: // IOUtils.copy(new ByteArrayInputStream(res), System.out);
89:
90: assertEquals(2, impl.getPeople().getPerson().size());
91:
92: svr.stop();
93: }
94:
95: }
|