Search in sources :

Example 1 with Receiver

use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.

the class WsdlGeneratorPipe method doPipe.

@Override
public PipeRunResult doPipe(Message message, PipeLineSession session) throws PipeRunException {
    Message fileInSession = session.getMessage(getSessionKey());
    if (fileInSession == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null value from session under key [" + getSessionKey() + "]");
    }
    File tempDir;
    String fileName;
    try (InputStream inputStream = fileInSession.asInputStream()) {
        tempDir = FileUtils.createTempDir(null, "WEB-INF" + File.separator + "classes");
        fileName = session.getMessage(getFilenameSessionKey()).asString();
        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 {
        // A DirectoryClassloader is used to create a new 'dummy' pipeline, see createPipeLineFromPropertiesFile(String)
        // This method reads a properties file and xsd's (when present) to programmatically 'create' a pipeline.
        // The pipeline will then be used to generate a new WSDL file.
        DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(originalClassLoader);
        directoryClassLoader.setDirectory(tempDir.getPath());
        directoryClassLoader.setBasePath(".");
        directoryClassLoader.configure(getAdapter().getConfiguration().getIbisManager().getIbisContext(), "dummy");
        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();
        Configuration configuration = new Configuration();
        configuration.setClassLoader(getConfigurationClassLoader());
        adapter.setConfiguration(configuration);
        String fileBaseName = FileUtils.getBaseName(fileName).replaceAll(" ", "_");
        adapter.setName(fileBaseName);
        Receiver receiver = new Receiver();
        EsbJmsListener esbJmsListener = new EsbJmsListener();
        esbJmsListener.setQueueConnectionFactoryName("jms/qcf_" + fileBaseName);
        esbJmsListener.setDestinationName("jms/dest_" + fileBaseName);
        receiver.setListener(esbJmsListener);
        adapter.registerReceiver(receiver);
        adapter.setPipeLine(pipeLine);
        WsdlGenerator wsdl = null;
        String generationInfo = "at " + RestListenerUtils.retrieveRequestURL(session);
        wsdl = new WsdlGenerator(pipeLine, generationInfo);
        wsdl.setIndent(true);
        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(getSuccessForward(), result);
}
Also used : Dir2Xml(nl.nn.adapterframework.util.Dir2Xml) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) Message(nl.nn.adapterframework.stream.Message) Configuration(nl.nn.adapterframework.configuration.Configuration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Receiver(nl.nn.adapterframework.receivers.Receiver) Adapter(nl.nn.adapterframework.core.Adapter) IOException(java.io.IOException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) 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) WsdlGenerator(nl.nn.adapterframework.soap.WsdlGenerator)

Example 2 with Receiver

use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.

the class FxfListener method warn.

private void warn(String msg, Throwable t) {
    log.warn(msg, t);
    Receiver receiver = getReceiver();
    if (receiver != null) {
        IAdapter iAdapter = receiver.getAdapter();
        if (iAdapter != null) {
            iAdapter.getMessageKeeper().add("WARNING: " + msg + (t != null ? ": " + t.getMessage() : ""), MessageKeeperLevel.WARN);
        }
    }
}
Also used : Receiver(nl.nn.adapterframework.receivers.Receiver) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 3 with Receiver

use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.

the class Webservices method getWebServices.

@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/webservices")
@Relation("webservices")
@Produces(MediaType.APPLICATION_JSON)
public Response getWebServices() throws ApiException {
    Map<String, Object> returnMap = new HashMap<String, Object>();
    List<Map<String, Object>> webServices = new ArrayList<Map<String, Object>>();
    for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
        for (Receiver receiver : adapter.getReceivers()) {
            IListener listener = receiver.getListener();
            if (listener instanceof RestListener) {
                RestListener rl = (RestListener) listener;
                Map<String, Object> service = new HashMap<String, Object>();
                service.put("name", adapter.getName() + " " + receiver.getName());
                service.put("method", rl.getMethod());
                service.put("view", rl.isView());
                service.put("uriPattern", rl.getUriPattern());
                webServices.add(service);
            }
        }
    }
    returnMap.put("services", webServices);
    List<Map<String, Object>> wsdls = new ArrayList<Map<String, Object>>();
    for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
        Map<String, Object> wsdlMap = null;
        try {
            if (WsdlGeneratorUtils.canProvideWSDL(adapter)) {
                // check eligibility
                wsdlMap = new HashMap<String, Object>(2);
                WsdlGenerator wsdl = new WsdlGenerator(adapter.getPipeLine());
                wsdlMap.put("name", wsdl.getName());
                wsdlMap.put("extension", getWsdlExtension());
            }
        } catch (Exception e) {
            wsdlMap.put("name", adapter.getName());
            if (e.getMessage() != null) {
                wsdlMap.put("error", e.getMessage());
            } else {
                wsdlMap.put("error", e.toString());
            }
        }
        if (wsdlMap != null) {
            wsdls.add(wsdlMap);
        }
    }
    returnMap.put("wsdls", wsdls);
    // ApiListeners
    List<Map<String, Object>> apiListeners = new LinkedList<Map<String, Object>>();
    SortedMap<String, ApiDispatchConfig> patternClients = ApiServiceDispatcher.getInstance().getPatternClients();
    for (Entry<String, ApiDispatchConfig> client : patternClients.entrySet()) {
        ApiDispatchConfig config = client.getValue();
        Set<HttpMethod> methods = config.getMethods();
        for (HttpMethod method : methods) {
            ApiListener listener = config.getApiListener(method);
            Receiver receiver = listener.getReceiver();
            IAdapter adapter = receiver == null ? null : receiver.getAdapter();
            Map<String, Object> endpoint = new HashMap<>();
            String uriPattern = listener.getUriPattern();
            endpoint.put("uriPattern", uriPattern);
            endpoint.put("method", method);
            if (adapter != null)
                endpoint.put("adapter", adapter.getName());
            if (receiver != null)
                endpoint.put("receiver", receiver.getName());
            String schemaResource = uriPattern.substring(1).replace("/", "_") + "_" + method + "_" + "openapi.json";
            endpoint.put("schemaResource", schemaResource);
            apiListeners.add(endpoint);
        }
    }
    returnMap.put("apiListeners", apiListeners);
    return Response.status(Response.Status.OK).entity(returnMap).build();
}
Also used : HashMap(java.util.HashMap) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Receiver(nl.nn.adapterframework.receivers.Receiver) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) NamingException(javax.naming.NamingException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) WebApplicationException(javax.ws.rs.WebApplicationException) LinkedList(java.util.LinkedList) RestListener(nl.nn.adapterframework.http.RestListener) ApiListener(nl.nn.adapterframework.http.rest.ApiListener) ApiDispatchConfig(nl.nn.adapterframework.http.rest.ApiDispatchConfig) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) WsdlGenerator(nl.nn.adapterframework.soap.WsdlGenerator) IAdapter(nl.nn.adapterframework.core.IAdapter) HttpMethod(nl.nn.adapterframework.http.rest.ApiListener.HttpMethod) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with Receiver

use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.

the class Webservices method getServiceEndpoint.

private String getServiceEndpoint(IAdapter adapter) {
    String endpoint = "external address of ibis";
    Iterator it = adapter.getReceivers().iterator();
    while (it.hasNext()) {
        IListener listener = ((Receiver) it.next()).getListener();
        if (listener instanceof WebServiceListener) {
            String address = ((WebServiceListener) listener).getAddress();
            if (StringUtils.isNotEmpty(address)) {
                endpoint = address;
            } else {
                endpoint = "rpcrouter";
            }
            String protocol = request.isSecure() ? "https://" : "http://";
            int port = request.getServerPort();
            String restBaseUrl = protocol + request.getServerName() + (port != 0 ? ":" + port : "") + request.getContextPath() + "/services/";
            endpoint = restBaseUrl + endpoint;
            // what if there are more than 1 WebServiceListener
            break;
        }
    }
    return endpoint;
}
Also used : IListener(nl.nn.adapterframework.core.IListener) Iterator(java.util.Iterator) Receiver(nl.nn.adapterframework.receivers.Receiver) WebServiceListener(nl.nn.adapterframework.http.WebServiceListener)

Example 5 with Receiver

use of nl.nn.adapterframework.receivers.Receiver in project iaf by ibissource.

the class SlotIdRecord method getSlotmap.

private Map<String, SlotIdRecord> getSlotmap() {
    Map<String, SlotIdRecord> slotmap = new HashMap<String, SlotIdRecord>();
    for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
        for (Receiver receiver : adapter.getReceivers()) {
            ITransactionalStorage errorStorage = receiver.getErrorStorage();
            if (errorStorage != null) {
                String slotId = errorStorage.getSlotId();
                if (StringUtils.isNotEmpty(slotId)) {
                    SlotIdRecord sir = new SlotIdRecord(adapter.getName(), receiver.getName(), null);
                    String type = errorStorage.getType();
                    slotmap.put(type + "/" + slotId, sir);
                }
            }
            ITransactionalStorage messageLog = receiver.getMessageLog();
            if (messageLog != null) {
                String slotId = messageLog.getSlotId();
                if (StringUtils.isNotEmpty(slotId)) {
                    SlotIdRecord sir = new SlotIdRecord(adapter.getName(), receiver.getName(), null);
                    String type = messageLog.getType();
                    slotmap.put(type + "/" + slotId, sir);
                }
            }
        }
        PipeLine pipeline = adapter.getPipeLine();
        if (pipeline != null) {
            for (int i = 0; i < pipeline.getPipeLineSize(); i++) {
                IPipe pipe = pipeline.getPipe(i);
                if (pipe instanceof MessageSendingPipe) {
                    MessageSendingPipe msp = (MessageSendingPipe) pipe;
                    ITransactionalStorage messageLog = msp.getMessageLog();
                    if (messageLog != null) {
                        String slotId = messageLog.getSlotId();
                        if (StringUtils.isNotEmpty(slotId)) {
                            SlotIdRecord sir = new SlotIdRecord(adapter.getName(), null, msp.getName());
                            String type = messageLog.getType();
                            slotmap.put(type + "/" + slotId, sir);
                            slotmap.put(slotId, sir);
                        }
                    }
                }
            }
        }
    }
    return slotmap;
}
Also used : MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Receiver(nl.nn.adapterframework.receivers.Receiver) Adapter(nl.nn.adapterframework.core.Adapter) PipeLine(nl.nn.adapterframework.core.PipeLine) IPipe(nl.nn.adapterframework.core.IPipe) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage)

Aggregations

Receiver (nl.nn.adapterframework.receivers.Receiver)7 Adapter (nl.nn.adapterframework.core.Adapter)4 HashMap (java.util.HashMap)3 Configuration (nl.nn.adapterframework.configuration.Configuration)3 PipeLine (nl.nn.adapterframework.core.PipeLine)3 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 IAdapter (nl.nn.adapterframework.core.IAdapter)2 IListener (nl.nn.adapterframework.core.IListener)2 WebServiceListener (nl.nn.adapterframework.http.WebServiceListener)2 WsdlGenerator (nl.nn.adapterframework.soap.WsdlGenerator)2 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 Date (java.util.Date)1 Iterator (java.util.Iterator)1