示例#1
0
  @Test
  public void testServerFactoryBean() throws Exception {
    ServerFactoryBean svrBean = new ServerFactoryBean();
    svrBean.setAddress("http://localhost/Hello");
    svrBean.setTransportId("http://schemas.xmlsoap.org/soap/http");
    svrBean.setServiceBean(new HelloServiceImpl());
    svrBean.setServiceClass(HelloService.class);
    svrBean.setBus(getBus());

    svrBean.create();

    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress("http://localhost/Hello");
    clientBean.setTransportId("http://schemas.xmlsoap.org/soap/http");
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(getBus());
    clientBean.getInInterceptors().add(new LoggingInInterceptor());

    HelloService client = (HelloService) proxyFactory.create();

    ClientImpl c = (ClientImpl) ClientProxy.getClient(client);
    c.getOutInterceptors().add(new LoggingOutInterceptor());
    c.getInInterceptors().add(new LoggingInInterceptor());

    assertEquals("hello", client.sayHello());
    assertEquals("hello", client.echo("hello"));
  }
  @Test
  public void testClient() throws Exception {
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://IInterfaceService");
    proxyFac.setServiceClass(IInterfaceService.class);
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

    IInterfaceService client = (IInterfaceService) proxyFac.create();

    IChild child = client.getChild();
    assertNotNull(child);
    assertEquals("child", child.getChildName());
    assertEquals("parent", child.getParentName());

    IParent parent = client.getChildViaParent();
    assertEquals("parent", parent.getParentName());
    assertFalse(parent instanceof IChild);

    IGrandChild grandChild = client.getGrandChild();
    assertEquals("parent", grandChild.getParentName());

    Document wsdl = getWSDLDocument("IInterfaceService");
    assertValid("//xsd:complexType[@name='IGrandChild']", wsdl);
    assertValid(
        "//xsd:complexType[@name='IGrandChild']//xsd:element[@name='grandChildName']", wsdl);
    assertValid("//xsd:complexType[@name='IGrandChild']//xsd:element[@name='childName'][1]", wsdl);
    assertInvalid(
        "//xsd:complexType[@name='IGrandChild']//xsd:element[@name='childName'][2]", wsdl);
    assertValid("//xsd:complexType[@name='IChild']", wsdl);
    assertValid("//xsd:complexType[@name='IParent']", wsdl);
    assertInvalid("//xsd:complexType[@name='IChild'][@abstract='true']", wsdl);
  }
示例#3
0
  @Test(expected = HelloException.class)
  @Ignore("Not working yet due to namespace things")
  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();
  }
示例#4
0
  public static void main(String[] args) throws FileNotFoundException, IOException {

    ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
    factory.setServiceClass(ServiceSEI.class);
    factory.setAddress("http://localhost:9191/BPMNServer");
    ServiceSEI client = (ServiceSEI) factory.create();

    //		String fileName =
    // Thread.currentThread().getContextClassLoader().getResource("bpmn20.input.xml").getFile();
    String fileName = "src/main/resources/bpmn20.input.xml";
    byte[] buffer = new byte[(int) new File(fileName).length()];
    BufferedInputStream f = new BufferedInputStream(new FileInputStream(fileName));
    f.read(buffer);
    String content = new String(buffer);
    content.replace("<", "&lt;");
    content.replace(">", "&gt;");

    String result = client.CompleteBPMN(content);

    System.out.println("The file " + content + " is completed" + result);
  }
  @Test
  public void testInvokingServiceFromCXFClient() throws Exception {
    ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(simpleEndpointAddress);
    clientBean.setServiceClass(HelloService.class);
    clientBean.setBus(BusFactory.getDefaultBus());

    HelloService client = (HelloService) proxyFactory.create();
    assertNotNull(client);

    String result = client.echo(TEST_MESSAGE);
    assertEquals(
        "We should get the echo string result from router", result, "echo " + TEST_MESSAGE);

    Boolean bool = client.echoBoolean(Boolean.TRUE);
    assertNotNull("The result should not be null", bool);
    assertEquals("We should get the echo boolean result from router ", bool.toString(), "true");

    int beforeCallingPing = pingCounter;
    client.ping();
    int afterCallingPing = pingCounter;
    assertTrue("The ping operation doesn't be called", afterCallingPing - beforeCallingPing == 1);
  }
示例#6
0
  @Test
  public void testHeaders() throws Exception {
    ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
    proxyFac.setAddress("local://ExceptionService");
    proxyFac.setBus(getBus());
    setupAegis(proxyFac.getClientFactoryBean());

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

    try {
      client.sayHiWithException();
      fail("Must throw exception!");
    } catch (HelloException e) {
      // nothing
    }

    // check to make sure the fault is an element
    Document wsdl = getWSDLDocument("ExceptionService");
    addNamespace("tns", "http://exception.aegis.cxf.apache.org");
    assertValid(
        "//wsdl:message[@name='HelloException']/wsdl:part[@name='HelloException']"
            + "[@element='tns:String']",
        wsdl);
  }
  /** Create a CXF Client */
  @Override
  Client createClient() throws Exception {

    // get service class
    Class<?> cls = getSEIClass();

    if (getDataFormat().equals(DataFormat.POJO)) {
      ObjectHelper.notNull(cls, CxfConstants.SERVICE_CLASS);
    }

    if (getWsdlURL() == null && cls == null) {
      // no WSDL and serviceClass specified, set our default serviceClass
      setServiceClass(org.apache.camel.component.cxf.DefaultSEI.class.getName());
      setDefaultOperationNamespace(CxfConstants.DISPATCH_NAMESPACE);
      setDefaultOperationName(CxfConstants.DISPATCH_DEFAULT_OPERATION_NAMESPACE);
      if (getDataFormat().equals(DataFormat.PAYLOAD)) {
        setSkipPayloadMessagePartCheck(true);
      }
      cls = getSEIClass();
    }

    if (cls != null) {
      // create client factory bean
      ClientProxyFactoryBean factoryBean = createClientFactoryBean(cls);

      // configure client factory bean by CXF configurer
      configure(factoryBean);

      // setup client factory bean
      setupClientFactoryBean(factoryBean, cls);

      // fill in values that have not been filled.
      QName serviceQName = null;
      try {
        serviceQName = factoryBean.getServiceName();
      } catch (IllegalStateException e) {
        // It throws IllegalStateException if serviceName has not been set.
      }

      if (serviceQName == null && getServiceLocalName() != null) {
        factoryBean.setServiceName(new QName(getServiceNamespace(), getServiceLocalName()));
      }
      if (factoryBean.getEndpointName() == null && getEndpointLocalName() != null) {
        factoryBean.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
      }

      return ((ClientProxy) Proxy.getInvocationHandler(factoryBean.create())).getClient();
    } else {

      ClientFactoryBean factoryBean = createClientFactoryBean();

      // configure client factory bean by CXF configurer
      configure(factoryBean);

      // setup client factory bean
      setupClientFactoryBean(factoryBean);

      // fill in values that have not been filled.
      QName serviceQName = null;
      try {
        serviceQName = factoryBean.getServiceName();
      } catch (IllegalStateException e) {
        // It throws IllegalStateException if serviceName has not been set.
      }

      if (serviceQName == null && getServiceLocalName() != null) {
        factoryBean.setServiceName(new QName(getServiceNamespace(), getServiceLocalName()));
      }
      if (factoryBean.getEndpointName() == null && getEndpointLocalName() != null) {
        factoryBean.setEndpointName(new QName(getEndpointNamespace(), getEndpointLocalName()));
      }

      checkName(factoryBean.getEndpointName(), "endpoint/port name");
      checkName(factoryBean.getServiceName(), "service name");
      return (Client) factoryBean.create();
    }
  }