use of org.apache.cxf.jaxws.JaxWsServerFactoryBean in project cxf by apache.
the class UserNameTokenAuthorizationTest method setUpService.
public void setUpService(String expectedRoles, boolean digest, boolean encryptUsernameTokenOnly) throws Exception {
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceBean(new EchoImpl());
factory.setAddress("local://Echo");
factory.setTransportId(LocalTransportFactory.TRANSPORT_ID);
Server server = factory.create();
Service service = server.getEndpoint().getService();
service.getInInterceptors().add(new SAAJInInterceptor());
service.getInInterceptors().add(new LoggingInInterceptor());
service.getOutInterceptors().add(new SAAJOutInterceptor());
service.getOutInterceptors().add(new LoggingOutInterceptor());
wsIn = new SimpleSubjectCreatingInterceptor();
wsIn.setSupportDigestPasswords(digest);
wsIn.setProperty(ConfigurationConstants.SIG_PROP_FILE, "insecurity.properties");
wsIn.setProperty(ConfigurationConstants.DEC_PROP_FILE, "insecurity.properties");
wsIn.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
service.getInInterceptors().add(wsIn);
SimpleAuthorizingInterceptor sai = new SimpleAuthorizingInterceptor();
sai.setMethodRolesMap(Collections.singletonMap("echo", expectedRoles));
service.getInInterceptors().add(sai);
wsOut = new WSS4JOutInterceptor();
wsOut.setProperty(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
wsOut.setProperty(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
wsOut.setProperty(ConfigurationConstants.USER, "myalias");
if (digest) {
wsOut.setProperty("password", "myAliasPassword");
} else {
wsOut.setProperty(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
}
if (encryptUsernameTokenOnly) {
wsOut.setProperty(ConfigurationConstants.ENCRYPTION_USER, "myalias");
wsOut.setProperty(ConfigurationConstants.ENCRYPTION_PARTS, "{Content}{" + WSS4JConstants.WSSE_NS + "}UsernameToken");
}
wsOut.setProperty(ConfigurationConstants.PW_CALLBACK_CLASS, TestPwdCallback.class.getName());
service.getOutInterceptors().add(wsOut);
// Create the client
JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
proxyFac.setServiceClass(Echo.class);
proxyFac.setAddress("local://Echo");
proxyFac.getClientFactoryBean().setTransportId(LocalTransportFactory.TRANSPORT_ID);
echo = (Echo) proxyFac.create();
((BindingProvider) echo).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getInInterceptors().add(wsIn);
client.getInInterceptors().add(new SAAJInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
client.getOutInterceptors().add(wsOut);
client.getOutInterceptors().add(new SAAJOutInterceptor());
}
use of org.apache.cxf.jaxws.JaxWsServerFactoryBean in project cxf by apache.
the class SpringBeansTest method testServers.
@Test
public void testServers() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/servers.xml" });
JaxWsServerFactoryBean bean;
BindingConfiguration bc;
SoapBindingConfiguration sbc;
bean = (JaxWsServerFactoryBean) ctx.getBean("inlineSoapBindingRPC");
assertNotNull(bean);
bc = bean.getBindingConfig();
assertTrue(bc instanceof SoapBindingConfiguration);
sbc = (SoapBindingConfiguration) bc;
assertEquals("rpc", sbc.getStyle());
bean = (JaxWsServerFactoryBean) ctx.getBean("simple");
assertNotNull(bean);
bean = (JaxWsServerFactoryBean) ctx.getBean("inlineWsdlLocation");
assertNotNull(bean);
assertEquals(bean.getWsdlLocation(), "wsdl/hello_world_doc_lit.wsdl");
bean = (JaxWsServerFactoryBean) ctx.getBean("inlineSoapBinding");
assertNotNull(bean);
bc = bean.getBindingConfig();
assertTrue(bc instanceof SoapBindingConfiguration);
sbc = (SoapBindingConfiguration) bc;
assertTrue("Not soap version 1.2: " + sbc.getVersion(), sbc.getVersion() instanceof Soap12);
bean = (JaxWsServerFactoryBean) ctx.getBean("inlineDataBinding");
assertNotNull(bean);
boolean found = false;
String[] names = ctx.getBeanNamesForType(SpringServerFactoryBean.class);
for (String n : names) {
if (n.startsWith(SpringServerFactoryBean.class.getName())) {
found = true;
}
}
assertTrue("Could not find server factory with autogenerated id", found);
testNamespaceMapping(ctx);
}
use of org.apache.cxf.jaxws.JaxWsServerFactoryBean in project cxf by apache.
the class MtomServerTest method testURLBasedAttachment.
@Test
public void testURLBasedAttachment() throws Exception {
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new EchoService());
sf.setBus(getStaticBus());
String address = "http://localhost:" + PORT2 + "/EchoService";
sf.setAddress(address);
Map<String, Object> props = new HashMap<>();
props.put(Message.MTOM_ENABLED, "true");
sf.setProperties(props);
Server server = sf.create();
server.getEndpoint().getService().getDataBinding().setMtomThreshold(0);
servStatic(getClass().getResource("mtom-policy.xml"), "http://localhost:" + PORT2 + "/policy.xsd");
EndpointInfo ei = new EndpointInfo(null, HTTP_ID);
ei.setAddress(address);
ConduitInitiatorManager conduitMgr = getStaticBus().getExtension(ConduitInitiatorManager.class);
ConduitInitiator conduitInit = conduitMgr.getConduitInitiator("http://schemas.xmlsoap.org/soap/http");
Conduit conduit = conduitInit.getConduit(ei, getStaticBus());
TestUtilities.TestMessageObserver obs = new TestUtilities.TestMessageObserver();
conduit.setMessageObserver(obs);
Message m = new MessageImpl();
String ct = "multipart/related; type=\"application/xop+xml\"; " + "start=\"<soap.xml@xfire.codehaus.org>\"; " + "start-info=\"text/xml; charset=utf-8\"; " + "boundary=\"----=_Part_4_701508.1145579811786\"";
m.put(Message.CONTENT_TYPE, ct);
conduit.prepare(m);
OutputStream os = m.getContent(OutputStream.class);
InputStream is = testUtilities.getResourceAsStream("request-url-attachment");
if (is == null) {
throw new RuntimeException("Could not find resource " + "request");
}
try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
IOUtils.copy(is, bout);
String s = bout.toString(StandardCharsets.UTF_8.name());
s = s.replaceAll(":9036/", ":" + PORT2 + "/");
os.write(s.getBytes(StandardCharsets.UTF_8));
}
os.flush();
is.close();
os.close();
byte[] res = obs.getResponseStream().toByteArray();
MessageImpl resMsg = new MessageImpl();
resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
resMsg.setExchange(new ExchangeImpl());
AttachmentDeserializer deserializer = new AttachmentDeserializer(resMsg);
deserializer.initializeAttachments();
Collection<Attachment> attachments = resMsg.getAttachments();
assertNotNull(attachments);
assertEquals(1, attachments.size());
Attachment inAtt = attachments.iterator().next();
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
IOUtils.copy(inAtt.getDataHandler().getInputStream(), out);
assertTrue("Wrong size: " + out.size() + "\n" + out.toString(), out.size() > 970 && out.size() < 1020);
}
unregisterServStatic("http://localhost:" + PORT2 + "/policy.xsd");
}
use of org.apache.cxf.jaxws.JaxWsServerFactoryBean in project cxf by apache.
the class SoapActionTest method createServers.
@BeforeClass
public static void createServers() throws Exception {
bus = BusFactory.getDefaultBus();
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new SoapActionGreeterImpl());
sf.setAddress(add11);
sf.setBus(bus);
sf.create();
sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new SoapActionGreeterImpl());
sf.setAddress(add12);
sf.setBus(bus);
SoapBindingConfiguration config = new SoapBindingConfiguration();
config.setVersion(Soap12.getInstance());
sf.setBindingConfig(config);
sf.create();
sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new WrappedSoapActionGreeterImpl());
sf.setAddress(add13);
sf.setBus(bus);
sf.create();
sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new WrappedSoapActionGreeterImpl());
sf.setAddress(add14);
sf.setBus(bus);
config.setVersion(Soap12.getInstance());
sf.setBindingConfig(config);
sf.create();
sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new RPCLitSoapActionGreeterImpl());
sf.setAddress(add15);
sf.setBus(bus);
sf.create();
sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new RPCEncodedSoapActionGreeterImpl());
sf.setAddress(add16);
sf.setBus(bus);
sf.create();
sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new WrappedEncodedSoapActionGreeterImpl());
sf.setAddress(add17);
sf.setBus(bus);
sf.create();
}
use of org.apache.cxf.jaxws.JaxWsServerFactoryBean in project cxf by apache.
the class SimpleEventingIntegrationTest method createWrappedEventSink.
protected Server createWrappedEventSink(String address) {
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setBus(bus);
factory.setServiceBean(new TestingWrappedEventSinkImpl());
factory.setAddress(address);
return factory.create();
}
Aggregations