Search in sources :

Example 36 with JaxWsServerFactoryBean

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());
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) SimpleAuthorizingInterceptor(org.apache.cxf.interceptor.security.SimpleAuthorizingInterceptor) Server(org.apache.cxf.endpoint.Server) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Service(org.apache.cxf.service.Service) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Example 37 with JaxWsServerFactoryBean

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);
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) SpringServerFactoryBean(org.apache.cxf.jaxws.spring.NamespaceHandler.SpringServerFactoryBean) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) BindingConfiguration(org.apache.cxf.binding.BindingConfiguration) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) Test(org.junit.Test)

Example 38 with JaxWsServerFactoryBean

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");
}
Also used : Server(org.apache.cxf.endpoint.Server) Message(org.apache.cxf.message.Message) AttachmentDeserializer(org.apache.cxf.attachment.AttachmentDeserializer) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Attachment(org.apache.cxf.message.Attachment) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestUtilities(org.apache.cxf.test.TestUtilities) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Conduit(org.apache.cxf.transport.Conduit) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 39 with JaxWsServerFactoryBean

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();
}
Also used : SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) BeforeClass(org.junit.BeforeClass)

Example 40 with JaxWsServerFactoryBean

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();
}
Also used : TestingWrappedEventSinkImpl(org.apache.cxf.ws.eventing.integration.eventsink.TestingWrappedEventSinkImpl) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean)

Aggregations

JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)106 Server (org.apache.cxf.endpoint.Server)32 Test (org.junit.Test)29 Service (org.apache.cxf.service.Service)21 Bus (org.apache.cxf.Bus)15 HashMap (java.util.HashMap)13 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)13 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)13 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)9 AbstractAegisTest (org.apache.cxf.aegis.AbstractAegisTest)8 QName (javax.xml.namespace.QName)7 AbstractJaxWsTest (org.apache.cxf.jaxws.AbstractJaxWsTest)7 BeforeClass (org.junit.BeforeClass)7 Endpoint (org.apache.cxf.endpoint.Endpoint)6 ServerFactoryBean (org.apache.cxf.frontend.ServerFactoryBean)6 JAXWSMethodInvoker (org.apache.cxf.jaxws.JAXWSMethodInvoker)6 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)6 AegisDatabinding (org.apache.cxf.aegis.databinding.AegisDatabinding)5 URL (java.net.URL)4 Definition (javax.wsdl.Definition)4