Search in sources :

Example 56 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class WSDLToJavaScriptProcessor method process.

public void process() throws ToolException {
    super.process();
    ServiceInfo serviceInfo = context.get(ServiceInfo.class);
    File jsFile = getOutputFile(serviceInfo.getName().getLocalPart() + ".js");
    BasicNameManager nameManager = BasicNameManager.newNameManager(serviceInfo, null);
    NamespacePrefixAccumulator prefixManager = new NamespacePrefixAccumulator(serviceInfo.getXmlSchemaCollection());
    Map<String, String> nsPrefixMap = CastUtils.cast(context.get(ToolConstants.CFG_JSPREFIXMAP, Map.class), String.class, String.class);
    if (nsPrefixMap != null) {
        for (Map.Entry<String, String> prefixEntry : nsPrefixMap.entrySet()) {
            prefixManager.collect(prefixEntry.getValue(), prefixEntry.getKey());
        }
    }
    try {
        OutputStream outputStream = Files.newOutputStream(jsFile.toPath());
        if (null != context.get(ToolConstants.CFG_JAVASCRIPT_UTILS)) {
            JavascriptGetInterceptor.writeUtilsToResponseStream(WSDLToJavaScriptProcessor.class, outputStream);
        }
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, UTF_8);
        try (BufferedWriter writer = new BufferedWriter(outputStreamWriter)) {
            XmlSchemaCollection collection = serviceInfo.getXmlSchemaCollection().getXmlSchemaCollection();
            SchemaJavascriptBuilder jsBuilder = new SchemaJavascriptBuilder(serviceInfo.getXmlSchemaCollection(), prefixManager, nameManager);
            String jsForSchemas = jsBuilder.generateCodeForSchemaCollection(collection);
            writer.append(jsForSchemas);
            ServiceJavascriptBuilder serviceBuilder = new ServiceJavascriptBuilder(serviceInfo, null, prefixManager, nameManager);
            serviceBuilder.walk();
            String serviceJavascript = serviceBuilder.getCode();
            writer.append(serviceJavascript);
        }
    } catch (IOException e) {
        throw new ToolException(e);
    }
}
Also used : ServiceJavascriptBuilder(org.apache.cxf.javascript.service.ServiceJavascriptBuilder) OutputStream(java.io.OutputStream) IOException(java.io.IOException) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) BufferedWriter(java.io.BufferedWriter) SchemaJavascriptBuilder(org.apache.cxf.javascript.types.SchemaJavascriptBuilder) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) BasicNameManager(org.apache.cxf.javascript.BasicNameManager) OutputStreamWriter(java.io.OutputStreamWriter) ToolException(org.apache.cxf.tools.common.ToolException) NamespacePrefixAccumulator(org.apache.cxf.javascript.NamespacePrefixAccumulator) File(java.io.File) Map(java.util.Map)

Example 57 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class MAPAggregatorTest method setUpBindingOperationInfo.

private BindingOperationInfo setUpBindingOperationInfo(String nsuri, String opreq, String opresp, String opfault, Method method) {
    ServiceInfo si = new ServiceInfo();
    InterfaceInfo iinf = new InterfaceInfo(si, new QName(nsuri, method.getDeclaringClass().getSimpleName()));
    OperationInfo opInfo = iinf.addOperation(new QName(nsuri, method.getName()));
    opInfo.setProperty(Method.class.getName(), method);
    opInfo.setInput(opreq, opInfo.createMessage(new QName(nsuri, opreq), Type.INPUT));
    opInfo.setOutput(opresp, opInfo.createMessage(new QName(nsuri, opresp), Type.INPUT));
    FaultInfo finfo = opInfo.addFault(new QName(nsuri, opfault), new QName(nsuri, opfault));
    finfo.addMessagePart("fault");
    return new TestBindingOperationInfo(opInfo);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo) FaultInfo(org.apache.cxf.service.model.FaultInfo) QName(javax.xml.namespace.QName) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) Method(java.lang.reflect.Method)

Example 58 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class JettyHTTPDestinationTest method setUpDestination.

private JettyHTTPDestination setUpDestination(boolean contextMatchOnStem, boolean mockedBus) throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    transportFactory = new HTTPTransportFactory();
    final ConduitInitiator ci = new ConduitInitiator() {

        public Conduit getConduit(EndpointInfo targetInfo, Bus b) throws IOException {
            return decoupledBackChannel;
        }

        public Conduit getConduit(EndpointInfo localInfo, EndpointReferenceType target, Bus b) throws IOException {
            return decoupledBackChannel;
        }

        public List<String> getTransportIds() {
            return null;
        }

        public Set<String> getUriPrefixes() {
            return new HashSet<>(Collections.singletonList("http"));
        }
    };
    ConduitInitiatorManager mgr = new ConduitInitiatorManager() {

        public void deregisterConduitInitiator(String name) {
        }

        public ConduitInitiator getConduitInitiator(String name) throws BusException {
            return null;
        }

        public ConduitInitiator getConduitInitiatorForUri(String uri) {
            return ci;
        }

        public void registerConduitInitiator(String name, ConduitInitiator factory) {
        }
    };
    if (!mockedBus) {
        bus = new ExtensionManagerBus();
        bus.setExtension(mgr, ConduitInitiatorManager.class);
    } else {
        bus = EasyMock.createMock(Bus.class);
        bus.getExtension(EndpointResolverRegistry.class);
        EasyMock.expectLastCall().andReturn(null);
        bus.getExtension(ContinuationProviderFactory.class);
        EasyMock.expectLastCall().andReturn(null).anyTimes();
        bus.getExtension(PolicyDataEngine.class);
        EasyMock.expectLastCall().andReturn(null).anyTimes();
        bus.hasExtensionByName("org.apache.cxf.ws.policy.PolicyEngine");
        EasyMock.expectLastCall().andReturn(false);
        bus.getExtension(ClassLoader.class);
        EasyMock.expectLastCall().andReturn(this.getClass().getClassLoader());
        EasyMock.replay(bus);
    }
    engine = EasyMock.createNiceMock(JettyHTTPServerEngine.class);
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    endpointInfo = new EndpointInfo(serviceInfo, "");
    endpointInfo.setName(new QName("bla", "Port"));
    endpointInfo.setAddress(NOWHERE + "bar/foo");
    endpointInfo.addExtensor(policy);
    engine.addServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")), EasyMock.isA(JettyHTTPHandler.class));
    EasyMock.expectLastCall();
    engine.getContinuationsEnabled();
    EasyMock.expectLastCall().andReturn(true);
    EasyMock.replay(engine);
    JettyHTTPDestination dest = new EasyMockJettyHTTPDestination(bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    dest.retrieveEngine();
    policy = dest.getServer();
    observer = new MessageObserver() {

        public void onMessage(Message m) {
            inMessage = m;
            threadDefaultBus = BusFactory.getThreadDefaultBus();
        }
    };
    dest.setMessageObserver(observer);
    return dest;
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HashSet(java.util.HashSet)

Example 59 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class JettyHTTPDestinationTest method testGetMultiple.

@Test
public void testGetMultiple() throws Exception {
    bus = BusFactory.getDefaultBus(true);
    transportFactory = new HTTPTransportFactory();
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    EndpointInfo ei = new EndpointInfo(serviceInfo, "");
    ei.setName(new QName("bla", "Port"));
    ei.setAddress("http://foo");
    Destination d1 = transportFactory.getDestination(ei, bus);
    Destination d2 = transportFactory.getDestination(ei, bus);
    // Second get should not generate a new destination. It should just retrieve the existing one
    assertEquals(d1, d2);
    d2.shutdown();
    Destination d3 = transportFactory.getDestination(ei, bus);
    // Now a new destination should have been created
    assertNotSame(d1, d3);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) Test(org.junit.Test)

Example 60 with ServiceInfo

use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.

the class JettyHTTPDestinationTest method testServerPolicyInServiceModel.

@Test
public void testServerPolicyInServiceModel() throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    bus = BusFactory.getDefaultBus(true);
    transportFactory = new HTTPTransportFactory();
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    endpointInfo = new EndpointInfo(serviceInfo, "");
    endpointInfo.setName(new QName("bla", "Port"));
    endpointInfo.addExtensor(policy);
    engine = EasyMock.createMock(JettyHTTPServerEngine.class);
    EasyMock.replay();
    endpointInfo.setAddress(NOWHERE + "bar/foo");
    JettyHTTPDestination dest = new EasyMockJettyHTTPDestination(bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    assertEquals(policy, dest.getServer());
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) Test(org.junit.Test)

Aggregations

ServiceInfo (org.apache.cxf.service.model.ServiceInfo)195 QName (javax.xml.namespace.QName)89 Test (org.junit.Test)76 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)63 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)47 BindingInfo (org.apache.cxf.service.model.BindingInfo)43 OperationInfo (org.apache.cxf.service.model.OperationInfo)37 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)36 Service (org.apache.cxf.service.Service)33 Endpoint (org.apache.cxf.endpoint.Endpoint)31 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)29 File (java.io.File)28 ArrayList (java.util.ArrayList)27 Bus (org.apache.cxf.Bus)26 InputStream (java.io.InputStream)23 Definition (javax.wsdl.Definition)20 Method (java.lang.reflect.Method)16 SchemaCollection (org.apache.cxf.common.xmlschema.SchemaCollection)15 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)15 IOException (java.io.IOException)12