Search in sources :

Example 1 with WSDLGetUtils

use of org.apache.cxf.frontend.WSDLGetUtils in project cxf by apache.

the class MEXUtils method getSchemas.

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<Element>();
    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;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) Element(org.w3c.dom.Element) WSDLGetUtils(org.apache.cxf.frontend.WSDLGetUtils) Map(java.util.Map) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList)

Example 2 with WSDLGetUtils

use of org.apache.cxf.frontend.WSDLGetUtils 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();
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Server(org.apache.cxf.endpoint.Server) Message(org.apache.cxf.message.Message) WSDLGetUtils(org.apache.cxf.frontend.WSDLGetUtils) Document(org.w3c.dom.Document) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 3 with WSDLGetUtils

use of org.apache.cxf.frontend.WSDLGetUtils in project cxf by apache.

the class EndpointImpl method doPublish.

/**
 * Performs the publication action by setting up a {@link Server}
 * instance based on this endpoint's configuration.
 *
 * @param addr the optional endpoint address.
 *
 * @throws IllegalStateException if the endpoint cannot be published/republished
 * @throws SecurityException if permission checking is enabled and policy forbids publishing
 * @throws WebServiceException if there is an error publishing the endpoint
 *
 * @see #checkPublishPermission()
 * @see #checkPublishable()
 * @see #getServer(String)
 */
protected void doPublish(String addr) {
    checkPublishPermission();
    checkPublishable();
    ServerImpl serv = null;
    ClassLoaderHolder loader = null;
    try {
        if (bus != null) {
            ClassLoader newLoader = bus.getExtension(ClassLoader.class);
            if (newLoader != null) {
                loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
            }
        }
        serv = getServer(addr);
        if (addr != null) {
            EndpointInfo endpointInfo = serv.getEndpoint().getEndpointInfo();
            if (endpointInfo.getAddress() == null || !endpointInfo.getAddress().contains(addr)) {
                endpointInfo.setAddress(addr);
            }
            if (publishedEndpointUrl != null) {
                endpointInfo.setProperty(WSDLGetUtils.PUBLISHED_ENDPOINT_URL, publishedEndpointUrl);
            }
            if (publishedEndpointUrl != null && wsdlLocation != null) {
                // early update the publishedEndpointUrl so that endpoints in the same app sharing the same wsdl
                // do not require all of them to be queried for wsdl before the wsdl is finally fully updated
                Definition def = endpointInfo.getService().getProperty(WSDLServiceBuilder.WSDL_DEFINITION, Definition.class);
                if (def == null) {
                    def = bus.getExtension(WSDLManager.class).getDefinition(wsdlLocation);
                }
                new WSDLGetUtils().updateWSDLPublishedEndpointAddress(def, endpointInfo);
            }
            if (null != properties) {
                for (Entry<String, Object> entry : properties.entrySet()) {
                    endpointInfo.setProperty(entry.getKey(), entry.getValue());
                }
            }
            this.address = endpointInfo.getAddress();
        }
        serv.start();
        publishable = false;
    } catch (Exception ex) {
        try {
            stop();
        } catch (Exception e) {
        // Nothing we can do.
        }
        throw new WebServiceException(ex);
    } finally {
        if (loader != null) {
            loader.reset();
        }
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ServerImpl(org.apache.cxf.endpoint.ServerImpl) WebServiceException(javax.xml.ws.WebServiceException) Definition(javax.wsdl.Definition) WSDLGetUtils(org.apache.cxf.frontend.WSDLGetUtils) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) WebServiceException(javax.xml.ws.WebServiceException)

Example 4 with WSDLGetUtils

use of org.apache.cxf.frontend.WSDLGetUtils in project cxf by apache.

the class MEXUtils method getWSDLs.

public static List<Element> getWSDLs(Server server) {
    Message message = PhaseInterceptorChain.getCurrentMessage();
    message.put(WSDLGetUtils.AUTO_REWRITE_ADDRESS_ALL, true);
    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();
    List<Element> ret = new LinkedList<Element>();
    for (String id : utils.getWSDLIds(message, base, ctxUri, info)) {
        Map<String, String> params = new HashMap<>();
        params.put("wsdl", id);
        ret.add(utils.getDocument(message, base, params, ctxUri, info).getDocumentElement());
    }
    return ret;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) WSDLGetUtils(org.apache.cxf.frontend.WSDLGetUtils) LinkedList(java.util.LinkedList)

Example 5 with WSDLGetUtils

use of org.apache.cxf.frontend.WSDLGetUtils in project cxf by apache.

the class MEXUtils method getSchemaLocations.

public static Map<String, String> getSchemaLocations(Server server) {
    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();
    return utils.getSchemaLocations(message, base, ctxUri, info);
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Message(org.apache.cxf.message.Message) WSDLGetUtils(org.apache.cxf.frontend.WSDLGetUtils)

Aggregations

WSDLGetUtils (org.apache.cxf.frontend.WSDLGetUtils)5 Message (org.apache.cxf.message.Message)4 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)4 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Element (org.w3c.dom.Element)2 Map (java.util.Map)1 Definition (javax.wsdl.Definition)1 WebServiceException (javax.xml.ws.WebServiceException)1 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)1 Server (org.apache.cxf.endpoint.Server)1 ServerImpl (org.apache.cxf.endpoint.ServerImpl)1 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)1 Exchange (org.apache.cxf.message.Exchange)1 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)1 MessageImpl (org.apache.cxf.message.MessageImpl)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1