Java Code Examples for org.apache.cxf.service.model.ServiceInfo#getInterface()

The following examples show how to use org.apache.cxf.service.model.ServiceInfo#getInterface() . 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: URIDomainExpression.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public boolean appliesTo(ServiceInfo si) {
    if (si == null) {
        return false;
    }
    if (wsdl11XPointer.matchesWsdl(si.getTargetNamespace())) {
        return true;
    }
    if ((si.getName() != null)
        && wsdl11XPointer.matchesService(si.getTargetNamespace(), si.getName().getLocalPart())) {
        return true;
    }
    return (si.getInterface() != null) && (si.getInterface().getName() != null)
        && wsdl11XPointer.matchesPortType(si.getTargetNamespace(),
                                          si.getInterface().getName().getLocalPart());
}
 
Example 2
Source File: PortTypeProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void processClassNames(ServiceInfo serviceInfo) throws ToolException {
    InterfaceInfo interfaceInfo = serviceInfo.getInterface();
    if (interfaceInfo == null) {
        return;
    }
    getInterface(context, serviceInfo, interfaceInfo);
}
 
Example 3
Source File: PortTypeProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void process(ServiceInfo serviceInfo) throws ToolException {
    operationMap.clear();
    JavaModel jmodel = context.get(JavaModel.class);


    InterfaceInfo interfaceInfo = serviceInfo.getInterface();

    if (interfaceInfo == null) {
        return;
    }

    JavaInterface intf = getInterface(context, serviceInfo, interfaceInfo);
    intf.setJavaModel(jmodel);

    Element handler = (Element)context.get(ToolConstants.HANDLER_CHAIN);
    intf.setHandlerChains(handler);


    Collection<OperationInfo> operations = interfaceInfo.getOperations();

    for (OperationInfo operation : operations) {
        if (isOverloading(operation.getName())) {
            LOG.log(Level.WARNING, "SKIP_OVERLOADED_OPERATION", operation.getName());
            continue;
        }
        OperationProcessor operationProcessor = new OperationProcessor(context);
        operationProcessor.process(intf, operation);
    }

    jmodel.setLocation(intf.getLocation());
    jmodel.addInterface(intf.getName(), intf);
}
 
Example 4
Source File: JaxWsServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Set<Class<?>> generatedWrapperBeanClass() {
    DataBinding b = getDataBinding();
    if (b.getClass().getName().endsWith("JAXBDataBinding")
        && schemaLocations == null) {
        ServiceInfo serviceInfo = getService().getServiceInfos().get(0);
        WrapperClassGenerator wrapperGen = new WrapperClassGenerator(this,
                                                                     serviceInfo.getInterface(),
                                                                     getQualifyWrapperSchema());
        return wrapperGen.generate();
    }
    return Collections.emptySet();
}
 
Example 5
Source File: ReflectionServiceFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnwrappedBuild() throws Exception {
    Service service = createService(false);

    ServiceInfo si = service.getServiceInfos().get(0);
    InterfaceInfo intf = si.getInterface();

    assertEquals(4, intf.getOperations().size());

    String ns = si.getName().getNamespaceURI();
    OperationInfo sayHelloOp = intf.getOperation(new QName(ns, "sayHello"));
    assertNotNull(sayHelloOp);

    assertEquals("sayHello", sayHelloOp.getInput().getName().getLocalPart());

    List<MessagePartInfo> messageParts = sayHelloOp.getInput().getMessageParts();
    assertEquals(0, messageParts.size());

    // test output
    messageParts = sayHelloOp.getOutput().getMessageParts();
    assertEquals(1, messageParts.size());
    assertEquals("sayHelloResponse", sayHelloOp.getOutput().getName().getLocalPart());

    MessagePartInfo mpi = messageParts.get(0);
    assertEquals("return", mpi.getName().getLocalPart());
    assertEquals(String.class, mpi.getTypeClass());


    OperationInfo op = si.getInterface().getOperation(new QName(ns, "echoWithExchange"));
    assertEquals(1, op.getInput().getMessageParts().size());
}
 
Example 6
Source File: ReflectionServiceFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testWrappedBuild() throws Exception {
    Service service = createService(true);

    ServiceInfo si = service.getServiceInfos().get(0);
    InterfaceInfo intf = si.getInterface();

    assertEquals(4, intf.getOperations().size());

    String ns = si.getName().getNamespaceURI();
    OperationInfo sayHelloOp = intf.getOperation(new QName(ns, "sayHello"));
    assertNotNull(sayHelloOp);

    assertEquals("sayHello", sayHelloOp.getInput().getName().getLocalPart());

    List<MessagePartInfo> messageParts = sayHelloOp.getInput().getMessageParts();
    assertEquals(1, messageParts.size());
    assertNotNull(messageParts.get(0).getXmlSchema());

    // test unwrapping
    assertTrue(sayHelloOp.isUnwrappedCapable());

    OperationInfo unwrappedOp = sayHelloOp.getUnwrappedOperation();
    assertEquals("sayHello", unwrappedOp.getInput().getName().getLocalPart());

    messageParts = unwrappedOp.getInput().getMessageParts();
    assertEquals(0, messageParts.size());

    // test output
    messageParts = sayHelloOp.getOutput().getMessageParts();
    assertEquals(1, messageParts.size());
    assertEquals("sayHelloResponse", sayHelloOp.getOutput().getName().getLocalPart());

    messageParts = unwrappedOp.getOutput().getMessageParts();
    assertEquals("sayHelloResponse", unwrappedOp.getOutput().getName().getLocalPart());
    assertEquals(1, messageParts.size());
    MessagePartInfo mpi = messageParts.get(0);
    assertEquals("return", mpi.getName().getLocalPart());
    assertEquals(String.class, mpi.getTypeClass());
}
 
Example 7
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected InterfaceInfo getInterfaceInfo() {
    if (getEndpointInfo() != null) {
        return getEndpointInfo().getInterface();
    }
    QName qn = this.getInterfaceName();
    for (ServiceInfo si : getService().getServiceInfos()) {
        if (qn.equals(si.getInterface().getName())) {
            return si.getInterface();
        }
    }
    throw new ServiceConstructionException(new Message("COULD_NOT_FIND_PORTTYPE", LOG, qn));
}
 
Example 8
Source File: WrapperClassGeneratorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@org.junit.Test
public void testForXmlList() throws Exception {
    JaxWsImplementorInfo implInfo =
        new JaxWsImplementorInfo(AddNumbersImpl.class);
    JaxWsServiceFactoryBean jaxwsFac = new JaxWsServiceFactoryBean(implInfo);
    jaxwsFac.setBus(BusFactory.getDefaultBus());
    Service service = jaxwsFac.create();


    ServiceInfo serviceInfo = service.getServiceInfos().get(0);

    InterfaceInfo interfaceInfo = serviceInfo.getInterface();
    OperationInfo inf = interfaceInfo.getOperations().iterator().next();
    Class<?> requestClass = inf.getInput().getMessagePart(0).getTypeClass();
    Class<?> responseClass = inf.getOutput().getMessagePart(0).getTypeClass();

    // Create request wrapper Object
    List<String> partNames = Arrays.asList(new String[] {"arg0"});
    List<String> elTypeNames = Arrays.asList(new String[] {"list"});
    List<Class<?>> partClasses = Arrays.asList(new Class<?>[] {List.class});

    String className = requestClass.getName();
    className = className.substring(0, className.lastIndexOf('.') + 1);

    WrapperHelper wh = new JAXBDataBinding().createWrapperHelper(requestClass, null,
                                                         partNames, elTypeNames, partClasses);

    List<Object> paraList = new ArrayList<>();
    List<String> valueList = new ArrayList<>();
    valueList.add("str1");
    valueList.add("str2");
    valueList.add("str3");
    paraList.add(valueList);
    Object requestObj = wh.createWrapperObject(paraList);
    // Create response wrapper Object

    partNames = Arrays.asList(new String[] {"return"});
    elTypeNames = Arrays.asList(new String[] {"list"});
    partClasses = Arrays.asList(new Class<?>[] {List.class});

    className = responseClass.getName();
    className = className.substring(0, className.lastIndexOf('.') + 1);

    wh = new JAXBDataBinding().createWrapperHelper(responseClass, null,
                                                         partNames, elTypeNames, partClasses);
    List<Object> resPara = new ArrayList<>();
    List<Integer> intValueList = new ArrayList<>();
    intValueList.add(1);
    intValueList.add(2);
    intValueList.add(3);
    resPara.add(intValueList);
    Object responseObj = wh.createWrapperObject(resPara);

    JAXBContext jaxbContext = JAXBContext.newInstance(requestClass, responseClass);
    java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
    Marshaller marshaller = jaxbContext.createMarshaller();

    //check marshall wrapper
    marshaller.marshal(requestObj, bout);
    String expected = "<arg0>str1 str2 str3</arg0>";

    assertTrue("The generated request wrapper class does not contain the correct annotations",
               bout.toString().contains(expected));


    bout.reset();
    marshaller.marshal(responseObj, bout);
    expected = "<return>1</return><return>2</return><return>3</return>";
    assertTrue("The generated response wrapper class is not correct", bout.toString().contains(expected));

}
 
Example 9
Source File: JaxWsServiceFactoryBeanTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testWrappedDocLit() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    Bus bus = getBus();
    bean.setBus(bus);
    bean.setServiceClass(org.apache.hello_world_doc_lit.Greeter.class);
    Service service = bean.create();

    ServiceInfo si = service.getServiceInfos().get(0);
    InterfaceInfo intf = si.getInterface();

    assertEquals(4, intf.getOperations().size());

    String ns = si.getName().getNamespaceURI();
    assertEquals("http://apache.org/hello_world_doc_lit", ns);
    OperationInfo greetMeOp = intf.getOperation(new QName(ns, "greetMe"));
    assertNotNull(greetMeOp);

    assertEquals("greetMe", greetMeOp.getInput().getName().getLocalPart());
    assertEquals("http://apache.org/hello_world_doc_lit", greetMeOp.getInput().getName()
        .getNamespaceURI());

    List<MessagePartInfo> messageParts = greetMeOp.getInput().getMessageParts();
    assertEquals(1, messageParts.size());

    MessagePartInfo inMessagePart = messageParts.get(0);
    assertEquals("http://apache.org/hello_world_doc_lit", inMessagePart.getName().getNamespaceURI());
    assertEquals("http://apache.org/hello_world_doc_lit/types", inMessagePart.getElementQName()
        .getNamespaceURI());


    // test output
    messageParts = greetMeOp.getOutput().getMessageParts();
    assertEquals(1, messageParts.size());
    assertEquals("greetMeResponse", greetMeOp.getOutput().getName().getLocalPart());

    MessagePartInfo outMessagePart = messageParts.get(0);
    //assertEquals("result", outMessagePart.getName().getLocalPart());
    assertEquals("http://apache.org/hello_world_doc_lit", outMessagePart.getName().getNamespaceURI());
    assertEquals("http://apache.org/hello_world_doc_lit/types", outMessagePart.getElementQName()
        .getNamespaceURI());


    OperationInfo greetMeOneWayOp = si.getInterface().getOperation(new QName(ns, "greetMeOneWay"));
    assertEquals(1, greetMeOneWayOp.getInput().getMessageParts().size());
    assertNull(greetMeOneWayOp.getOutput());

    Collection<SchemaInfo> schemas = si.getSchemas();
    assertEquals(1, schemas.size());
}
 
Example 10
Source File: RMEndpointTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void verifyService() {
    Service service = rme.getService(ProtocolVariation.RM10WSA200408);
    ServiceInfo si = service.getServiceInfos().get(0);
    assertNotNull("service info is null", si);

    InterfaceInfo intf = si.getInterface();

    assertEquals(8, intf.getOperations().size());

    String ns = RM10Constants.NAMESPACE_URI;
    OperationInfo oi = intf.getOperation(new QName(ns, "CreateSequence"));
    assertNotNull("No operation info.", oi);
    assertFalse("Operation is oneway.", oi.isOneWay());
    assertFalse("Operation is unwrapped.", oi.isUnwrapped());
    assertFalse("Operation is unwrappedCapable.", oi.isUnwrappedCapable());
    assertNull("Unexpected unwrapped operation.", oi.getUnwrappedOperation());

    oi = intf.getOperation(new QName(ns, "TerminateSequence"));
    assertNotNull("No operation info.", oi);
    assertTrue("Operation is toway.", oi.isOneWay());

    oi = intf.getOperation(new QName(ns, "TerminateSequenceAnonymous"));
    assertNotNull("No operation info.", oi);
    assertFalse("Operation is oneway.", oi.isOneWay());

    oi = intf.getOperation(new QName(ns, "SequenceAcknowledgement"));
    assertNotNull("No operation info.", oi);
    assertTrue("Operation is toway.", oi.isOneWay());

    oi = intf.getOperation(new QName(ns, "CloseSequence"));
    assertNotNull("No operation info.", oi);
    assertTrue("Operation is toway.", oi.isOneWay());

    oi = intf.getOperation(new QName(ns, "AckRequested"));
    assertNotNull("No operation info.", oi);
    assertTrue("Operation is toway.", oi.isOneWay());

    oi = intf.getOperation(new QName(ns, "CreateSequenceOneway"));
    assertNotNull("No operation info.", oi);
    assertTrue("Operation is toway.", oi.isOneWay());

    oi = intf.getOperation(new QName(ns, "CreateSequenceResponseOneway"));
    assertNotNull("No operation info.", oi);
    assertTrue("Operation is toway.", oi.isOneWay());
}
 
Example 11
Source File: DefaultLogEventMapper.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setServiceInfo(ServiceInfo service, LogEvent event) {
    event.setServiceName(service.getName());
    InterfaceInfo iface = service.getInterface();
    event.setPortTypeName(iface.getName());
}