org.apache.cxf.endpoint.Server Java Examples

The following examples show how to use org.apache.cxf.endpoint.Server. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FragmentGetXPath10Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void getImpliedLanguageTest() throws XMLStreamException {
    String content = "<root><a><b>Text</b></a></root>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    ObjectFactory objectFactory = new ObjectFactory();

    Get request = new Get();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    ExpressionType expression = new ExpressionType();
    expression.getContent().add("/root/a/b");
    request.getAny().add(objectFactory.createExpression(expression));

    GetResponse response = client.get(request);
    ValueType value = getValue(response);
    Assert.assertEquals(1, value.getContent().size());
    Assert.assertEquals("b", ((Element)value.getContent().get(0)).getLocalName());

    resource.destroy();
}
 
Example #2
Source File: FragmentGetQNameTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void getTest() throws XMLStreamException {
    String content = "<root><a><b>Text</b></a></root>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    ObjectFactory objectFactory = new ObjectFactory();

    Get request = new Get();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    ExpressionType expression = new ExpressionType();
    expression.setLanguage(FragmentDialectConstants.QNAME_LANGUAGE_IRI);
    expression.getContent().add("a");
    request.getAny().add(objectFactory.createExpression(expression));

    GetResponse response = client.get(request);
    ValueType value = getValue(response);
    Assert.assertEquals(1, value.getContent().size());
    Assert.assertEquals("a", ((Element)value.getContent().get(0)).getLocalName());

    resource.destroy();
}
 
Example #3
Source File: DefaultApplicationFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Detects the application (if present) or creates the default application (in case the scan is disabled).
 */
public static ApplicationInfo createApplicationInfoOrDefault(final Server server, 
            final ServerProviderFactory factory, final JAXRSServiceFactoryBean sfb, final Bus bus, 
                final boolean scan) {
    
    ApplicationInfo appInfo = null;
    if (!scan) {
        appInfo = factory.getApplicationProvider();
        if (appInfo == null) {
            Set<Class<?>> serviceClasses = new HashSet<>();
            for (ClassResourceInfo cri : sfb.getClassResourceInfo()) {
                serviceClasses.add(cri.getServiceClass());
            }
            appInfo = createApplicationInfo(serviceClasses, bus);
            server.getEndpoint().put(Application.class.getName(), appInfo);
        }
    }
    
    return appInfo;
}
 
Example #4
Source File: FragmentGetXPath10Test.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void getNumberTest() throws XMLStreamException {
    String content = "<root><a><b>Text</b><b>Text2</b></a></root>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    ObjectFactory objectFactory = new ObjectFactory();

    Get request = new Get();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    ExpressionType expression = new ExpressionType();
    expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
    expression.getContent().add("count(//b)");
    request.getAny().add(objectFactory.createExpression(expression));

    GetResponse response = client.get(request);
    ValueType value = getValue(response);
    Assert.assertEquals(1, value.getContent().size());
    Assert.assertEquals("2", value.getContent().get(0));

    resource.destroy();
}
 
Example #5
Source File: AbstractTestCXFClientServerInterceptors.java    From kieker with Apache License 2.0 6 votes vote down vote up
private Server startServer() {
	LOGGER.info("XX: {}", this.serviceAddress);

	final JaxWsServerFactoryBean srvFactory = new JaxWsServerFactoryBean();
	srvFactory.setServiceClass(IBookstore.class);
	srvFactory.setAddress(this.serviceAddress);
	srvFactory.setServiceBean(new BookstoreImpl());

	// On the server-side, we only intercept incoming requests and outgoing
	// responses.
	srvFactory.getInInterceptors()
			.add(new OperationExecutionSOAPRequestInInterceptor(this.serverMonitoringController));
	srvFactory.getOutInterceptors()
			.add(new OperationExecutionSOAPResponseOutInterceptor(this.serverMonitoringController));
	return srvFactory.create(); // create() also starts the server
}
 
Example #6
Source File: ExceptionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test(expected = HelloException.class)
public void testJaxwsServerSimpleClient() throws Exception {
    JaxWsServerFactoryBean sfbean = new JaxWsServerFactoryBean();
    sfbean.setServiceClass(ExceptionService.class);
    sfbean.setDataBinding(new AegisDatabinding());
    sfbean.setAddress("local://ExceptionServiceJaxWs1");
    Server server = sfbean.create();
    Service service = server.getEndpoint().getService();
    service.setInvoker(new BeanInvoker(new ExceptionServiceImpl()));

    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://ExceptionServiceJaxWs1");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    ExceptionService clientInterface = proxyFac.create(ExceptionService.class);

    clientInterface.sayHiWithException();
}
 
Example #7
Source File: AbstractSpringConfigurationFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server createJaxRsServer() {

        JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
        factory.setAddress(getAddress());
        factory.setTransportId(getTransportId());
        factory.setBus(getBus());

        setJaxrsResources(factory);

        factory.setInInterceptors(getInInterceptors());
        factory.setOutInterceptors(getOutInterceptors());
        factory.setOutFaultInterceptors(getOutFaultInterceptors());
        factory.setFeatures(getFeatures());
        if (!StringUtils.isEmpty(jaxrsExtensions)) {
            factory.setExtensionMappings(CastUtils.cast((Map<?, ?>)parseMapSequence(jaxrsExtensions)));
        }
        finalizeFactorySetup(factory);
        return factory.create();
    }
 
Example #8
Source File: ServerFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbExtraClass() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setServiceClass(HelloServiceImpl.class);
    svrBean.setBus(getBus());

    Map<String, Object> props = svrBean.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses",
              new Class[] {GreetMe.class, GreetMeOneWay.class});
    svrBean.setProperties(props);
    Server serv = svrBean.create();
    Class<?>[] extraClass = ((JAXBDataBinding)serv.getEndpoint().getService()
            .getDataBinding()).getExtraClass();
    assertEquals(extraClass.length, 2);
    assertEquals(extraClass[0], GreetMe.class);
    assertEquals(extraClass[1], GreetMeOneWay.class);
}
 
Example #9
Source File: MEXUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static List<Element> getSchemas(Server server, String id) {
    Message message = PhaseInterceptorChain.getCurrentMessage();

    String base = (String)message.get(Message.REQUEST_URL);
    String ctxUri = (String)message.get(Message.PATH_INFO);

    WSDLGetUtils utils = new WSDLGetUtils();
    EndpointInfo info = server.getEndpoint().getEndpointInfo();
    Map<String, String> locs = utils.getSchemaLocations(message,
                                                  base,
                                                  ctxUri,
                                                  info);
    List<Element> ret = new LinkedList<>();
    for (Map.Entry<String, String> xsd : locs.entrySet()) {

        if (StringUtils.isEmpty(id)
            || id.equals(xsd.getKey())) {
            String query = xsd.getValue().substring(xsd.getValue().indexOf('?') + 1);
            Map<String, String> params = UrlUtils.parseQueryString(query);

            ret.add(utils.getDocument(message, base, params, ctxUri, info).getDocumentElement());
        }
    }
    return ret;
}
 
Example #10
Source File: CrossSchemaImportsTests.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbCrossSchemaImport() throws Exception {
    testUtilities.setBus((Bus)applicationContext.getBean("cxf"));
    testUtilities.addDefaultNamespaces();
    Server s = testUtilities.getServerForService(new QName("http://apache.org/type_test/doc",
                                                           "TypeTestPortTypeService"));
    Document wsdl = testUtilities.getWSDLDocument(s);
    testUtilities.
         assertValid("//xsd:schema[@targetNamespace='http://apache.org/type_test/doc']/"
                     + "xsd:import[@namespace='http://apache.org/type_test/types1']", wsdl);

    Assert.assertEquals(1, LifeCycleListenerTester.getInitCount());

    Assert.assertEquals(0, LifeCycleListenerTester.getShutdownCount());

    ((ConfigurableApplicationContext)applicationContext).close();
    Assert.assertEquals(1, LifeCycleListenerTester.getShutdownCount());
}
 
Example #11
Source File: JavaFirstSchemaValidationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: StudentTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReturnMap() throws Exception {

    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setServiceClass(StudentService.class);
    sf.setServiceBean(new StudentServiceImpl());
    sf.setAddress("local://StudentService");
    setupAegis(sf);
    Server server = sf.create();
    server.start();

    JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean();
    proxyFac.setAddress("local://StudentService");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    StudentService clientInterface = proxyFac.create(StudentService.class);
    Map<Long, Student> fullMap = clientInterface.getStudentsMap();
    assertNotNull(fullMap);
    Student one = fullMap.get(Long.valueOf(1));
    assertNotNull(one);
    assertEquals("Student1", one.getName());

    Map<String, ?> wildMap = clientInterface.getWildcardMap();
    assertEquals("valuestring", wildMap.get("keystring"));
}
 
Example #13
Source File: AbstractAegisTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server createJaxwsService(Class<?> serviceClass,
                                    Object serviceBean, String address, QName name) {
    if (address == null) {
        address = serviceClass.getSimpleName();
    }
    JaxWsServiceFactoryBean sf = new JaxWsServiceFactoryBean();
    sf.setDataBinding(new AegisDatabinding());
    JaxWsServerFactoryBean serverFactoryBean = new JaxWsServerFactoryBean();
    serverFactoryBean.setServiceClass(serviceClass);

    if (serviceBean != null) {
        serverFactoryBean.setServiceBean(serviceBean);
    }

    serverFactoryBean.setAddress("local://" + address);

    serverFactoryBean.setServiceFactory(sf);
    if (name != null) {
        serverFactoryBean.setEndpointName(name);
    }
    return serverFactoryBean.create();
}
 
Example #14
Source File: JaxWsServerFactoryBean.java    From cxf with Apache License 2.0 6 votes vote down vote up
public Server create() {
    ClassLoaderHolder orig = null;
    try {
        if (bus != null) {
            ClassLoader loader = bus.getExtension(ClassLoader.class);
            if (loader != null) {
                orig = ClassLoaderUtils.setThreadContextClassloader(loader);
            }
        }

        Server server = super.create();
        initializeResourcesAndHandlerChain(server);
        checkPrivateEndpoint(server.getEndpoint());

        return server;
    } finally {
        if (orig != null) {
            orig.reset();
        }
    }
}
 
Example #15
Source File: StudentTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testMapMap() throws Exception {

    ServerFactoryBean sf = new ServerFactoryBean();
    sf.setServiceClass(StudentServiceDocLiteral.class);
    sf.setServiceBean(new StudentServiceDocLiteralImpl());
    sf.setAddress("local://StudentServiceDocLiteral");
    setupAegis(sf);
    Server server = sf.create();
    server.start();

    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://StudentServiceDocLiteral");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());
    //CHECKSTYLE:OFF
    HashMap<String, Student> mss = new HashMap<>();
    mss.put("Alice", new Student());
    HashMap<String, HashMap<String, Student>> mmss = new HashMap<>();
    mmss.put("Bob", mss);

    StudentServiceDocLiteral clientInterface = proxyFac.create(StudentServiceDocLiteral.class);
    clientInterface.takeMapMap(mmss);
    //CHECKSTYLE:ON
}
 
Example #16
Source File: AppConfig.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Bean
public Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance()
            .createEndpoint(jaxRsApiApplication(), JAXRSServerFactoryBean.class);
    factory.setServiceBeans(Arrays.<Object>asList(peopleRestService()));
    factory.setAddress("/" + factory.getAddress());
    factory.setProviders(Arrays.<Object>asList(jsonProvider()));
    return factory.create();
}
 
Example #17
Source File: CxfTest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Test
public void testRs(final MockTracer tracer) {
  System.setProperty(Configuration.INTERCEPTORS_CLIENT_IN, ClientSpanTagInterceptor.class.getName());
  System.setProperty(Configuration.INTERCEPTORS_SERVER_OUT, ServerSpanTagInterceptor.class.getName());
  final String msg = "hello";

  // prepare server
  final JAXRSServerFactoryBean serverFactory = new JAXRSServerFactoryBean();
  serverFactory.setAddress(BASE_URI);
  serverFactory.setServiceBean(new EchoImpl());
  final Server server = serverFactory.create();

  // prepare client
  final JAXRSClientFactoryBean clientFactory = new JAXRSClientFactoryBean();
  clientFactory.setServiceClass(Echo.class);
  clientFactory.setAddress(BASE_URI);
  final Echo echo = clientFactory.create(Echo.class);

  final String response = echo.echo(msg);

  assertEquals(msg, response);
  assertEquals(2, tracer.finishedSpans().size());

  final WebClient client = WebClient.create(BASE_URI);
  final String result = client.post(msg, String.class);

  assertEquals(msg, result);
  assertEquals(4, tracer.finishedSpans().size());

  final List<MockSpan> spans = tracer.finishedSpans();
  for (final MockSpan span : spans) {
    assertEquals(AbstractSpanTagInterceptor.SPAN_TAG_VALUE, span.tags().get(AbstractSpanTagInterceptor.SPAN_TAG_KEY));
  }

  server.destroy();
  serverFactory.getBus().shutdown(true);
}
 
Example #18
Source File: JAXRSServerFactoryBeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testRegisterProviders() {
    JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
    bean.setAddress("http://localhost:8080/rest");
    bean.setStart(false);
    bean.setResourceClasses(BookStore.class);
    List<Object> providers = new ArrayList<>();
    Object provider1 = new CustomExceptionMapper();
    providers.add(provider1);
    Object provider2 = new RuntimeExceptionMapper();
    providers.add(provider2);
    bean.setProviders(providers);
    Server s = bean.create();

    ServerProviderFactory factory =
        (ServerProviderFactory)s.getEndpoint().get(ServerProviderFactory.class.getName());

    ExceptionMapper<Exception> mapper1 =
        factory.createExceptionMapper(Exception.class, new MessageImpl());
    assertNotNull(mapper1);
    ExceptionMapper<RuntimeException> mapper2 =
        factory.createExceptionMapper(RuntimeException.class, new MessageImpl());
    assertNotNull(mapper2);
    assertNotSame(mapper1, mapper2);
    assertSame(provider1, mapper1);
    assertSame(provider2, mapper2);


}
 
Example #19
Source File: StaxToDOMSignatureIdentifierTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Service createService() {
    // Create the Service
    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 LoggingInInterceptor());
    service.getOutInterceptors().add(new LoggingOutInterceptor());

    return service;
}
 
Example #20
Source File: ColocOutInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void verifyIsColocatedWithNullList() {
    Server val = colocOut.isColocated(null, null, null);
    assertEquals("Is not a colocated call",
                 null,
                 val);
    control.reset();
}
 
Example #21
Source File: JaxWsServerFactoryBeanTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleServiceClass() throws Exception {
    ServerFactoryBean factory = new ServerFactoryBean();
    factory.setServiceClass(Hello.class);
    String address = "http://localhost:9001/jaxwstest";
    factory.setAddress(address);
    Server server = factory.create();
    Endpoint endpoint = server.getEndpoint();
    ServiceInfo service = endpoint.getEndpointInfo().getService();
    assertNotNull(service);

    Bus bus = factory.getBus();
    Definition def = new ServiceWSDLBuilder(bus, service).build();

    WSDLWriter wsdlWriter = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter();
    def.setExtensionRegistry(bus.getExtension(WSDLManager.class).getExtensionRegistry());
    Document doc = wsdlWriter.getDocument(def);

    Map<String, String> ns = new HashMap<>();
    ns.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    ns.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    XPathUtils xpather = new XPathUtils(ns);
    xpather.isExist("/wsdl:definitions/wsdl:binding/soap:binding",
                    doc,
                    XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:binding/wsdl:operation[@name='add']/soap:operation",
                    doc,
                    XPathConstants.NODE);
    xpather.isExist("/wsdl:definitions/wsdl:service/wsdl:port[@name='add']/soap:address[@location='"
                    + address + "']",
                    doc,
                    XPathConstants.NODE);
}
 
Example #22
Source File: GenericAegisTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateJavascript() throws Exception {
 // Create our service implementation
    GenericGenericClass<String> impl = new GenericGenericClass<>();

    // Create our Server
    ServerFactoryBean svrFactory = new ServerFactoryBean();
    // we sure can't get a .class for the interface, can we?
    svrFactory.setServiceClass(impl.getClass());
    svrFactory.setAddress("http://localhost:" + PORT + "/aegisgeneric");
    svrFactory.setServiceBean(impl);
    Server server = svrFactory.create();
    ServiceInfo serviceInfo = ((EndpointImpl)server.getEndpoint()).getEndpointInfo().getService();
    Collection<SchemaInfo> schemata = serviceInfo.getSchemas();
    BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo);
    NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo
        .getXmlSchemaCollection());
    for (SchemaInfo schema : schemata) {
        SchemaJavascriptBuilder builder = new SchemaJavascriptBuilder(serviceInfo
            .getXmlSchemaCollection(), prefixManager, nameManager);
        String allThatJavascript = builder.generateCodeForSchema(schema.getSchema());
        assertNotNull(allThatJavascript);
    }

    ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null,
                                                                           prefixManager, nameManager);
    serviceBuilder.walk();
    String serviceJavascript = serviceBuilder.getCode();
    assertNotNull(serviceJavascript);

}
 
Example #23
Source File: ColocOutInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void verifyIsColocatedWithDifferentOperation() {
    //Funtion Param
    Server s1 = control.createMock(Server.class);
    List<Server> list = new ArrayList<>();
    list.add(s1);
    Endpoint sep = control.createMock(Endpoint.class);
    BindingOperationInfo sboi = control.createMock(BindingOperationInfo.class);
    //Local var
    Service ses = control.createMock(Service.class);
    ServiceInfo ssi = control.createMock(ServiceInfo.class);
    EndpointInfo sei = control.createMock(EndpointInfo.class);
    TestBindingInfo rbi = new TestBindingInfo(ssi, "testBinding");
    Endpoint rep = control.createMock(Endpoint.class);
    Service res = control.createMock(Service.class);
    EndpointInfo rei = control.createMock(EndpointInfo.class);

    EasyMock.expect(sep.getService()).andReturn(ses);
    EasyMock.expect(sep.getEndpointInfo()).andReturn(sei);
    EasyMock.expect(s1.getEndpoint()).andReturn(rep);
    EasyMock.expect(rep.getService()).andReturn(res);
    EasyMock.expect(rep.getEndpointInfo()).andReturn(rei);
    EasyMock.expect(ses.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(res.getName()).andReturn(new QName("A", "B"));
    EasyMock.expect(rei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(sei.getName()).andReturn(new QName("C", "D"));
    EasyMock.expect(rei.getBinding()).andReturn(rbi);
    EasyMock.expect(sboi.getName()).andReturn(new QName("E", "F"));
    //Causes ConcurrentModification intermittently
    //QName op = new QName("E", "F");
    //EasyMock.expect(rbi.getOperation(op).andReturn(null);

    control.replay();
    Server val = colocOut.isColocated(list, sep, sboi);
    assertEquals("Is not a colocated call",
                 null,
                 val);
    assertEquals("BindingOperation.getOperation was not called",
                 1, rbi.getOpCount());
    control.reset();
}
 
Example #24
Source File: HttpTestActivator.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Server createTestServer(String url) {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setServiceClass(Greeter.class);
    factory.setAddress(url);
    factory.setServiceBean(new GreeterImpl());
    return factory.create();
}
 
Example #25
Source File: ResourceFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void createRemoteResourceTest() {
    ReferenceParametersType refParams = createReferenceParameters();
    ResourceManager manager = EasyMock.createMock(ResourceManager.class);
    EasyMock.expect(manager.create(EasyMock.isA(Representation.class)))
            .andReturn(refParams);
    EasyMock.expectLastCall().once();
    EasyMock.replay(manager);

    Server remoteResourceFactory = createRemoteResourceFactory();
    Server remoteResource = createRemoteResource(manager);
    ResourceFactory client = createClient();

    Create createRequest = new Create();
    Representation representation = new Representation();
    representation.setAny(createXMLRepresentation());
    createRequest.setRepresentation(representation);

    CreateResponse response = client.create(createRequest);
    EasyMock.verify(manager);

    Assert.assertEquals("ResourceAddress is other than expected.", RESOURCE_REMOTE_ADDRESS,
            response.getResourceCreated().getAddress().getValue());
    Element refParamEl = (Element) response.getResourceCreated().getReferenceParameters().getAny().get(0);
    Assert.assertEquals(REF_PARAM_NAMESPACE, refParamEl.getNamespaceURI());
    Assert.assertEquals(REF_PARAM_LOCAL_NAME, refParamEl.getLocalName());
    Assert.assertEquals(RESOURCE_UUID, refParamEl.getTextContent());
    Assert.assertEquals("root", ((Element) response.getRepresentation().getAny()).getLocalName());
    Assert.assertEquals(2, ((Element) response.getRepresentation().getAny()).getChildNodes().getLength());

    remoteResourceFactory.destroy();
    remoteResource.destroy();
}
 
Example #26
Source File: SimpleEventingIntegrationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server createWrappedEventSink(String address) {
    JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
    factory.setBus(bus);
    factory.setServiceBean(new TestingWrappedEventSinkImpl());
    factory.setAddress(address);
    return factory.create();
}
 
Example #27
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testInjectApplicationInPerRequestResource() throws Exception {
    CustomerApplication app = new CustomerApplication();
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setServiceClass(Customer.class);
    sf.setApplication(app);
    sf.setStart(false);
    Server server = sf.create();

    @SuppressWarnings("unchecked")
    ThreadLocalProxy<UriInfo> proxy = (ThreadLocalProxy<UriInfo>)app.getUriInfo();
    assertNotNull(proxy);

    ClassResourceInfo cri = sf.getServiceFactory().getClassResourceInfo().get(0);

    Customer customer = (Customer)cri.getResourceProvider().getInstance(
         createMessage());

    assertNull(customer.getApplication1());
    assertNull(customer.getApplication2());

    invokeCustomerMethod(cri, customer, server);
    assertSame(app, customer.getApplication1());
    assertSame(app, customer.getApplication2());

    assertTrue(proxy.get() instanceof UriInfo);
}
 
Example #28
Source File: AppConfig.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Bean
public Server jaxRsServer() {
    JAXRSServerFactoryBean factory = RuntimeDelegate.getInstance().createEndpoint( jaxRsApiApplication(), JAXRSServerFactoryBean.class );
    factory.setServiceBeans( Arrays.< Object >asList( peopleRestService() ) );
    factory.setAddress( "/" + factory.getAddress() );
    factory.setProviders( Arrays.< Object >asList( jsonProvider() ) );
    return factory.create();
}
 
Example #29
Source File: FragmentPutReplaceTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void replaceAllElementsTest() throws XMLStreamException {
    String content = "<a><b/><b/></a>";
    ResourceManager resourceManager = new MemoryResourceManager();
    ReferenceParametersType refParams = resourceManager.create(getRepresentation(content));
    Server resource = createLocalResource(resourceManager);
    Resource client = createClient(refParams);

    Put request = new Put();
    request.setDialect(FragmentDialectConstants.FRAGMENT_2011_03_IRI);
    Fragment fragment = new Fragment();
    ExpressionType expression = new ExpressionType();
    expression.setLanguage(FragmentDialectConstants.XPATH10_LANGUAGE_IRI);
    expression.getContent().add("/a/b");
    Element replacedElement = DOMUtils.getEmptyDocument().createElement("c");
    ValueType value = new ValueType();
    value.getContent().add(replacedElement);
    fragment.setExpression(expression);
    fragment.setValue(value);
    request.getAny().add(fragment);

    PutResponse response = client.put(request);
    Element rootEl = (Element) response.getRepresentation().getAny();
    Assert.assertEquals(1, rootEl.getChildNodes().getLength());
    Assert.assertEquals("c", ((Element)rootEl.getChildNodes().item(0)).getLocalName());

    resource.destroy();
}
 
Example #30
Source File: MockWebServiceExtension.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
    Class<?> parameterType = parameterContext.getParameter().getType();
    if (WebServiceMock.class.equals(parameterType)) {
        return getMockWebServiceContext(extensionContext).webServiceMock;
    } else if (Server.class.equals(parameterType)) {
        return getMockWebServiceContext(extensionContext).server;
    }
    throw new ParameterResolutionException("Cannot resolve parameter for parameter context: " + parameterContext);
}