2011. 1. 27. 18:37
서비스하나 맹가놓고.. soap, rest, json 등.. 입맛에 맞는 넘으로 endpoint를 열어 놓는 세상.. 참 좋구만..
Spring 설정을 보면..
import
작업하다 추가된 넘들이라.. 기억이 가물가물하지만.. 저넘들 하나하나가 특정 프로토콜을 사용하는 데 필요하다.
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:/META-INF/cxf/cxf-extension-jaxws.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:/META-INF/cxf/cxf-extension-jaxws.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-http-binding.xml" />
작업하다 추가된 넘들이라.. 기억이 가물가물하지만.. 저넘들 하나하나가 특정 프로토콜을 사용하는 데 필요하다.
JOSN endpoint 설정
뭐.. 이넘과 매핑되는 소스코드를 보면.. (다운로드 받으면 제공되는 예제 참조함)
결국 JaxWsServerFactoryBean 를 생성..
<jaxws:endpoint id="getServiceJson"
implementor="#starMapServiceImpl"
implementorClass="star.map.service.StarMapService"
address="/StarMapService/JSON"
bindingUri="http://apache.org/cxf/binding/http">
<jaxws:serviceFactory>
<bean class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">
<property name="wrapped" value="false"/>
<property name="properties">
<map>
<entry key="Content-Type" value="text/plain"/>
<entry>
<key><value>javax.xml.stream.XMLInputFactory</value></key>
<bean class="org.codehaus.jettison.mapped.MappedXMLInputFactory">
<constructor-arg>
<map>
<!-- targetNamespace : http://map.star -->
<entry key="http://map.star" value=""/>
</map>
</constructor-arg>
</bean>
</entry>
<entry>
<key><value>javax.xml.stream.XMLOutputFactory</value></key>
<bean class="org.codehaus.jettison.mapped.MappedXMLOutputFactory">
<constructor-arg>
<map>
<!-- targetNamespace : http://map.star -->
<entry key="http://map.star" value=""/>
</map>
</constructor-arg>
</bean>
</entry>
</map>
</property>
</bean>
</jaxws:serviceFactory>
</jaxws:endpoint>
implementor="#starMapServiceImpl"
implementorClass="star.map.service.StarMapService"
address="/StarMapService/JSON"
bindingUri="http://apache.org/cxf/binding/http">
<jaxws:serviceFactory>
<bean class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean">
<property name="wrapped" value="false"/>
<property name="properties">
<map>
<entry key="Content-Type" value="text/plain"/>
<entry>
<key><value>javax.xml.stream.XMLInputFactory</value></key>
<bean class="org.codehaus.jettison.mapped.MappedXMLInputFactory">
<constructor-arg>
<map>
<!-- targetNamespace : http://map.star -->
<entry key="http://map.star" value=""/>
</map>
</constructor-arg>
</bean>
</entry>
<entry>
<key><value>javax.xml.stream.XMLOutputFactory</value></key>
<bean class="org.codehaus.jettison.mapped.MappedXMLOutputFactory">
<constructor-arg>
<map>
<!-- targetNamespace : http://map.star -->
<entry key="http://map.star" value=""/>
</map>
</constructor-arg>
</bean>
</entry>
</map>
</property>
</bean>
</jaxws:serviceFactory>
</jaxws:endpoint>
뭐.. 이넘과 매핑되는 소스코드를 보면.. (다운로드 받으면 제공되는 예제 참조함)
private static void createJsonRestService(Object serviceObj) {
// Build up the server factory bean
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceClass(CustomerService.class);
// Use the HTTP Binding which understands the Java Rest Annotations
sf.setBindingId(HttpBindingFactory.HTTP_BINDING_ID);
sf.setAddress("http://localhost:8080/json");
sf.getServiceFactory().setInvoker(new BeanInvoker(serviceObj));
// Turn the "wrapped" style off. This means that CXF won't generate
// wrapper JSON elements and we'll have prettier JSON text. This
// means that we need to stick to one request and one response
// parameter though.
sf.getServiceFactory().setWrapped(false);
// Tell CXF to use a different Content-Type for the JSON endpoint
// This should probably be application/json, but text/plain allows
// us to view easily in a web browser.
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("Content-Type", "text/plain");
// Set up the JSON StAX implementation
Map<String, String> nstojns = new HashMap<String, String>();
nstojns.put("http://demo.restful.server", "acme");
MappedXMLInputFactory xif = new MappedXMLInputFactory(nstojns);
properties.put(XMLInputFactory.class.getName(), xif);
MappedXMLOutputFactory xof = new MappedXMLOutputFactory(nstojns);
properties.put(XMLOutputFactory.class.getName(), xof);
sf.setProperties(properties);
sf.create();
}
// Build up the server factory bean
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceClass(CustomerService.class);
// Use the HTTP Binding which understands the Java Rest Annotations
sf.setBindingId(HttpBindingFactory.HTTP_BINDING_ID);
sf.setAddress("http://localhost:8080/json");
sf.getServiceFactory().setInvoker(new BeanInvoker(serviceObj));
// Turn the "wrapped" style off. This means that CXF won't generate
// wrapper JSON elements and we'll have prettier JSON text. This
// means that we need to stick to one request and one response
// parameter though.
sf.getServiceFactory().setWrapped(false);
// Tell CXF to use a different Content-Type for the JSON endpoint
// This should probably be application/json, but text/plain allows
// us to view easily in a web browser.
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("Content-Type", "text/plain");
// Set up the JSON StAX implementation
Map<String, String> nstojns = new HashMap<String, String>();
nstojns.put("http://demo.restful.server", "acme");
MappedXMLInputFactory xif = new MappedXMLInputFactory(nstojns);
properties.put(XMLInputFactory.class.getName(), xif);
MappedXMLOutputFactory xof = new MappedXMLOutputFactory(nstojns);
properties.put(XMLOutputFactory.class.getName(), xof);
sf.setProperties(properties);
sf.create();
}
결국 JaxWsServerFactoryBean 를 생성..
REST
1. Spring 설정으로 배포
2. 소스코드로 배포
1. Spring 설정으로 배포
<jaxws:endpoint id="getServiceHttp"
implementor="#starMapServiceImpl"
implementorClass="star.map.service.StarMapService"
address="/StarMapService"
bindingUri="http://apache.org/cxf/binding/http">
<jaxws:serviceFactory>
<ref bean="jaxWsServiceFactoryBean"/>
</jaxws:serviceFactory>
</jaxws:endpoint>
<bean id="jaxWsServiceFactoryBean"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean" scope="prototype">
<property name="wrapped" value="false" />
</bean>
implementor="#starMapServiceImpl"
implementorClass="star.map.service.StarMapService"
address="/StarMapService"
bindingUri="http://apache.org/cxf/binding/http">
<jaxws:serviceFactory>
<ref bean="jaxWsServiceFactoryBean"/>
</jaxws:serviceFactory>
</jaxws:endpoint>
<bean id="jaxWsServiceFactoryBean"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean" scope="prototype">
<property name="wrapped" value="false" />
</bean>
2. 소스코드로 배포
private static void createRestService(Object serviceObj) {
// Build up the server factory bean
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceClass(CustomerService.class);
// Use the HTTP Binding which understands the Java Rest Annotations
sf.setBindingId(HttpBindingFactory.HTTP_BINDING_ID);
sf.setAddress("http://localhost:8080/xml/");
sf.getServiceFactory().setInvoker(new BeanInvoker(serviceObj));
// Turn the "wrapped" style off. This means that CXF won't generate
// wrapper XML elements and we'll have prettier XML text. This
// means that we need to stick to one request and one response
// parameter though.
sf.getServiceFactory().setWrapped(false);
sf.create();
}
// Build up the server factory bean
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceClass(CustomerService.class);
// Use the HTTP Binding which understands the Java Rest Annotations
sf.setBindingId(HttpBindingFactory.HTTP_BINDING_ID);
sf.setAddress("http://localhost:8080/xml/");
sf.getServiceFactory().setInvoker(new BeanInvoker(serviceObj));
// Turn the "wrapped" style off. This means that CXF won't generate
// wrapper XML elements and we'll have prettier XML text. This
// means that we need to stick to one request and one response
// parameter though.
sf.getServiceFactory().setWrapped(false);
sf.create();
}
SOAP
1. Spring 설정으로 배포
2. 소스코드로 배포
1. Spring 설정으로 배포
<jaxws:endpoint
id="getServiceSoap"
implementor="#starMapServiceImpl"
implementorClass="star.map.service.StarMapService"
address="/StarMapService/SOAP" />
id="getServiceSoap"
implementor="#starMapServiceImpl"
implementorClass="star.map.service.StarMapService"
address="/StarMapService/SOAP" />
2. 소스코드로 배포
private static void createSoapService(Object serviceObj) {
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceClass(CustomerService.class);
sf.setAddress("http://localhost:8080/soap");
sf.getServiceFactory().setInvoker(new BeanInvoker(serviceObj));
sf.getServiceFactory().setWrapped(false);
sf.create();
}
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceClass(CustomerService.class);
sf.setAddress("http://localhost:8080/soap");
sf.getServiceFactory().setInvoker(new BeanInvoker(serviceObj));
sf.getServiceFactory().setWrapped(false);
sf.create();
}
'framework > apache cxf' 카테고리의 다른 글
[JAX-RS] - file upload (0) | 2011.09.27 |
---|---|
[JAX-RS] - @Produces를 다중으로 설정 시 클라이언트 헤더 설정방법 (0) | 2011.09.27 |
[Apache cxf] - log4j 설정하자 (0) | 2010.06.28 |
[Apache cxf] - 톰켓에서 한글 설정하자 (0) | 2010.06.28 |
[Apache cxf] - session support (0) | 2010.06.28 |