use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class ResourceTest method putRequestTest.
@Test
public void putRequestTest() {
ResourceManager manager = EasyMock.createMock(ResourceManager.class);
EasyMock.expect(manager.get(EasyMock.isA(ReferenceParametersType.class))).andReturn(new Representation());
EasyMock.expectLastCall().once();
manager.put(EasyMock.isA(ReferenceParametersType.class), EasyMock.isA(Representation.class));
EasyMock.expectLastCall().once();
EasyMock.replay(manager);
ReferenceParametersType refParams = new ReferenceParametersType();
Element uuid = DOMUtils.getEmptyDocument().createElementNS(MemoryResourceManager.REF_NAMESPACE, MemoryResourceManager.REF_LOCAL_NAME);
uuid.setTextContent(UUID_VALUE);
refParams.getAny().add(uuid);
Element representationEl = DOMUtils.getEmptyDocument().createElementNS(REPRESENTATION_NAMESPACE, REPRESENTATION_NAME);
representationEl.setTextContent(REPRESENTATION_VALUE);
Representation representation = new Representation();
representation.setAny(representationEl);
Server server = createLocalResource(manager);
Resource client = createClient(refParams);
Put putRequest = new Put();
putRequest.setRepresentation(representation);
PutResponse response = client.put(putRequest);
EasyMock.verify(manager);
representationEl = (Element) response.getRepresentation().getAny();
Assert.assertEquals("Namespace is other than expected.", REPRESENTATION_NAMESPACE, representationEl.getNamespaceURI());
Assert.assertEquals("Element name is other than expected", REPRESENTATION_NAME, representationEl.getLocalName());
Assert.assertEquals("Value is other than expected.", REPRESENTATION_VALUE, representationEl.getTextContent());
server.destroy();
}
use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class JavaFirstSchemaValidationTest method createServer.
public static Server createServer(String port, Class<?> serviceInterface, Object serviceImpl, SchemaValidationType type, Feature... features) throws IOException {
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setServiceClass(serviceImpl.getClass());
if (features != null) {
Collections.addAll(svrFactory.getFeatures(), features);
}
if (type != null) {
Map<String, Object> properties = new HashMap<>();
properties.put(Message.SCHEMA_VALIDATION_ENABLED, type);
svrFactory.setProperties(properties);
}
svrFactory.setAddress(getAddress(port, serviceInterface));
svrFactory.setServiceBean(serviceImpl);
Server server = svrFactory.create();
serverList.add(server);
return server;
}
use of org.apache.cxf.endpoint.Server in project cxf by apache.
the class WsdlGetUtilsTest method testNewDocumentIsCreatedForEachWsdlRequest.
@Test
public void testNewDocumentIsCreatedForEachWsdlRequest() {
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceBean(new StuffImpl());
factory.setAddress("http://localhost:" + PORT + "/Stuff");
Server server = factory.create();
try {
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
exchange.put(Bus.class, getBus());
exchange.put(Service.class, server.getEndpoint().getService());
exchange.put(Endpoint.class, server.getEndpoint());
message.setExchange(exchange);
Map<String, String> map = UrlUtils.parseQueryString("wsdl");
String baseUri = "http://localhost:" + PORT + "/Stuff";
String ctx = "/Stuff";
WSDLGetUtils utils = new WSDLGetUtils();
Document doc = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());
Document doc2 = utils.getDocument(message, baseUri, map, ctx, server.getEndpoint().getEndpointInfo());
assertFalse(doc == doc2);
} finally {
server.stop();
}
}
use of org.apache.cxf.endpoint.Server 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.endpoint.Server in project cxf by apache.
the class RoundTripTest method setUpService.
@Before
public void setUpService() 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 WSS4JInInterceptor();
wsIn.setProperty(ConfigurationConstants.SIG_VER_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);
wsOut = new WSS4JOutInterceptor();
wsOut.setProperty(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
wsOut.setProperty(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
wsOut.setProperty(ConfigurationConstants.USER, "myalias");
wsOut.setProperty("password", "myAliasPassword");
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();
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());
}
Aggregations