Search in sources :

Example 1 with URI

use of org.apache.axis2.databinding.types.URI in project wso2-axis2-transports by wso2.

the class AxisTestEndpoint method setUp.

@Setup
@SuppressWarnings("unused")
private void setUp(LogManager logManager, AxisTestEndpointContext context, Channel channel, AxisServiceConfigurator[] configurators) throws Exception {
    this.context = context;
    TransportListener listener = context.getTransportListener();
    if (listener instanceof TransportErrorSource) {
        transportErrorSource = (TransportErrorSource) listener;
        errorListener = new TransportErrorListener() {

            public void error(TransportError error) {
                AxisService s = error.getService();
                if (s == null || s == service) {
                    onTransportError(error.getException());
                }
            }
        };
        transportErrorSource.addErrorListener(errorListener);
    } else {
        transportErrorSource = null;
    }
    String path;
    try {
        path = new URI(channel.getEndpointReference().getAddress()).getPath();
    } catch (URISyntaxException ex) {
        path = null;
    }
    String serviceName;
    if (path != null && path.startsWith(Channel.CONTEXT_PATH + "/")) {
        serviceName = path.substring(Channel.CONTEXT_PATH.length() + 1);
    } else {
        serviceName = "TestService-" + UUID.randomUUID();
    }
    service = new AxisService(serviceName);
    service.addOperation(createOperation());
    if (configurators != null) {
        for (AxisServiceConfigurator configurator : configurators) {
            configurator.setupService(service, false);
        }
    }
    // Output service parameters to log file
    // FIXME: This actually doesn't give the expected result because the AxisTestEndpoint might be reused
    // by several test cases and in that case the log file is only produced once
    List<Parameter> params = (List<Parameter>) service.getParameters();
    if (!params.isEmpty()) {
        PrintWriter log = new PrintWriter(logManager.createLog("service-parameters"), false);
        try {
            for (Parameter param : params) {
                log.print(param.getName());
                log.print("=");
                log.println(param.getValue());
            }
        } finally {
            log.close();
        }
    }
    // We want to receive all messages through the same operation:
    service.addParameter(AxisService.SUPPORT_SINGLE_OP, true);
    context.getAxisConfiguration().addService(service);
    // The transport may disable the service. In that case, fail directly.
    if (!BaseUtils.isUsingTransport(service, context.getTransportName())) {
        Assert.fail("The service has been disabled by the transport");
    }
}
Also used : TransportError(org.apache.axis2.transport.base.event.TransportError) AxisServiceConfigurator(org.apache.axis2.transport.testkit.axis2.AxisServiceConfigurator) AxisService(org.apache.axis2.description.AxisService) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) TransportErrorSource(org.apache.axis2.transport.base.event.TransportErrorSource) TransportListener(org.apache.axis2.transport.TransportListener) TransportErrorListener(org.apache.axis2.transport.base.event.TransportErrorListener) Parameter(org.apache.axis2.description.Parameter) List(java.util.List) PrintWriter(java.io.PrintWriter) Setup(org.apache.axis2.transport.testkit.tests.Setup)

Example 2 with URI

use of org.apache.axis2.databinding.types.URI in project wso2-synapse by wso2.

the class VFSTransportListener method scanFileOrDirectory.

/**
 * Search for files that match the given regex pattern and create a list
 * Then process each of these files and update the status of the scan on
 * the poll table
 * @param entry the poll table entry for the scan
 * @param fileURI the file or directory to be scanned
 */
private void scanFileOrDirectory(final PollTableEntry entry, String fileURI) {
    if (log.isDebugEnabled()) {
        log.debug("Polling: " + VFSUtils.maskURLPassword(fileURI));
    }
    if (entry.isClusterAware()) {
        boolean leader = true;
        ClusteringAgent agent = getConfigurationContext().getAxisConfiguration().getClusteringAgent();
        if (agent != null && agent.getParameter("domain") != null) {
            // hazelcast clustering instance name
            String hazelcastInstanceName = agent.getParameter("domain").getValue() + ".instance";
            HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(hazelcastInstanceName);
            if (instance != null) {
                // dirty leader election
                leader = instance.getCluster().getMembers().iterator().next().localMember();
            } else {
                log.warn("Clustering error, running the polling task in this node");
            }
        } else {
            log.warn("Although proxy is cluster aware, clustering config are not present, hence running the" + " the polling task in this node");
        }
        if (!leader) {
            if (log.isDebugEnabled()) {
                log.debug("This Member is not the leader");
            }
            entry.setLastPollState(PollTableEntry.NONE);
            long now = System.currentTimeMillis();
            entry.setLastPollTime(now);
            entry.setNextPollTime(now + entry.getPollInterval());
            onPollCompletion(entry);
            return;
        }
        if (log.isDebugEnabled()) {
            log.debug("This Member is the leader");
        }
    }
    FileSystemOptions fso = null;
    setFileSystemClosed(false);
    try {
        fso = VFSUtils.attachFileSystemOptions(entry.getVfsSchemeProperties(), fsManager);
    } catch (Exception e) {
        log.error("Error while attaching VFS file system properties. " + e.getMessage());
    }
    FileObject fileObject = null;
    // TODO : Trying to make the correct URL out of the malformed one.
    if (fileURI.contains("vfs:")) {
        fileURI = fileURI.substring(fileURI.indexOf("vfs:") + 4);
    }
    if (log.isDebugEnabled()) {
        log.debug("Scanning directory or file : " + VFSUtils.maskURLPassword(fileURI));
    }
    boolean wasError = true;
    int retryCount = 0;
    int maxRetryCount = entry.getMaxRetryCount();
    long reconnectionTimeout = entry.getReconnectTimeout();
    while (wasError) {
        try {
            retryCount++;
            fileObject = fsManager.resolveFile(fileURI, fso);
            if (fileObject == null) {
                log.error("fileObject is null");
                throw new FileSystemException("fileObject is null");
            }
            wasError = false;
        } catch (FileSystemException e) {
            if (retryCount >= maxRetryCount) {
                processFailure("Repeatedly failed to resolve the file URI: " + VFSUtils.maskURLPassword(fileURI), e, entry);
                closeFileSystem(fileObject);
                return;
            } else {
                log.warn("Failed to resolve the file URI: " + VFSUtils.maskURLPassword(fileURI) + ", in attempt " + retryCount + ", " + e.getMessage() + " Retrying in " + reconnectionTimeout + " milliseconds.");
            }
        }
        if (wasError) {
            try {
                Thread.sleep(reconnectionTimeout);
            } catch (InterruptedException e2) {
                log.error("Thread was interrupted while waiting to reconnect.", e2);
            }
        }
    }
    try {
        if (fileObject.exists() && fileObject.isReadable()) {
            entry.setLastPollState(PollTableEntry.NONE);
            FileObject[] children = null;
            try {
                children = fileObject.getChildren();
            } catch (FileNotFolderException ignored) {
            } catch (FileSystemException ex) {
                log.error(ex.getMessage(), ex);
            }
            // if this is a file that would translate to a single message
            if (children == null || children.length == 0) {
                boolean isFailedRecord = false;
                if (entry.getMoveAfterMoveFailure() != null) {
                    isFailedRecord = isFailedRecord(fileObject, entry);
                }
                if (fileObject.getType() == FileType.FILE && !isFailedRecord) {
                    boolean runPostProcess = true;
                    if (!entry.isFileLockingEnabled() || (entry.isFileLockingEnabled() && acquireLock(fsManager, fileObject, entry, fso, true))) {
                        try {
                            if (fileObject.getType() == FileType.FILE) {
                                processFile(entry, fileObject);
                                entry.setLastPollState(PollTableEntry.SUCCSESSFUL);
                                metrics.incrementMessagesReceived();
                            } else {
                                runPostProcess = false;
                            }
                        } catch (AxisFault e) {
                            if (e.getCause() instanceof FileNotFoundException) {
                                log.warn("Error processing File URI : " + VFSUtils.maskURLPassword(fileObject.getName().toString()) + ". This can be due to file moved from another process.");
                                runPostProcess = false;
                            } else {
                                logException("Error processing File URI : " + VFSUtils.maskURLPassword(fileObject.getName().getURI()), e);
                                entry.setLastPollState(PollTableEntry.FAILED);
                                metrics.incrementFaultsReceiving();
                            }
                        }
                        if (runPostProcess) {
                            try {
                                moveOrDeleteAfterProcessing(entry, fileObject, fso);
                            } catch (AxisFault axisFault) {
                                logException("File object '" + VFSUtils.maskURLPassword(fileObject.getURL().toString()) + "' " + "cloud not be moved", axisFault);
                                entry.setLastPollState(PollTableEntry.FAILED);
                                String timeStamp = VFSUtils.getSystemTime(entry.getFailedRecordTimestampFormat());
                                addFailedRecord(entry, fileObject, timeStamp);
                            }
                        }
                        if (entry.isFileLockingEnabled()) {
                            VFSUtils.releaseLock(fsManager, fileObject, fso);
                            if (log.isDebugEnabled()) {
                                log.debug("Removed the lock file '" + VFSUtils.maskURLPassword(fileObject.toString()) + ".lock' of the file '" + VFSUtils.maskURLPassword(fileObject.toString()));
                            }
                        }
                    } else if (log.isDebugEnabled()) {
                        log.debug("Couldn't get the lock for processing the file : " + VFSUtils.maskURLPassword(fileObject.getName().getURI()));
                    } else if (isFailedRecord) {
                        if (entry.isFileLockingEnabled()) {
                            VFSUtils.releaseLock(fsManager, fileObject, fso);
                        }
                        // schedule a cleanup task if the file is there
                        if (fsManager.resolveFile(fileObject.getURL().toString(), fso) != null && removeTaskState == STATE_STOPPED && entry.getMoveAfterMoveFailure() != null) {
                            workerPool.execute(new FileRemoveTask(entry, fileObject, fso));
                        }
                        if (log.isDebugEnabled()) {
                            log.debug("File '" + VFSUtils.maskURLPassword(fileObject.getURL().toString()) + "' has been marked as a failed" + " record, it will not process");
                        }
                    }
                }
            } else {
                int failCount = 0;
                int successCount = 0;
                int processCount = 0;
                Integer iFileProcessingInterval = entry.getFileProcessingInterval();
                Integer iFileProcessingCount = entry.getFileProcessingCount();
                if (log.isDebugEnabled()) {
                    log.debug("File name pattern : " + entry.getFileNamePattern());
                }
                // Sort the files
                String strSortParam = entry.getFileSortParam();
                if (strSortParam != null) {
                    log.debug("Start Sorting the files.");
                    boolean bSortOrderAsscending = entry.isFileSortAscending();
                    if (log.isDebugEnabled()) {
                        log.debug("Sorting the files by : " + strSortParam + ". (" + bSortOrderAsscending + ")");
                    }
                    if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_NAME) && bSortOrderAsscending) {
                        Arrays.sort(children, new FileNameAscComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_NAME) && !bSortOrderAsscending) {
                        Arrays.sort(children, new FileNameDesComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_SIZE) && bSortOrderAsscending) {
                        Arrays.sort(children, new FileSizeAscComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_SIZE) && !bSortOrderAsscending) {
                        Arrays.sort(children, new FileSizeDesComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_LASTMODIFIEDTIMESTAMP) && bSortOrderAsscending) {
                        Arrays.sort(children, new FileLastmodifiedtimestampAscComparator());
                    } else if (strSortParam.equals(VFSConstants.FILE_SORT_VALUE_LASTMODIFIEDTIMESTAMP) && !bSortOrderAsscending) {
                        Arrays.sort(children, new FileLastmodifiedtimestampDesComparator());
                    }
                    log.debug("End Sorting the files.");
                }
                for (FileObject child : children) {
                    // Stop processing when service get undeployed
                    if (state != BaseConstants.STARTED || !entry.getService().isActive()) {
                        return;
                    }
                    /**
                     * Before starting to process another file, see whether the proxy is stopped or not.
                     */
                    if (entry.isCanceled()) {
                        break;
                    }
                    // skipping *.lock file
                    if (child.getName().getBaseName().endsWith(".lock")) {
                        continue;
                    }
                    // skipping subfolders
                    if (child.getType() != FileType.FILE) {
                        continue;
                    }
                    // skipping files depending on size limitation
                    if (entry.getFileSizeLimit() >= 0 && child.getContent().getSize() > entry.getFileSizeLimit()) {
                        if (log.isDebugEnabled()) {
                            log.debug("Ignoring file - " + child.getName().getBaseName() + " size - " + child.getContent().getSize() + " since it exceeds file size limit - " + entry.getFileSizeLimit());
                        }
                        continue;
                    }
                    boolean isFailedRecord = false;
                    if (entry.getMoveAfterMoveFailure() != null) {
                        isFailedRecord = isFailedRecord(child, entry);
                    }
                    if (entry.getFileNamePattern() != null && child.getName().getBaseName().matches(entry.getFileNamePattern())) {
                        // now we try to get the lock and process
                        if (log.isDebugEnabled()) {
                            log.debug("Matching file : " + child.getName().getBaseName());
                        }
                        boolean runPostProcess = true;
                        if ((!entry.isFileLockingEnabled() || (entry.isFileLockingEnabled() && VFSUtils.acquireLock(fsManager, child, fso, true))) && !isFailedRecord) {
                            // process the file
                            try {
                                if (log.isDebugEnabled()) {
                                    log.debug("Processing file :" + VFSUtils.maskURLPassword(child.toString()));
                                }
                                processCount++;
                                if (child.getType() == FileType.FILE) {
                                    processFile(entry, child);
                                    successCount++;
                                    // tell moveOrDeleteAfterProcessing() file was success
                                    entry.setLastPollState(PollTableEntry.SUCCSESSFUL);
                                    metrics.incrementMessagesReceived();
                                } else {
                                    runPostProcess = false;
                                }
                            } catch (Exception e) {
                                if (e.getCause() instanceof FileNotFoundException) {
                                    log.warn("Error processing File URI : " + VFSUtils.maskURLPassword(child.getName().toString()) + ". This can be due to file moved from another process.");
                                    runPostProcess = false;
                                } else {
                                    logException("Error processing File URI : " + VFSUtils.maskURLPassword(child.getName().getURI()), e);
                                    failCount++;
                                    // tell moveOrDeleteAfterProcessing() file failed
                                    entry.setLastPollState(PollTableEntry.FAILED);
                                    metrics.incrementFaultsReceiving();
                                }
                            }
                            // skipping un-locking file if failed to do delete/move after process
                            boolean skipUnlock = false;
                            if (runPostProcess) {
                                try {
                                    moveOrDeleteAfterProcessing(entry, child, fso);
                                } catch (AxisFault axisFault) {
                                    logException("File object '" + VFSUtils.maskURLPassword(child.getURL().toString()) + "'cloud not be moved, will remain in \"locked\" state", axisFault);
                                    skipUnlock = true;
                                    failCount++;
                                    entry.setLastPollState(PollTableEntry.FAILED);
                                    String timeStamp = VFSUtils.getSystemTime(entry.getFailedRecordTimestampFormat());
                                    addFailedRecord(entry, child, timeStamp);
                                }
                            }
                            // if there is a failure or not we'll try to release the lock
                            if (entry.isFileLockingEnabled() && !skipUnlock) {
                                VFSUtils.releaseLock(fsManager, child, fso);
                            }
                        }
                    } else if (entry.getFileNamePattern() != null && !child.getName().getBaseName().matches(entry.getFileNamePattern())) {
                        // child's file name does not match the file name pattern
                        if (log.isDebugEnabled()) {
                            log.debug("Non-Matching file : " + child.getName().getBaseName());
                        }
                    } else if (isFailedRecord) {
                        // it is a failed record
                        if (entry.isFileLockingEnabled()) {
                            VFSUtils.releaseLock(fsManager, child, fso);
                            VFSUtils.releaseLock(fsManager, fileObject, fso);
                        }
                        if (fsManager.resolveFile(child.getURL().toString(), fso) != null && removeTaskState == STATE_STOPPED && entry.getMoveAfterMoveFailure() != null) {
                            workerPool.execute(new FileRemoveTask(entry, child, fso));
                        }
                        if (log.isDebugEnabled()) {
                            log.debug("File '" + VFSUtils.maskURLPassword(fileObject.getURL().toString()) + "' has been marked as a failed record, it will not " + "process");
                        }
                    }
                    if (iFileProcessingInterval != null && iFileProcessingInterval > 0) {
                        try {
                            if (log.isDebugEnabled()) {
                                log.debug("Put the VFS processor to sleep for : " + iFileProcessingInterval);
                            }
                            Thread.sleep(iFileProcessingInterval);
                        } catch (InterruptedException ie) {
                            log.error("Unable to set the interval between file processors." + ie);
                        }
                    } else if (iFileProcessingCount != null && iFileProcessingCount <= processCount) {
                        break;
                    }
                }
                if (failCount == 0 && successCount > 0) {
                    entry.setLastPollState(PollTableEntry.SUCCSESSFUL);
                } else if (successCount == 0 && failCount > 0) {
                    entry.setLastPollState(PollTableEntry.FAILED);
                } else {
                    entry.setLastPollState(PollTableEntry.WITH_ERRORS);
                }
            }
            // processing of this poll table entry is complete
            long now = System.currentTimeMillis();
            entry.setLastPollTime(now);
            entry.setNextPollTime(now + entry.getPollInterval());
        } else if (log.isDebugEnabled()) {
            log.debug("Unable to access or read file or directory : " + VFSUtils.maskURLPassword(fileURI) + "." + " Reason: " + (fileObject.exists() ? (fileObject.isReadable() ? "Unknown reason" : "The file can not be read!") : "The file does not exists!"));
        }
        onPollCompletion(entry);
    } catch (FileSystemException e) {
        processFailure("Error checking for existence and readability : " + VFSUtils.maskURLPassword(fileURI), e, entry);
    } catch (Exception ex) {
        processFailure("Un-handled exception thrown when processing the file : ", ex, entry);
    } finally {
        closeFileSystem(fileObject);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) FileNotFoundException(org.apache.commons.vfs2.FileNotFoundException) ClusteringAgent(org.apache.axis2.clustering.ClusteringAgent) FileNotFolderException(org.apache.commons.vfs2.FileNotFolderException) SecureVaultException(org.wso2.securevault.SecureVaultException) FileSystemException(org.apache.commons.vfs2.FileSystemException) ParseException(javax.mail.internet.ParseException) IOException(java.io.IOException) FileNotFoundException(org.apache.commons.vfs2.FileNotFoundException) FileNotFolderException(org.apache.commons.vfs2.FileNotFolderException) FileSystemException(org.apache.commons.vfs2.FileSystemException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) FileObject(org.apache.commons.vfs2.FileObject) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 3 with URI

use of org.apache.axis2.databinding.types.URI in project wso2-synapse by wso2.

the class VFSTransportListener method processFile.

/**
 * Process a single file through Axis2
 * @param entry the PollTableEntry for the file (or its parent directory or archive)
 * @param file the file that contains the actual message pumped into Axis2
 * @throws AxisFault on error
 */
private void processFile(PollTableEntry entry, FileObject file) throws AxisFault {
    try {
        FileContent content = file.getContent();
        String fileName = file.getName().getBaseName();
        String filePath = file.getName().getPath();
        String fileURI = file.getName().getURI();
        metrics.incrementBytesReceived(content.getSize());
        Map<String, Object> transportHeaders = new HashMap<String, Object>();
        transportHeaders.put(VFSConstants.FILE_PATH, filePath);
        transportHeaders.put(VFSConstants.FILE_NAME, fileName);
        transportHeaders.put(VFSConstants.FILE_URI, fileURI);
        try {
            transportHeaders.put(VFSConstants.FILE_LENGTH, content.getSize());
            transportHeaders.put(VFSConstants.LAST_MODIFIED, content.getLastModifiedTime());
        } catch (FileSystemException ignore) {
        }
        MessageContext msgContext = entry.createMessageContext();
        String contentType = entry.getContentType();
        if (BaseUtils.isBlank(contentType)) {
            if (file.getName().getExtension().toLowerCase().endsWith(".xml")) {
                contentType = "text/xml";
            } else if (file.getName().getExtension().toLowerCase().endsWith(".txt")) {
                contentType = "text/plain";
            }
        } else {
            // Extract the charset encoding from the configured content type and
            // set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder relies on this.
            String charSetEnc = null;
            try {
                if (contentType != null) {
                    charSetEnc = new ContentType(contentType).getParameter("charset");
                }
            } catch (ParseException ex) {
            // ignore
            }
            msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
        }
        // if the content type was not found, but the service defined it.. use it
        if (contentType == null) {
            if (entry.getContentType() != null) {
                contentType = entry.getContentType();
            } else if (VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE) != null) {
                contentType = VFSUtils.getProperty(content, BaseConstants.CONTENT_TYPE);
            }
        }
        // does the service specify a default reply file URI ?
        String replyFileURI = entry.getReplyFileURI();
        if (replyFileURI != null) {
            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new VFSOutTransportInfo(replyFileURI, entry.isFileLockingEnabled()));
        }
        // Determine the message builder to use
        Builder builder;
        if (contentType == null) {
            if (log.isDebugEnabled()) {
                log.debug("No content type specified. Using SOAP builder.");
            }
            builder = new SOAPBuilder();
        } else {
            int index = contentType.indexOf(';');
            String type = index > 0 ? contentType.substring(0, index) : contentType;
            builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
            if (builder == null) {
                if (log.isDebugEnabled()) {
                    log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
                }
                builder = new SOAPBuilder();
            }
        }
        // set the message payload to the message context
        InputStream in;
        ManagedDataSource dataSource;
        if (builder instanceof DataSourceMessageBuilder && entry.isStreaming()) {
            in = null;
            dataSource = ManagedDataSourceFactory.create(new FileObjectDataSource(file, contentType));
        } else {
            in = new AutoCloseInputStream(content.getInputStream());
            dataSource = null;
        }
        try {
            OMElement documentElement;
            if (in != null) {
                documentElement = builder.processDocument(in, contentType, msgContext);
            } else {
                documentElement = ((DataSourceMessageBuilder) builder).processDocument(dataSource, contentType, msgContext);
            }
            msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
            handleIncomingMessage(msgContext, transportHeaders, // * SOAP Action - not applicable *//
            null, contentType);
        } finally {
            if (dataSource != null) {
                dataSource.destroy();
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Processed file : " + VFSUtils.maskURLPassword(file.toString()) + " of Content-type : " + contentType);
        }
    } catch (FileSystemException e) {
        handleException("Error reading file content or attributes : " + VFSUtils.maskURLPassword(file.toString()), e);
    } finally {
        try {
            if (file != null) {
                if (fsManager != null && file.getName() != null && file.getName().getScheme() != null && file.getName().getScheme().startsWith("file")) {
                    fsManager.closeFileSystem(file.getParent().getFileSystem());
                }
                file.close();
            }
        } catch (FileSystemException warn) {
        // ignore the warning,  since we handed over the stream close job to
        // AutocloseInputstream..
        }
    }
}
Also used : ContentType(javax.mail.internet.ContentType) HashMap(java.util.HashMap) AutoCloseInputStream(org.apache.commons.io.input.AutoCloseInputStream) InputStream(java.io.InputStream) DataSourceMessageBuilder(org.apache.axis2.format.DataSourceMessageBuilder) Builder(org.apache.axis2.builder.Builder) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) OMElement(org.apache.axiom.om.OMElement) FileContent(org.apache.commons.vfs2.FileContent) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) FileObjectDataSource(org.apache.synapse.commons.vfs.FileObjectDataSource) MessageContext(org.apache.axis2.context.MessageContext) ParseException(javax.mail.internet.ParseException) VFSOutTransportInfo(org.apache.synapse.commons.vfs.VFSOutTransportInfo) AutoCloseInputStream(org.apache.commons.io.input.AutoCloseInputStream) ManagedDataSource(org.apache.axis2.format.ManagedDataSource) DataSourceMessageBuilder(org.apache.axis2.format.DataSourceMessageBuilder)

Example 4 with URI

use of org.apache.axis2.databinding.types.URI in project wso2-synapse by wso2.

the class ProxyServiceTest method testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeDisabled.

/**
 * Tests building a proxy service with an unreachable endpoint specified as the published wsdl url with the
 * 'enablePublishWSDLSafeMode' set to true.
 *
 * @throws Exception if an error occurs when converting the URI string to a URI
 */
public void testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeDisabled() throws Exception {
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration axisCfg = new AxisConfiguration();
    ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxyWithPublishWSDLSafeModeDisabled");
    proxyService.setPublishWSDLEndpoint("wsdlEndPoint");
    AddressEndpoint wsdlEndpoint = new AddressEndpoint();
    EndpointDefinition endpointDefinition = new EndpointDefinition();
    endpointDefinition.setAddress((new URI("http://localhost/SimpleStockService.wsdl")).toString());
    wsdlEndpoint.setDefinition(endpointDefinition);
    proxyService.addParameter("enablePublishWSDLSafeMode", false);
    synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint);
    try {
        proxyService.buildAxisService(synCfg, axisCfg);
        Assert.fail("Axis service built with an unreachable wsdl endpoint should throw fault");
    } catch (SynapseException e) {
        Assert.assertTrue("Unexpected exception thrown: " + e, e.getMessage().contains("Error reading from wsdl URI"));
    }
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) SynapseException(org.apache.synapse.SynapseException) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URI(java.net.URI)

Example 5 with URI

use of org.apache.axis2.databinding.types.URI in project wso2-synapse by wso2.

the class ProxyServiceTest method testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeEnabled.

/**
 * Tests building a proxy service with an unreachable endpoint specified as the published wsdl url with the
 * 'enablePublishWSDLSafeMode' set to false.
 *
 * @throws Exception if an error occurs when converting the URI string to a URI
 */
public void testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeEnabled() throws Exception {
    MessageContext synCtx = new TestMessageContext();
    SynapseConfiguration synCfg = new SynapseConfiguration();
    synCtx.setConfiguration(synCfg);
    AxisConfiguration axisCfg = new AxisConfiguration();
    ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxyWithPublishWSDLSafeModeEnabled");
    proxyService.setPublishWSDLEndpoint("wsdlEndPoint");
    AddressEndpoint wsdlEndpoint = new AddressEndpoint();
    EndpointDefinition endpointDefinition = new EndpointDefinition();
    endpointDefinition.setAddress((new URI("http://localhost/SimpleStockService.wsdl")).toString());
    wsdlEndpoint.setDefinition(endpointDefinition);
    proxyService.addParameter("enablePublishWSDLSafeMode", true);
    synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint);
    Assert.assertNull("Axis service built with an unreachable wsdl endpoint be null", proxyService.buildAxisService(synCfg, axisCfg));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) TestMessageContext(org.apache.synapse.TestMessageContext) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) MessageContext(org.apache.synapse.MessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) URI(java.net.URI)

Aggregations

AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)16 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)15 OMElement (org.apache.axiom.om.OMElement)13 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)13 Parameter (org.apache.axis2.description.Parameter)11 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)10 URI (java.net.URI)9 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)9 Test (org.junit.Test)9 EndpointReference (org.apache.axis2.addressing.EndpointReference)8 URI (org.apache.axis2.databinding.types.URI)7 IOException (java.io.IOException)5 SynapseException (org.apache.synapse.SynapseException)5 MalformedURLException (java.net.MalformedURLException)4 Calendar (java.util.Calendar)4 HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)4 InputStream (java.io.InputStream)3 URISyntaxException (java.net.URISyntaxException)3 URL (java.net.URL)3 HashMap (java.util.HashMap)3