Search in sources :

Example 51 with URL

use of org.apache.axis2.util.URL in project wso2-axis2-transports by wso2.

the class XMPPConnectionFactory method connect.

/**
 * Connects to a XMPP server based on the details available in serverCredentials object
 * @param serverCredentials
 * @throws XMPPException
 */
public XMPPConnection connect(final XMPPServerCredentials serverCredentials) throws AxisFault {
    // XMPPConnection.DEBUG_ENABLED = true;
    if (XMPPConstants.XMPP_SERVER_TYPE_JABBER.equals(serverCredentials.getServerType())) {
        xmppConnection = new XMPPConnection(serverCredentials.getServerUrl());
        try {
            xmppConnection.connect();
        } catch (XMPPException e) {
            log.error("Failed to connect to server :" + serverCredentials.getServerUrl(), e);
            throw new AxisFault("Failed to connect to server :" + serverCredentials.getServerUrl());
        }
        // This prevents random ssl exception from Smack API
        try {
            Thread.sleep(100);
        } catch (InterruptedException e5) {
            log.debug("Sleep interrupted ", e5);
        }
        if (xmppConnection.isConnected()) {
            String resource = serverCredentials.getResource() + new Object().hashCode();
            if (!xmppConnection.isAuthenticated()) {
                try {
                    xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
                } catch (XMPPException e) {
                    try {
                        log.error("Login failed for " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + ".Retrying in 2 secs", e);
                        Thread.sleep(2000);
                        xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
                    } catch (InterruptedException e1) {
                        log.error("Sleep interrupted.", e1);
                    } catch (XMPPException e2) {
                        log.error("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl(), e2);
                        throw new AxisFault("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl());
                    }
                }
                // Listen for Message type packets from specified server url
                packetFilter = new FromContainsFilter(serverCredentials.getServerUrl());
            }
        }
    } else if (XMPPConstants.XMPP_SERVER_TYPE_GOOGLETALK.equals(serverCredentials.getServerType())) {
        ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(XMPPConstants.GOOGLETALK_URL, XMPPConstants.GOOGLETALK_PORT, XMPPConstants.GOOGLETALK_SERVICE_NAME);
        xmppConnection = new XMPPConnection(connectionConfiguration);
        try {
            xmppConnection.connect();
            xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), serverCredentials.getResource(), true);
            packetFilter = new ToContainsFilter("@gmail.com");
        } catch (XMPPException e1) {
            log.error("Error occured while connecting to Googletalk server.", e1);
            throw new AxisFault("Error occured while connecting to Googletalk server.");
        }
    }
    ConnectionListener connectionListener = null;
    connectionListener = new ConnectionListener() {

        public void connectionClosed() {
            log.debug("Connection closed normally");
        }

        public void connectionClosedOnError(Exception e1) {
            log.error("Connection to " + serverCredentials.getServerUrl() + " closed with error.", e1);
        }

        public void reconnectingIn(int seconds) {
            log.error("Connection to " + serverCredentials.getServerUrl() + " failed. Reconnecting in " + seconds + "s");
        }

        public void reconnectionFailed(Exception e) {
            log.error("Reconnection to " + serverCredentials.getServerUrl() + " failed.", e);
        }

        public void reconnectionSuccessful() {
            log.debug("Reconnection to " + serverCredentials.getServerUrl() + " successful.");
        }
    };
    if (xmppConnection != null && xmppConnection.isConnected()) {
        xmppConnection.addConnectionListener(connectionListener);
        log.info("Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
    } else {
        log.warn(" Not Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
    }
    return xmppConnection;
}
Also used : AxisFault(org.apache.axis2.AxisFault) ToContainsFilter(org.jivesoftware.smack.filter.ToContainsFilter) ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration) FromContainsFilter(org.jivesoftware.smack.filter.FromContainsFilter) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ConnectionListener(org.jivesoftware.smack.ConnectionListener) XMPPException(org.jivesoftware.smack.XMPPException) XMPPException(org.jivesoftware.smack.XMPPException)

Example 52 with URL

use of org.apache.axis2.util.URL in project tdi-studio-se by Talend.

the class MSCRMClient method doGetOnlineConnection.

/**
     * URL for the Discovery Service For North America Microsoft account, discovery service url is
     * https://dev.crm.dynamics.com/XRMServices/2011/Discovery.svc Microsoft office 365, discovery service url is
     * https://disco.crm.dynamics.com/XRMServices/2011/Discovery.svc To use appropriate discovery service url for other
     * environments refer http://technet.microsoft.com/en-us/library/gg309401.aspx
     * 
     * @throws Exception
     */
public OrganizationServiceStub doGetOnlineConnection(String discoveryServiceURL) throws Exception {
    try {
        // Retrieve the authentication policy for the discovery service.
        OnlineAuthenticationPolicy discoveryPolicy = new OnlineAuthenticationPolicy(discoveryServiceURL + FlatWSDLSuffix);
        WsdlTokenManager discoeryTokenManager = new WsdlTokenManager();
        // Authenticate the user using the discovery authentication policy.
        SecurityData discoverySecurityData = discoeryTokenManager.authenticate(discoveryServiceURL, username, password, discoveryPolicy.getAppliesTo(), discoveryPolicy.getPolicy(), discoveryPolicy.getIssuerUri());
        // Retrieve discovery stub using organization URL with the security data.
        DiscoveryServiceStub discoveryServiceStub = createDiscoveryServiceStub(discoveryServiceURL, discoverySecurityData);
        // Retrieve organization service url using discovery stub.
        String orgUrl = discoverOrganizationUrl(discoveryServiceStub, orgName);
        // The discovery service stub cannot be reused against the organization service
        // as the Issuer and AppliesTo may differ between the discovery and organization services.
        // Retrieve the authentication policy for the organization service.
        OnlineAuthenticationPolicy organizationPolicy = new OnlineAuthenticationPolicy(orgUrl + FlatWSDLSuffix);
        WsdlTokenManager orgTokenManager = new WsdlTokenManager();
        // Authenticate the user using the organization authentication policy.
        SecurityData securityData = orgTokenManager.authenticate(orgUrl, username, password, organizationPolicy.getAppliesTo(), organizationPolicy.getPolicy(), organizationPolicy.getIssuerUri());
        // Retrieve organization stub using organization URL with the security data.
        serviceStub = createOrganizationServiceStub(orgUrl, securityData);
        Options options = serviceStub._getServiceClient().getOptions();
        if (reuseHttpClient != null) {
            options.setProperty(org.apache.axis2.transport.http.HTTPConstants.REUSE_HTTP_CLIENT, reuseHttpClient);
        }
        if (timeout != null) {
            options.setTimeOutInMilliSeconds(Long.valueOf(timeout));
            options.setProperty(org.apache.axis2.transport.http.HTTPConstants.SO_TIMEOUT, timeout);
            options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CONNECTION_TIMEOUT, timeout);
        }
    } catch (IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage e) {
        throw new Exception(e.getFaultMessage().getDiscoveryServiceFault().getMessage());
    }
    return serviceStub;
}
Also used : DiscoveryServiceStub(com.microsoft.schemas.xrm._2011.contracts.DiscoveryServiceStub) Options(org.apache.axis2.client.Options) OnlineAuthenticationPolicy(org.talend.ms.crm.sdk.OnlineAuthenticationPolicy) SecurityData(org.talend.ms.crm.sdk.SecurityData) IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage(com.microsoft.schemas.xrm._2011.contracts.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage) WsdlTokenManager(org.talend.ms.crm.sdk.WsdlTokenManager) XMLStreamException(javax.xml.stream.XMLStreamException) RemoteException(java.rmi.RemoteException)

Example 53 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class URLGeneratorUtil method getPermanentLink.

/**
 * Generate the permanent link for the given attachment uri based on current system configurations like host, port
 * eg - if {@code uniqueID} is abc123, then the resultant permanent link would {@code https://127.0.0.1:9443/context/abc123}
 * So this url can be used to download the attachment
 *
 * @param uniqueID uri for the attachment
 * @return downloadable url of the attachment
 * @throws AttachmentMgtException
 */
public static URL getPermanentLink(URI uniqueID) throws AttachmentMgtException {
    String scheme = CarbonConstants.HTTPS_TRANSPORT;
    String host;
    try {
        host = NetworkUtils.getLocalHostname();
    } catch (SocketException e) {
        log.error(e.getMessage(), e);
        throw new AttachmentMgtException(e.getLocalizedMessage(), e);
    }
    int port = 9443;
    try {
        ConfigurationContext serverConfigContext = AttachmentServerHolder.getInstance().getConfigurationContextService().getServerConfigContext();
        port = CarbonUtils.getTransportProxyPort(serverConfigContext, scheme);
        if (port == -1) {
            port = CarbonUtils.getTransportPort(serverConfigContext, scheme);
        }
    } catch (Exception ex) {
        log.warn("Using default port settings");
    }
    String webContext = ServerConfiguration.getInstance().getFirstProperty("WebContextRoot");
    if (webContext == null || webContext.equals("/")) {
        webContext = "";
    }
    String tenantDomain = String.valueOf(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    try {
        tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    } catch (Throwable e) {
        tenantDomain = null;
    }
    String url = null;
    try {
        String link = scheme + "://" + host + ":" + port + webContext + ((tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) ? "/" + MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + tenantDomain : "") + AttachmentMgtConfigurationConstants.ATTACHMENT_DOWNLOAD_SERVELET_URL_PATTERN + "/" + uniqueID.toString();
        return new URL(link);
    } catch (MalformedURLException e) {
        log.error(e.getMessage(), e);
        throw new AttachmentMgtException(e.getLocalizedMessage(), e);
    }
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) SocketException(java.net.SocketException) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MalformedURLException(java.net.MalformedURLException) MalformedURLException(java.net.MalformedURLException) AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) SocketException(java.net.SocketException) URL(java.net.URL)

Example 54 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class AxisServiceUtils method populateAxisService.

private static AxisService populateAxisService(BPELProcessProxy processProxy, AxisConfiguration axisConfiguration, WSDL11ToAxisServiceBuilder serviceBuilder) throws AxisFault {
    ProcessConf pConf = processProxy.getProcessConfiguration();
    AxisService axisService = serviceBuilder.populateService();
    axisService.setParent(axisConfiguration);
    axisService.setWsdlFound(true);
    axisService.setCustomWsdl(true);
    axisService.setClassLoader(axisConfiguration.getServiceClassLoader());
    URL wsdlUrl = null;
    for (File file : pConf.getFiles()) {
        if (file.getAbsolutePath().indexOf(processProxy.getWsdlDefinition().getDocumentBaseURI()) > 0) {
            try {
                wsdlUrl = file.toURI().toURL();
            } catch (MalformedURLException e) {
                String errorMessage = "Cannot convert File URI to URL.";
                handleException(pConf.getProcessId(), errorMessage, e);
            }
        }
    }
    if (wsdlUrl != null) {
        axisService.setFileName(wsdlUrl);
    }
    Utils.setEndpointsToAllUsedBindings(axisService);
    axisService.addParameter(new Parameter("useOriginalwsdl", "true"));
    axisService.addParameter(new Parameter("modifyUserWSDLPortAddress", "true"));
    axisService.addParameter(new Parameter("setEndpointsToAllUsedBindings", "true"));
    /* Setting service type to use in service management*/
    axisService.addParameter(ServerConstants.SERVICE_TYPE, "bpel");
    /* Process ID as a service parameter to use with process try-it*/
    axisService.addParameter(BPELConstants.PROCESS_ID, pConf.getProcessId());
    /* Fix for losing of security configuration  when updating BPEL package*/
    axisService.addParameter(new Parameter(CarbonConstants.PRESERVE_SERVICE_HISTORY_PARAM, "true"));
    return axisService;
}
Also used : MalformedURLException(java.net.MalformedURLException) ProcessConf(org.apache.ode.bpel.iapi.ProcessConf) AxisService(org.apache.axis2.description.AxisService) Parameter(org.apache.axis2.description.Parameter) File(java.io.File) URL(java.net.URL)

Example 55 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class HumanTaskUploader method uploadHumanTask.

public void uploadHumanTask(UploadedFileItem[] fileItems) throws AxisFault {
    // First lets filter for jar resources
    ConfigurationContext configurationContext = getConfigContext();
    String repo = configurationContext.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(repo)) {
        throw new AxisFault("URL Repositories are not supported: " + repo);
    }
    // Writting the artifacts to the proper location
    String humantaskDirectory = getHumanTaskLocation(repo);
    String humantaskTemp = CarbonUtils.getCarbonHome() + File.separator + HumanTaskConstants.HUMANTASK_PACKAGE_TEMP_DIRECTORY;
    File humantaskTempDir = new File(humantaskTemp);
    if (!humantaskTempDir.exists() && !humantaskTempDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + humantaskTempDir.getAbsolutePath());
    }
    File humantaskDir = new File(humantaskDirectory);
    if (!humantaskDir.exists() && !humantaskDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + humantaskDir.getAbsolutePath());
    }
    for (UploadedFileItem uploadedFile : fileItems) {
        String fileName = uploadedFile.getFileName();
        if (fileName == null || fileName.equals("")) {
            throw new AxisFault("Invalid file name. File name is not available");
        }
        if (HumanTaskConstants.HUMANTASK_PACKAGE_EXTENSION.equals(uploadedFile.getFileType())) {
            try {
                writeResource(uploadedFile.getDataHandler(), humantaskTemp, fileName, humantaskDir);
            } catch (IOException e) {
                throw new AxisFault("IOError: Writing resource failed.", e);
            }
        } else {
            throw new AxisFault("Invalid file type : " + uploadedFile.getFileType() + " ." + HumanTaskConstants.HUMANTASK_PACKAGE_EXTENSION + " file type is expected");
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) UploadedFileItem(org.wso2.carbon.core.common.UploadedFileItem)

Aggregations

IOException (java.io.IOException)31 EndpointReference (org.apache.axis2.addressing.EndpointReference)29 AxisFault (org.apache.axis2.AxisFault)27 URL (java.net.URL)21 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)19 URL (org.apache.axis2.util.URL)19 HttpClient (org.apache.http.client.HttpClient)19 Options (org.apache.axis2.client.Options)18 MalformedURLException (java.net.MalformedURLException)17 OMElement (org.apache.axiom.om.OMElement)17 MessageContext (org.apache.axis2.context.MessageContext)16 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 ServiceClient (org.apache.axis2.client.ServiceClient)13 SynapseException (org.apache.synapse.SynapseException)13 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)12 AxisService (org.apache.axis2.description.AxisService)10 StringEntity (org.apache.http.entity.StringEntity)9 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)9 Map (java.util.Map)7 JSONObject (org.json.JSONObject)7