Search in sources :

Example 1 with Wsdl

use of nl.nn.adapterframework.soap.Wsdl in project iaf by ibissource.

the class Webservices method getLogDirectory.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/webservices")
@Relation("webservices")
@Produces(MediaType.APPLICATION_JSON)
public Response getLogDirectory() throws ApiException {
    initBase(servletConfig);
    Map<String, Object> returnMap = new HashMap<String, Object>();
    List<Map<String, Object>> webServices = new ArrayList<Map<String, Object>>();
    for (IAdapter a : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) a;
        Iterator<IReceiver> recIt = adapter.getReceiverIterator();
        while (recIt.hasNext()) {
            IReceiver receiver = recIt.next();
            if (receiver instanceof ReceiverBase) {
                ReceiverBase rb = (ReceiverBase) receiver;
                IListener listener = rb.getListener();
                if (listener instanceof RestListener) {
                    RestListener rl = (RestListener) listener;
                    if (rl.isView()) {
                        Map<String, Object> service = new HashMap<String, Object>(2);
                        service.put("name", rb.getName());
                        service.put("uriPattern", rl.getUriPattern());
                        webServices.add(service);
                    }
                }
            }
        }
    }
    returnMap.put("services", webServices);
    List<Map<String, Object>> wsdls = new ArrayList<Map<String, Object>>();
    for (IAdapter a : ibisManager.getRegisteredAdapters()) {
        Map<String, Object> wsdlMap = new HashMap<String, Object>(2);
        try {
            Adapter adapter = (Adapter) a;
            Wsdl wsdl = new Wsdl(adapter.getPipeLine());
            wsdlMap.put("name", wsdl.getName());
            wsdlMap.put("extention", getWsdlExtention());
        } catch (Exception e) {
            wsdlMap.put("name", a.getName());
            if (e.getMessage() != null) {
                wsdlMap.put("error", e.getMessage());
            } else {
                wsdlMap.put("error", e.toString());
            }
        }
        wsdls.add(wsdlMap);
    }
    returnMap.put("wsdls", wsdls);
    return Response.status(Response.Status.OK).entity(returnMap).build();
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) HashMap(java.util.HashMap) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) Wsdl(nl.nn.adapterframework.soap.Wsdl) RestListener(nl.nn.adapterframework.http.RestListener) IReceiver(nl.nn.adapterframework.core.IReceiver) HashMap(java.util.HashMap) Map(java.util.Map) IAdapter(nl.nn.adapterframework.core.IAdapter) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Wsdl

use of nl.nn.adapterframework.soap.Wsdl in project iaf by ibissource.

the class WsdlGeneratorPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String result = null;
    IAdapter adapter;
    if ("input".equals(getFrom())) {
        adapter = ((Adapter) getAdapter()).getConfiguration().getIbisManager().getRegisteredAdapter((String) input);
        if (adapter == null) {
            throw new PipeRunException(this, "Could not find adapter: " + input);
        }
    } else {
        adapter = getPipeLine().getAdapter();
    }
    try {
        Wsdl wsdl = new Wsdl(((Adapter) adapter).getPipeLine());
        wsdl.setDocumentation("Generated at " + AppConstants.getInstance().getResolvedProperty("otap.stage") + "-" + AppConstants.getInstance().getResolvedProperty("otap.side") + " on " + DateUtils.getIsoTimeStamp() + ".");
        wsdl.init();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        wsdl.wsdl(outputStream, null);
        result = outputStream.toString("UTF-8");
    } catch (Exception e) {
        throw new PipeRunException(this, "Could not generate WSDL for adapter '" + adapter.getName() + "'", e);
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAdapter(nl.nn.adapterframework.core.IAdapter) Wsdl(nl.nn.adapterframework.soap.Wsdl) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 3 with Wsdl

use of nl.nn.adapterframework.soap.Wsdl in project iaf by ibissource.

the class WsdlGeneratorPipe method doPipe.

@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    InputStream inputStream = (InputStream) session.get("file");
    if (inputStream == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null value from session under key [" + getSessionKey() + "]");
    }
    File tempDir;
    String fileName;
    try {
        tempDir = FileUtils.createTempDir(null, "WEB-INF" + File.separator + "classes");
        fileName = (String) session.get("fileName");
        if (FileUtils.extensionEqualsIgnoreCase(fileName, "zip")) {
            FileUtils.unzipStream(inputStream, tempDir);
        } else {
            File file = new File(tempDir, fileName);
            Misc.streamToFile(inputStream, file);
            file.deleteOnExit();
        }
    } catch (IOException e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on uploading and unzipping/writing file", e);
    }
    File propertiesFile = new File(tempDir, getPropertiesFileName());
    PipeLine pipeLine;
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(tempDir.getPath());
        Thread.currentThread().setContextClassLoader(directoryClassLoader);
        if (propertiesFile.exists()) {
            pipeLine = createPipeLineFromPropertiesFile(propertiesFile);
        } else {
            File xsdFile = FileUtils.getFirstFile(tempDir);
            pipeLine = createPipeLineFromXsdFile(xsdFile);
        }
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
    } finally {
        if (originalClassLoader != null) {
            Thread.currentThread().setContextClassLoader(originalClassLoader);
        }
    }
    Object result = null;
    OutputStream zipOut = null;
    OutputStream fullWsdlOut = null;
    try {
        Adapter adapter = new Adapter();
        adapter.setConfiguration(new Configuration(null));
        String fileBaseName = FileUtils.getBaseName(fileName).replaceAll(" ", "_");
        adapter.setName(fileBaseName);
        GenericReceiver genericReceiver = new GenericReceiver();
        EsbJmsListener esbJmsListener = new EsbJmsListener();
        esbJmsListener.setQueueConnectionFactoryName("jms/qcf_" + fileBaseName);
        esbJmsListener.setDestinationName("jms/dest_" + fileBaseName);
        genericReceiver.setListener(esbJmsListener);
        adapter.registerReceiver(genericReceiver);
        pipeLine.setAdapter(adapter);
        Wsdl wsdl = null;
        wsdl = new Wsdl(pipeLine);
        wsdl.setIndent(true);
        wsdl.setDocumentation(getWsdlDocumentation(wsdl.getFilename()));
        wsdl.init();
        File wsdlDir = FileUtils.createTempDir(tempDir);
        // zip (with includes)
        File zipOutFile = new File(wsdlDir, wsdl.getFilename() + ".zip");
        zipOutFile.deleteOnExit();
        zipOut = new FileOutputStream(zipOutFile);
        wsdl.setUseIncludes(true);
        wsdl.zip(zipOut, null);
        // full wsdl (without includes)
        File fullWsdlOutFile = new File(wsdlDir, wsdl.getFilename() + ".wsdl");
        fullWsdlOutFile.deleteOnExit();
        fullWsdlOut = new FileOutputStream(fullWsdlOutFile);
        wsdl.setUseIncludes(false);
        wsdl.wsdl(fullWsdlOut, null);
        Dir2Xml dx = new Dir2Xml();
        dx.setPath(wsdlDir.getPath());
        result = dx.getDirList();
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
    } finally {
        try {
            if (zipOut != null) {
                zipOut.close();
            }
            if (fullWsdlOut != null) {
                fullWsdlOut.close();
            }
        } catch (IOException e1) {
            log.warn("exception closing outputstream", e1);
        }
    }
    return new PipeRunResult(getForward(), result);
}
Also used : Dir2Xml(nl.nn.adapterframework.util.Dir2Xml) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) Configuration(nl.nn.adapterframework.configuration.Configuration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Adapter(nl.nn.adapterframework.core.Adapter) IOException(java.io.IOException) Wsdl(nl.nn.adapterframework.soap.Wsdl) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) GenericReceiver(nl.nn.adapterframework.receivers.GenericReceiver) FileOutputStream(java.io.FileOutputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) PipeLine(nl.nn.adapterframework.core.PipeLine) File(java.io.File)

Example 4 with Wsdl

use of nl.nn.adapterframework.soap.Wsdl in project iaf by ibissource.

the class Webservices method zip.

private void zip(Adapter adapter, IPipeLineSession session) throws ConfigurationException, XMLStreamException, IOException, NamingException {
    Wsdl wsdl = new Wsdl(adapter.getPipeLine());
    wsdl.setUseIncludes(true);
    wsdl.setDocumentation(getDocumentation(wsdl, session));
    wsdl.init();
    wsdl.zip(RestListenerUtils.retrieveServletOutputStream(session), RestListenerUtils.retrieveSOAPRequestURL(session));
}
Also used : Wsdl(nl.nn.adapterframework.soap.Wsdl)

Example 5 with Wsdl

use of nl.nn.adapterframework.soap.Wsdl in project iaf by ibissource.

the class Webservices method wsdl.

private void wsdl(Adapter adapter, IPipeLineSession session, String indent, String useIncludes) throws ConfigurationException, XMLStreamException, IOException, NamingException {
    Wsdl wsdl = new Wsdl(adapter.getPipeLine());
    if (indent != null) {
        wsdl.setIndent(StringUtils.equalsIgnoreCase(indent, "true"));
    }
    if (useIncludes != null) {
        wsdl.setUseIncludes(StringUtils.equalsIgnoreCase(useIncludes, "true"));
    }
    wsdl.setDocumentation(getDocumentation(wsdl, session));
    wsdl.init();
    wsdl.wsdl(RestListenerUtils.retrieveServletOutputStream(session), RestListenerUtils.retrieveSOAPRequestURL(session));
}
Also used : Wsdl(nl.nn.adapterframework.soap.Wsdl)

Aggregations

Wsdl (nl.nn.adapterframework.soap.Wsdl)6 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)3 Adapter (nl.nn.adapterframework.core.Adapter)3 IAdapter (nl.nn.adapterframework.core.IAdapter)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 IOException (java.io.IOException)2 IListener (nl.nn.adapterframework.core.IListener)2 IReceiver (nl.nn.adapterframework.core.IReceiver)2 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)2 RestListener (nl.nn.adapterframework.http.RestListener)2 ReceiverBase (nl.nn.adapterframework.receivers.ReceiverBase)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1