Search in sources :

Example 36 with URI

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

the class EndpointDeployerTest method testUpdate.

/**
 * Test updating an endpoint
 *
 * @throws Exception
 */
@Test
public void testUpdate() throws Exception {
    String inputXML = "<endpoint name = \"sampleEP\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" >" + "</address>" + "</endpoint>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    EndpointDeployer endpointDeployer = new EndpointDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    endpointDeployer.init(cfgCtx);
    endpointDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    String inputUpdateXML = "<endpoint name = \"sampleUpdatedEP\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "<address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" >" + "</address>" + "</endpoint>";
    OMElement updatedElement = AXIOMUtil.stringToOM(inputUpdateXML);
    String response = endpointDeployer.updateSynapseArtifact(updatedElement, "sampleUpdateFile", "sampleEP", null);
    Assert.assertEquals("Endpoint not updated!", "sampleUpdatedEP", response);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 37 with URI

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

the class TemplateDeployerTest method testUndeploy.

/**
 * Test undeploying an endpoint
 *
 * @throws Exception
 */
@Test
public void testUndeploy() throws Exception {
    String inputXML = "<template name = \"TestTemplate\" xmlns=\"http://ws.apache.org/ns/synapse\">" + "              <endpoint name = \"sampleEP\" >" + "                  <address uri=\"http://localhost:9000/services/SimpleStockQuoteService\" >" + "</address>" + "              </endpoint>" + "          </template>";
    OMElement inputElement = AXIOMUtil.stringToOM(inputXML);
    TemplateDeployer templateDeployer = new TemplateDeployer();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment));
    axisConfiguration.addParameter(new Parameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfiguration));
    cfgCtx.setAxisConfiguration(axisConfiguration);
    templateDeployer.init(cfgCtx);
    templateDeployer.deploySynapseArtifact(inputElement, "sampleFile", null);
    Assert.assertNotNull("Endpoint template not deployed!", synapseConfiguration.getEndpointTemplate("TestTemplate"));
    templateDeployer.undeploySynapseArtifact("TestTemplate");
    Assert.assertNull("Endpoint template cannot be undeployed", synapseConfiguration.getEndpointTemplate("TestTemplate"));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Example 38 with URI

use of org.apache.axis2.databinding.types.URI in project carbon-business-process by wso2.

the class TransformerUtil method convertAttachment.

/**
 * Transform {@link Attachment} to (DTO) {@link TAttachment}
 *
 * @param attachment
 * @return
 */
public static TAttachment convertAttachment(Attachment attachment) throws AttachmentMgtException {
    TAttachment attachmentDTO = new TAttachment();
    attachmentDTO.setId(attachment.getId());
    attachmentDTO.setName(attachment.getName());
    attachmentDTO.setCreatedBy(attachment.getCreatedBy());
    Calendar cal = Calendar.getInstance();
    cal.setTime(attachment.getCreatedTime());
    attachmentDTO.setCreatedTime(cal);
    attachmentDTO.setContentType(attachment.getContentType());
    attachmentDTO.setContent(attachment.getContent());
    try {
        URI attachmentURI = new URI(attachment.getURL().toString());
        attachmentDTO.setUrl(attachmentURI);
    } catch (URI.MalformedURIException e) {
        log.error(e.getLocalizedMessage(), e);
        throw new AttachmentMgtException("Conversion of Attachment to TAttachment (DTO) failed due to reason : " + e.getLocalizedMessage(), e);
    }
    return attachmentDTO;
}
Also used : AttachmentMgtException(org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException) TAttachment(org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment) Calendar(java.util.Calendar) URI(org.apache.axis2.databinding.types.URI)

Example 39 with URI

use of org.apache.axis2.databinding.types.URI 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 40 with URI

use of org.apache.axis2.databinding.types.URI 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)

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