org.apache.axis2.description.TransportInDescription Java Examples

The following examples show how to use org.apache.axis2.description.TransportInDescription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IheHTTPServer.java    From openxds with Apache License 2.0 6 votes vote down vote up
/**
     * init method in TransportListener
     *
     * @param axisConf
     * @param transprtIn
     * @throws AxisFault
     */
    public void init(ConfigurationContext axisConf, TransportInDescription transprtIn)
            throws AxisFault {
        try {
            this.configurationContext = axisConf;

//            if (httpFactory == null) {
//                httpFactory = new IheHttpFactory(configurationContext, actor.getConnection());
//            }
//
//            if (actor.getConnection().getHostname() != null) {
//                hostAddress = actor.getConnection().getHostname();
//            } else {
//                hostAddress = httpFactory.getHostAddress();
//            }
        } catch (Exception e1) {
            throw AxisFault.makeFault(e1);
        }
    }
 
Example #2
Source File: TenantAwareLoadBalanceEndpoint.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
/**
 * Setup load balancer message context properties to be used by the out block of the main sequence.
 * These values will be used to update the Location value in the response header.
 *
 * @param synCtx
 * @param currentMember
 */
private void setupLoadBalancerContextProperties(MessageContext synCtx, org.apache.axis2.clustering.Member currentMember) {
    String targetHostname = extractTargetHost(synCtx);
    org.apache.axis2.context.MessageContext axis2MsgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();

    String httpTransportName = "http", httpsTransportName = "https";
    String transportId = getTransportId(extractIncomingTransport(synCtx));

    if (transportId != null) {
        httpsTransportName = httpsTransportName.concat(transportId);
        httpTransportName = httpTransportName.concat(transportId);
    }

    TransportInDescription httpTransportIn = axis2MsgCtx.getConfigurationContext().getAxisConfiguration().getTransportIn(httpTransportName);
    TransportInDescription httpsTransportIn = axis2MsgCtx.getConfigurationContext().getAxisConfiguration().getTransportIn(httpsTransportName);
    String lbHttpPort = (String) httpTransportIn.getParameter("port").getValue();
    String lbHttpsPort = (String) httpsTransportIn.getParameter("port").getValue();
    String clusterId = currentMember.getProperties().getProperty(LoadBalancerConstants.CLUSTER_ID);

    synCtx.setProperty(LoadBalancerConstants.LB_TARGET_HOSTNAME, targetHostname);
    synCtx.setProperty(LoadBalancerConstants.LB_HTTP_PORT, lbHttpPort);
    synCtx.setProperty(LoadBalancerConstants.LB_HTTPS_PORT, lbHttpsPort);
    synCtx.setProperty(LoadBalancerConstants.CLUSTER_ID, clusterId);
}
 
Example #3
Source File: WSDL2Code.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private String getWsdlInformation(String serviceName, AxisConfiguration axisConfig)
        throws AxisFault {
    String ip;
    try {
        ip = NetworkUtils.getLocalHostname();
    } catch (SocketException e) {
        throw new AxisFault("Cannot get local host name", e);
    }
    TransportInDescription http = axisConfig.getTransportIn("http");
    if (http != null) {
        EndpointReference epr =
                ((HttpTransportListener) http.getReceiver()).
                getEPRForService(serviceName, ip);
        String wsdlUrlPrefix = epr.getAddress();
        if (wsdlUrlPrefix.endsWith("/")) {
            wsdlUrlPrefix = wsdlUrlPrefix.substring(0, wsdlUrlPrefix.length() - 1);
        }
        return wsdlUrlPrefix + "?wsdl";
    }
    return null;
}
 
Example #4
Source File: Util.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public static String getWsdlInformation(String serviceName,
                                          AxisConfiguration axisConfig) throws AxisFault {
    String ip;
    try {
        ip = NetworkUtils.getLocalHostname();
    } catch (SocketException e) {
        throw new AxisFault("Cannot get local host name", e);
    }

    TransportInDescription transportInDescription = axisConfig.getTransportIn("http");

    if (transportInDescription == null) {
        transportInDescription = axisConfig.getTransportIn("https");
    }

    if (transportInDescription != null) {
        EndpointReference[] epr =
                transportInDescription.getReceiver().getEPRsForService(serviceName, ip);
        String wsdlUrlPrefix = epr[0].getAddress();
        if (wsdlUrlPrefix.endsWith("/")) {
            wsdlUrlPrefix = wsdlUrlPrefix.substring(0, wsdlUrlPrefix.length() - 1);
        }
        return wsdlUrlPrefix + "?wsdl";
    }
    return null;
}
 
Example #5
Source File: TestUtils.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * To initialize the (@link {@link ConfigurationContextService}} for testing.
 *
 * @return initialized configuration context service.
 */
public static ConfigurationContextService initConfigurationContextService(boolean initAPIMConfigurationService) {
    ConfigurationContextService configurationContextService = Mockito.mock(ConfigurationContextService.class);
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    AxisConfiguration axisConfiguration = Mockito.mock(AxisConfiguration.class);
    Mockito.doReturn(axisConfiguration).when(configurationContext).getAxisConfiguration();
    TransportInDescription transportInDescription = Mockito.mock(TransportInDescription.class);
    Mockito.doReturn(transportInDescription).when(axisConfiguration).getTransportIn(Mockito.anyString());
    Mockito.doReturn(configurationContext).when(configurationContextService).getServerConfigContext();

    if (initAPIMConfigurationService) {
        APIManagerConfigurationService apiManagerConfigurationService = Mockito
                .mock(APIManagerConfigurationService.class);
        APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
        Mockito.doReturn("true").when(apiManagerConfiguration).getFirstProperty(APIConstants.ENABLE_MTLS_FOR_APIS);
        Mockito.doReturn(apiManagerConfiguration).when(apiManagerConfigurationService).getAPIManagerConfiguration();
        ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
    }
    ServiceReferenceHolder.setContextService(configurationContextService);
    System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
    System.setProperty("javax.net.ssl.trustStore", ".");
    return configurationContextService;
}
 
Example #6
Source File: TransportBuilderUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a TransportInDescription object from an XML configuration. The expected
    * XML configuration should be as follows.
    *
    * <transportReceiver name="myTransport" class="my.transport.listener.Class">
    *     <parameter name="param1">value 1</parameter>
    *     <parameter name="param1">value 1</parameter>
    * </transportReceiver>
 * 
 * @param transport An OMElement which contains transport configurations.
    * @param init Whether to initialize the receiver or not
 * @return a transport in description
 * @throws DeploymentException on error
 */
public static TransportInDescription processTransportReceiver(
           OMElement transport, boolean init) throws DeploymentException {

       if (!TAG_TRANSPORT_RECEIVER.equals(transport.getLocalName())) {
           throw new DeploymentException("Invalid top level element in the transport receiver " +
                   "configuration");
       }

       String name = transport.getAttributeValue(new QName(ATTRIBUTE_NAME));
       if (name == null || "".equals(name)) {
           throw new DeploymentException("Transport name is not specified in the receiver " +
                   "configuration");
       }

       String className = transport.getAttributeValue(new QName(ATTRIBUTE_CLASS));
       if (className == null || "".equals(className)) {
           throw new DeploymentException("Class name is not specified in the receiver " +
                   "configuration");
       }

       TransportInDescription transportIn = new TransportInDescription(name);
       if (init) {
           try {
               Class clazz = TransportBuilderUtils.class.getClassLoader().loadClass(className);
               TransportListener listener = (TransportListener) clazz.newInstance();
               transportIn.setReceiver(listener);
           } catch (Exception e) {
               throw new DeploymentException("Error while initializing transport receiver", e);
           }
       }

       Iterator itr = transport.getChildrenWithName(new QName(TAG_PARAMETER));
       processParameters(itr, transportIn);
       return transportIn;
   }
 
Example #7
Source File: TransportBuilderUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static OMElement serializeTransportListener(TransportInDescription transport) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement transportReceiver = fac.createOMElement(new QName(TAG_TRANSPORT_RECEIVER));
    transportReceiver.addAttribute(ATTRIBUTE_NAME, transport.getName(), null);
    transportReceiver.addAttribute(ATTRIBUTE_CLASS, transport.getReceiver().
            getClass().getName(), null);

    serializeParameters(transport, transportReceiver, fac);
    return transportReceiver;
}
 
Example #8
Source File: IheHTTPServer.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
 * Create a configured IheHTTPServer
 */
private IheHTTPServer(IheHttpFactory httpFactory) throws AxisFault {
    this.httpFactory = httpFactory;
    this.configurationContext = httpFactory.getConfigurationContext();
    TransportInDescription httpDescription =
            new TransportInDescription(Constants.TRANSPORT_HTTP);
    httpDescription.setReceiver(this);
    httpFactory.getListenerManager().addListener(httpDescription, true);
    sessionManager = new SessionManager();
}
 
Example #9
Source File: CertificateManagerImpl.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes an instance of CertificateManagerImpl.
 */
private CertificateManagerImpl() {
    String isMutualTLSConfigured = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService()
            .getAPIManagerConfiguration().getFirstProperty(APIConstants.ENABLE_MTLS_FOR_APIS);
    if (StringUtils.isNotEmpty(isMutualTLSConfigured) && isMutualTLSConfigured.equalsIgnoreCase("true")) {
        isMTLSConfigured = true;
    }
    if (isMTLSConfigured) {
        if (log.isDebugEnabled()) {
            log.debug("Mutual TLS based security is enabled for APIs. Hence APIs can be secured using mutual TLS "
                    + "and OAuth2");
        }
        TransportInDescription transportInDescription = ServiceReferenceHolder.getContextService()
                .getServerConfigContext().getAxisConfiguration().getTransportIn(Constants.TRANSPORT_HTTPS);
        Parameter profilePathParam = transportInDescription.getParameter("dynamicSSLProfilesConfig");
        if (profilePathParam == null) {
            listenerProfileFilePath = null;
        } else {
            OMElement pathEl = profilePathParam.getParameterElement();
            String path = pathEl.getFirstChildWithName(new QName("filePath")).getText();
            if (path != null) {
                String separator = path.startsWith(File.separator) ? "" : File.separator;
                listenerProfileFilePath = System.getProperty("user.dir") + separator + path;
            }
        }
    }
    if (log.isDebugEnabled()) {
        if (isMTLSConfigured) {
            log.debug("Mutual SSL based authentication is supported for this server.");
        } else {
            log.debug("Mutual SSL based authentication is not supported for this server.");
        }
    }
}
 
Example #10
Source File: ServerManagement.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Method to change the state of a node from "maintenance" to "normal"
 *
 * @throws Exception If an error occurs while trying to connect to the Tomcat MBean
 */
public void endMaintenance() throws Exception {
    SecurityManager secMan = System.getSecurityManager();
    if (secMan != null) {
        secMan.checkPermission(new ManagementPermission("control"));
    }
    log.info("Switching to normal mode...");
    for (Iterator iter = inTransports.values().iterator(); iter.hasNext();) {
        TransportInDescription tinDesc = (TransportInDescription) iter.next();
        TransportListener transport = tinDesc.getReceiver();
        transport.start();
    }
    log.info("Switched to normal mode");
}
 
Example #11
Source File: ServerManagement.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Method to switch a node to maintenance mode.
 * <p/>
 * Here is the sequence of events:
 * <p/>
 * <ol>
 * <li>Client calls this method</li>
 * <li>The server stops accepting new requests/connections, but continues to stay alive so
 * that old requests & connections can be served</li>
 * <li>Once all requests have been processed, the method returns</li
 * </ol>
 * @throws Exception - on errors while starting maintenance
 */
public void startMaintenance() throws Exception {
    SecurityManager secMan = System.getSecurityManager();
    if (secMan != null) {
        secMan.checkPermission(new ManagementPermission("control"));
    }
    log.info("Starting to switch to maintenance mode...");
    for (TransportInDescription tinDesc : inTransports.values()) {
        TransportListener transport = tinDesc.getReceiver();
        transport.stop();
    }
    log.info("Stopped all transport listeners");

    waitForRequestCompletion();
}
 
Example #12
Source File: Utils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static String[] getWsdlInformation(String serviceName,
                                          AxisConfiguration axisConfig) throws AxisFault {
    String ip;
    try {
        ip = NetworkUtils.getLocalHostname();
    } catch (SocketException e) {
        throw new AxisFault("Cannot get local host name", e);
    }

    //TODO Ideally, The transport on which wsdls are displayed, should be configurable.
    TransportInDescription transportInDescription = axisConfig.getTransportIn("http");

    if (transportInDescription == null) {
        transportInDescription = axisConfig.getTransportIn("https");
    }

    if (transportInDescription != null) {
        EndpointReference[] epr =
                transportInDescription.getReceiver().getEPRsForService(serviceName, ip);
        String wsdlUrlPrefix = epr[0].getAddress();
        if (wsdlUrlPrefix.endsWith("/")) {
            wsdlUrlPrefix = wsdlUrlPrefix.substring(0, wsdlUrlPrefix.length() - 1);
        }
        return new String[]{wsdlUrlPrefix + "?wsdl", wsdlUrlPrefix + "?wsdl2"};
    }
    return new String[]{};
}
 
Example #13
Source File: IheHttpFactory.java    From openxds with Apache License 2.0 4 votes vote down vote up
/**
 * Getter for httpConfiguration
 */
public TransportInDescription getHttpConfiguration() {
    return httpConfiguration;
}
 
Example #14
Source File: DBDeployer.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a set of default endpoints for this service
 */
private void createDefaultEndpoints(AxisService axisService, AxisBinding soap11Binding,
		AxisBinding soap12Binding, AxisBinding httpBinding) {
	Map<String, TransportInDescription> transportsIn = axisConfig.getTransportsIn();
	Iterator<TransportInDescription> iterator = transportsIn.values().iterator();
	while (iterator.hasNext()) {
		/*
		 * Used to indicate whether a HTTPEndpoint is needed. Http endpoint
		 * is needed only for http and https transports
		 */
		boolean needHttp = false;

		/* The prefix is used to generate endpoint names */
		String prefix = "";
		TransportInDescription transportIn = iterator.next();
		String transportInName = transportIn.getName();
		if (HTTP_TRANSPORT.equalsIgnoreCase(transportInName)) {
			needHttp = true;
		} else if (HTTPS_TRANSPORT.equalsIgnoreCase(transportInName)) {
			needHttp = true;
			prefix = WSDL2Constants.DEFAULT_HTTPS_PREFIX;
		} else if (transportInName != null) {
			prefix = transportInName.toUpperCase();
		}

		/* Creates a default SOAP 1.1 endpoint */
		AxisEndpoint soap11Endpoint = new AxisEndpoint();
		String soap11EndpointName = prefix
				+ WSDL2Constants.DEFAULT_SOAP11_ENDPOINT_NAME;
		soap11Endpoint.setName(soap11EndpointName);
		soap11Endpoint.setBinding(soap11Binding);
		soap11Endpoint.setParent(axisService);
		soap11Endpoint.setTransportInDescription(transportInName);
		soap11Endpoint.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, httpLocationTable);
           soap11Endpoint.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE_FOR_RESOURCE, httpLocationTableForResource);
		axisService.addEndpoint(soap11EndpointName, soap11Endpoint);

           /* setting soap11 endpoint as the default endpoint */
		axisService.setEndpointName(soap11EndpointName);

		/* Creates a default SOAP 1.2 endpoint */
		AxisEndpoint soap12Endpoint = new AxisEndpoint();
		String soap12EndpointName = prefix
				+ WSDL2Constants.DEFAULT_SOAP12_ENDPOINT_NAME;
		soap12Endpoint.setName(soap12EndpointName);
		soap12Endpoint.setBinding(soap12Binding);
		soap12Endpoint.setParent(axisService);
		soap12Endpoint.setTransportInDescription(transportInName);
		soap12Endpoint.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, httpLocationTable);
           soap12Endpoint.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE_FOR_RESOURCE, httpLocationTableForResource);
		axisService.addEndpoint(soap12EndpointName, soap12Endpoint);

		/* Creates a HTTP endpoint if its http or https transport is used */
		if (needHttp) {
			AxisEndpoint httpEndpoint = new AxisEndpoint();
			String httpEndpointName = prefix
					+ WSDL2Constants.DEFAULT_HTTP_ENDPOINT_NAME;
			httpEndpoint.setName(httpEndpointName);
			httpEndpoint.setBinding(httpBinding);
			httpEndpoint.setParent(axisService);
			httpEndpoint.setTransportInDescription(transportInName);
			httpEndpoint.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE, httpLocationTable);
               httpEndpoint.setProperty(WSDL2Constants.HTTP_LOCATION_TABLE_FOR_RESOURCE, httpLocationTableForResource);
			axisService.addEndpoint(httpEndpointName, httpEndpoint);
		}
	}
}
 
Example #15
Source File: AxisConfigurationMockCreator.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public AxisConfigurationMockCreator() {
    configuration = Mockito.mock(AxisConfiguration.class);
    transportInDescription = Mockito.mock(TransportInDescription.class);
    Mockito.when(configuration.getTransportIn(Mockito.anyString())).thenReturn(transportInDescription);
}
 
Example #16
Source File: AxisConfigurationMockCreator.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public TransportInDescription getTransportInDescription() {
    return transportInDescription;
}
 
Example #17
Source File: ServerManagement.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
public ServerManagement(Map<String, TransportInDescription> inTransports,
                        ConfigurationContext serverConfigContext) {
    this.inTransports = inTransports;
    this.serverConfigContext = serverConfigContext;
}
 
Example #18
Source File: CarbonConnection.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a URL connection to the specified URL. A connection to
 * the object referenced by the URL is not created.
 *
 * @param url     the specified URL.
 * @param context BundleContext
 */
protected CarbonConnection(URL url, BundleContext context) throws Exception {
    super(url);
    ConfigurationContext configContext;
    configContext = CarbonUIServiceComponent
            .getConfigurationContextService().getServerConfigContext();

    TransportInDescription httpsInDescription = configContext.getAxisConfiguration().
            getTransportIn(ServerConstants.HTTPS_TRANSPORT);
    Parameter proxyParameter = httpsInDescription.getParameter("proxyPort");
    String httpsProxyPort = null;
    if (proxyParameter != null && !"-1".equals(proxyParameter.getValue())) {
        httpsProxyPort = (String) proxyParameter.getValue();
    }

    TransportInDescription httpInDescription = configContext.getAxisConfiguration().
            getTransportIn(ServerConstants.HTTP_TRANSPORT);
    if (httpInDescription != null) {
        proxyParameter = httpInDescription.getParameter("proxyPort");
    }
    String httpProxyPort = null;
    if (proxyParameter != null && !"-1".equals(proxyParameter.getValue())) {
        httpProxyPort = (String) proxyParameter.getValue();
    }
    try {
        String servicePath = configContext.getServicePath();
        String contextRoot = configContext.getContextRoot();
        contextRoot = contextRoot.equals("/") ? "" : contextRoot;
        String httpsPort;
        if (httpsProxyPort != null) {
            httpsPort = httpsProxyPort;
        } else {
            httpsPort =
                    CarbonUtils.
                            getTransportPort(CarbonUIServiceComponent.getConfigurationContextService(),
                                             "https") + "";
        }
        String httpPort;
        if (httpProxyPort != null) {
            httpPort = httpProxyPort;
        } else {
            if (httpInDescription != null) {
                httpPort =
                        CarbonUtils.
                                getTransportPort(CarbonUIServiceComponent.getConfigurationContextService(),
                                                 "http") + "";
            } else {
                httpPort = "-1";
            }
        }
        buf = ("var SERVICE_PATH=\"" + servicePath + "\";\n" +
               "var ROOT_CONTEXT=\"" + contextRoot + "\";\n" +
               "var HTTP_PORT=" + httpPort + ";\n" +
               "var HTTPS_PORT=" + httpsPort + ";\n").getBytes();
    } catch (Exception e) {
        String msg = "Error occurred while getting connection properties";
        log.error(msg, e);
    }
}