Java Code Examples for org.apache.axis2.context.MessageContext#getEnvelope()

The following examples show how to use org.apache.axis2.context.MessageContext#getEnvelope() . 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: SoapHeader.java    From openxds with Apache License 2.0 6 votes vote down vote up
public SoapHeader(MessageContext messageContext) {
	env = null;
	hdr = null;
	to = null;
	action = null;
	isSOAP12 = false;
	isSOAP11 = false;

	env = messageContext.getEnvelope();
	if (env == null) return;
	ns = env.getNamespace();
	if (ns != null) {
		isSOAP12 = ns.getNamespaceURI().contains("http://www.w3.org/2003/05/soap-envelope");
		isSOAP11 = ns.getNamespaceURI().contains("http://schemas.xmlsoap.org/soap/envelope/");
	}
	hdr = MetadataSupport.firstChildWithLocalName(env, "Header");
	if (hdr == null) return;
	to = MetadataSupport.firstChildWithLocalName(hdr, "To");
	action = MetadataSupport.firstChildWithLocalName(hdr, "Action");
}
 
Example 2
Source File: Soap.java    From openxds with Apache License 2.0 6 votes vote down vote up
public OMElement getInHeader() throws XdsInternalException {
	OperationContext oc = serviceClient.getLastOperationContext();
	HashMap<String, MessageContext> ocs = oc.getMessageContexts();
	MessageContext in = ocs.get("In");

	if (in == null)
		return null;

	if (in.getEnvelope() == null)
		return null;

	if (in.getEnvelope().getHeader() == null)
		return null;

	return Util.deep_copy( in.getEnvelope().getHeader());
}
 
Example 3
Source File: InOnlyMEPHandler.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
    if (msgContext.getEnvelope() == null) {
        return InvocationResponse.CONTINUE;
    }
    if (msgContext.getFLOW() != MessageContext.IN_FLOW &&
        msgContext.getFLOW() != MessageContext.IN_FAULT_FLOW) {
        log.error("InOnlyMEPHandler not deployed in IN/IN_FAULT flow. Flow: " +
                  msgContext.getFLOW());
        return InvocationResponse.CONTINUE;
    }
    try {
        msgContext.setProperty(StatisticsConstants.REQUEST_RECEIVED_TIME,
                               "" + System.currentTimeMillis());
    } catch (Throwable e) { // Catching Throwable since exceptions here should not be propagated up
        log.error("Could not call InOnlyMEPHandler.invoke", e);
    }
    return InvocationResponse.CONTINUE;
}
 
Example 4
Source File: AxisOperationClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * @param trpUrl
 * @param addUrl
 * @param payload
 * @param action
 * @return soap envelop
 * @throws org.apache.axis2.AxisFault
 */

public OMElement send(String trpUrl, String addUrl, OMElement payload, String action) throws AxisFault {
    operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
    setMessageContext(addUrl, trpUrl, action);
    outMsgCtx.setEnvelope(createSOAPEnvelope(payload));
    operationClient.addMessageContext(outMsgCtx);
    operationClient.execute(true);
    MessageContext inMsgtCtx = operationClient.getMessageContext("In");
    SOAPEnvelope response = inMsgtCtx.getEnvelope();
    return response;
}
 
Example 5
Source File: AxisOperationClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Creating the multiple quote request
 *
 * @param trpUrl
 * @param addUrl
 * @param symbol
 * @param iterations
 * @return
 * @throws java.io.IOException
 */
private OMElement createMultipleQuoteRequest(String trpUrl, String addUrl, String symbol, int iterations)
        throws IOException {
    operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
    setMessageContext(addUrl, trpUrl, null);
    outMsgCtx.setEnvelope(createSOAPEnvelope(symbol, iterations));
    operationClient.addMessageContext(outMsgCtx);
    operationClient.execute(true);
    MessageContext inMsgtCtx = operationClient.getMessageContext("In");
    SOAPEnvelope response = inMsgtCtx.getEnvelope();
    return response;

}
 
Example 6
Source File: AxisOperationClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param trpUrl
 * @param addUrl
 * @param payload
 * @param action
 * @return   soap envelop
 * @throws org.apache.axis2.AxisFault
 */

public OMElement send(String trpUrl, String addUrl, OMElement payload, String action) throws AxisFault {
    operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
    setMessageContext(addUrl, trpUrl, action);
    outMsgCtx.setEnvelope(createSOAPEnvelope(payload));
    operationClient.addMessageContext(outMsgCtx);
    operationClient.execute(true);
    MessageContext inMsgtCtx = operationClient.getMessageContext("In");
    SOAPEnvelope response = inMsgtCtx.getEnvelope();
    return response;
}
 
Example 7
Source File: AxisOperationClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Creating the multiple quote request
 *
 * @param trpUrl
 * @param addUrl
 * @param symbol
 * @param iterations
 * @return
 * @throws java.io.IOException
 */
private OMElement createMultipleQuoteRequest(String trpUrl, String addUrl, String symbol,
                                             int iterations) throws IOException {
    operationClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
    setMessageContext(addUrl, trpUrl, null);
    outMsgCtx.setEnvelope(createSOAPEnvelope(symbol, iterations));
    operationClient.addMessageContext(outMsgCtx);
    operationClient.execute(true);
    MessageContext inMsgtCtx = operationClient.getMessageContext("In");
    SOAPEnvelope response = inMsgtCtx.getEnvelope();
    return response;

}
 
Example 8
Source File: ProxyMessageReceiver.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private SOAPEnvelope getResponseEnvelope(ServiceClient client) throws AxisFault {
    OperationContext operationContext = client.getLastOperationContext();
    MessageContext messageContext =
            operationContext.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    if (messageContext != null) {
        return messageContext.getEnvelope();
    }
    return null;
}
 
Example 9
Source File: LoadBalanceSessionFullClient.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private List<ResponseData> makeRequest(String session, int iterations, long sleepTime, SOAPEnvelope[] envelopes,
                                       ServiceClient client) throws AxisFault {
    List<ResponseData> responseList = new ArrayList<ResponseData>();

    int i = 0;
    int sessionNumber;
    String[] cookies = new String[3];
    boolean httpSession = session != null && "http".equals(session);
    int cookieNumber;

    while (i < iterations) {

        i++;
        if (sleepTime != -1) {
            try {
                Thread.sleep(sleepTime);
            } catch (InterruptedException ignored) {
            }
        }

        MessageContext messageContext = new MessageContext();
        sessionNumber = getSessionTurn(envelopes.length);

        messageContext.setEnvelope(envelopes[sessionNumber]);
        cookieNumber = getSessionTurn(cookies.length);
        String cookie = cookies[cookieNumber];
        if (httpSession) {
            setSessionID(messageContext, cookie);
        }
        try {
            OperationClient op = client.createClient(ServiceClient.ANON_OUT_IN_OP);
            op.addMessageContext(messageContext);
            op.execute(true);

            MessageContext responseContext = op.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
            String receivedCookie = extractSessionID(responseContext);
            String receivedSetCookie = getSetCookieHeader(responseContext);
            if (httpSession) {

                if (receivedSetCookie != null && !"".equals(receivedSetCookie)) {
                    cookies[cookieNumber] = receivedCookie;
                }
            }

            SOAPEnvelope responseEnvelope = responseContext.getEnvelope();

            OMElement vElement = responseEnvelope.getBody().getFirstChildWithName(new QName("Value"));
            if (log.isDebugEnabled()) {
                log.debug("Request: " + i + " with Session ID: " + (httpSession ? cookie : sessionNumber) + " ---- "
                                  + "Response : with  " + (httpSession && receivedCookie != null ?
                        (receivedSetCookie != null ? receivedSetCookie : receivedCookie) :
                        " ") + " " + vElement.getText());
            }

            responseList
                    .add(new ResponseData(true, "" + (httpSession ? cookie : sessionNumber), vElement.getText()));

        } catch (AxisFault axisFault) {
            if (log.isDebugEnabled()) {
                log.debug("Request with session id " + (httpSession ? cookie : sessionNumber), axisFault);
            }

            responseList.add(new ResponseData(false, "" + (httpSession ? cookie : sessionNumber),
                                              axisFault.getMessage()));
        }
    }

    return responseList;
}
 
Example 10
Source File: LoadBalanceSessionFullClient.java    From product-ei with Apache License 2.0 4 votes vote down vote up
private List<ResponseData> makeRequest(String session, int iterations, long sleepTime, SOAPEnvelope[] envelopes,
                                       ServiceClient client) throws AxisFault {
    List<ResponseData> responseList = new ArrayList<ResponseData>();

    int i = 0;
    int sessionNumber;
    String[] cookies = new String[3];
    boolean httpSession = session != null && "http".equals(session);
    int cookieNumber;

    while (i < iterations) {

        i++;
        if (sleepTime != -1) {
            try {
                Thread.sleep(sleepTime);
            } catch (InterruptedException ignored) {
            }
        }

        MessageContext messageContext = new MessageContext();
        sessionNumber = getSessionTurn(envelopes.length);

        messageContext.setEnvelope(envelopes[sessionNumber]);
        cookieNumber = getSessionTurn(cookies.length);
        String cookie = cookies[cookieNumber];
        if (httpSession) {
            setSessionID(messageContext, cookie);
        }
        try {
            OperationClient op = client.createClient(ServiceClient.ANON_OUT_IN_OP);
            op.addMessageContext(messageContext);
            op.execute(true);

            MessageContext responseContext =
                op.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
            String receivedCookie = extractSessionID(responseContext);
            String receivedSetCookie = getSetCookieHeader(responseContext);
            if (httpSession) {

                if (receivedSetCookie != null && !"".equals(receivedSetCookie)) {
                    cookies[cookieNumber] = receivedCookie;
                }
            }

            SOAPEnvelope responseEnvelope = responseContext.getEnvelope();

            OMElement vElement =
                responseEnvelope.getBody().getFirstChildWithName(new QName("Value"));
            if (log.isDebugEnabled()) {
                log.debug(
                    "Request: " + i + " with Session ID: " + (httpSession ? cookie : sessionNumber) + " ---- " +
                    "Response : with  " + (httpSession && receivedCookie != null ?
                                           (receivedSetCookie != null ? receivedSetCookie : receivedCookie) :
                                           " ") + " " + vElement.getText());
            }

            responseList
                .add(new ResponseData(true, "" + (httpSession ? cookie : sessionNumber), vElement.getText()));

        } catch (AxisFault axisFault) {
            if (log.isDebugEnabled()) {
                log.debug("Request with session id " + (httpSession ? cookie : sessionNumber), axisFault);
            }

            responseList.add(
                new ResponseData(false, "" + (httpSession ? cookie : sessionNumber), axisFault.getMessage()));
        }
    }

    return responseList;
}
 
Example 11
Source File: MutualSSLAuthenticator.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isHandle(MessageContext msgCxt) {
    boolean canHandle = false;

    if (!isDisabled()) {

        if (!authenticatorInitialized) {
            init();
            if (!authenticatorInitialized) {
                return canHandle;
            }
        }

        HttpServletRequest request = (HttpServletRequest) msgCxt.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
        String authorizationHeader = request.getHeader(HTTPConstants.HEADER_AUTHORIZATION);
        // This authenticator should kickin only if authorization headers are null
        if (authorizationHeader == null) {
            Object certObject = request.getAttribute(JAVAX_SERVLET_REQUEST_CERTIFICATE);
            if (certObject != null) {
                SOAPEnvelope envelope = msgCxt.getEnvelope();
                SOAPHeader header = envelope.getHeader();
                boolean validHeader = false;

                if (header != null) {
                    List<SOAPHeaderBlock> headers = header.getHeaderBlocksWithNSURI(MUTUAL_SSL_URL);
                    if (headers != null) {
                        for (SOAPHeaderBlock soapHeaderBlock : headers) {
                            if (usernameHeaderName.equals(soapHeaderBlock.getLocalName())) {
                                //Username can be in SOAP Header
                                canHandle = true;
                                validHeader = true;
                                break;
                            }
                        }
                    }
                }

                if (!canHandle && StringUtils.isNotEmpty(request.getHeader(usernameHeaderName))) {
                    validHeader = true;
                    // Username is received in HTTP Header
                    canHandle = true;
                }

                if (!validHeader && log.isDebugEnabled()) {
                    log.debug("'" + usernameHeaderName + "'" + " header is not received in HTTP or SOAP header");
                }

            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Server is not picking up the client certificate. Mutual SSL authentication is not" +
                            "done");
                }
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("MutualSSLAuthenticator is Disabled.");
        }
    }
    return canHandle;
}
 
Example 12
Source File: InOnlyMEPHandler.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
@Override
// Handle IN_ONLY operations
public void flowComplete(MessageContext msgContext) {
    if (msgContext.getEnvelope() == null) {
        return;
    }
    AxisService axisService = msgContext.getAxisService();
    if (axisService == null ||
        SystemFilter.isFilteredOutService(axisService.getAxisServiceGroup()) ||
        axisService.isClientSide()) {
        return;
    }

    try {
        // Process Request Counter
        OperationContext opContext = msgContext.getOperationContext();
        if (opContext != null && opContext.isComplete()) {
            AxisOperation axisOp = opContext.getAxisOperation();
            if (axisOp != null && axisOp.isControlOperation()) {
                return;
            }
            if (axisOp != null) {
                String mep = axisOp.getMessageExchangePattern();
                if (mep != null &&
                    (mep.equals(WSDL2Constants.MEP_URI_IN_ONLY) ||
                     mep.equals(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY))) {

                    // Increment operation counter
                    final AxisOperation axisOperation = msgContext.getAxisOperation();
                    if (axisOperation != null) {
                        Parameter operationParameter =
                                axisOperation.getParameter(StatisticsConstants.IN_OPERATION_COUNTER);
                        if (operationParameter != null) {
                            ((AtomicInteger) operationParameter.getValue()).incrementAndGet();
                        } else {
                            log.error(StatisticsConstants.IN_OPERATION_COUNTER +
                                      " has not been set for operation " +
                                      axisService.getName() + "." + axisOperation.getName());
                            return;
                        }

                        // Calculate response times
                        try {
                            ResponseTimeCalculator.calculateResponseTimes(msgContext);
                        } catch (AxisFault axisFault) {
                            log.error("Cannot compute response times", axisFault);
                        }
                    }

                    // Increment global counter
                    Parameter globalRequestCounter =
                            msgContext.getParameter(StatisticsConstants.GLOBAL_REQUEST_COUNTER);
                    ((AtomicInteger) globalRequestCounter.getValue()).incrementAndGet();

                    updateCurrentInvocationGlobalStatistics(msgContext);
                }
            }
        }
    } catch (Throwable e) {  // Catching Throwable since exceptions here should not be propagated up
        log.error("Could not call InOnlyMEPHandler.flowComplete", e);
    }
}
 
Example 13
Source File: InOutMEPHandler.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
public InvocationResponse invoke(MessageContext outMsgContext) throws AxisFault {
    if(outMsgContext.getEnvelope() == null){
        return InvocationResponse.CONTINUE;
    }
    if (outMsgContext.getFLOW() != MessageContext.OUT_FLOW &&
        outMsgContext.getFLOW() != MessageContext.OUT_FAULT_FLOW) {
        log.error("InOutMEPHandler not deployed in OUT/OUT_FAULT flow. Flow: " +
                  outMsgContext.getFLOW());
        return InvocationResponse.CONTINUE;
    }
    try {
        AxisService axisService = outMsgContext.getAxisService();
        if(axisService == null) {
           updateStatistics(outMsgContext);
           return InvocationResponse.CONTINUE;
       } else if (SystemFilter.isFilteredOutService(axisService.getAxisServiceGroup()) ||
           axisService.isClientSide()) {
           return InvocationResponse.CONTINUE;
       }

        final AxisOperation axisOperation = outMsgContext.getAxisOperation();
        if(axisOperation != null && axisOperation.isControlOperation()){
            return InvocationResponse.CONTINUE;
        }
        if (axisOperation != null) {
            String mep = axisOperation.getMessageExchangePattern();
            if (mep != null &&
                (mep.equals(WSDL2Constants.MEP_URI_OUT_IN) ||
                    mep.equals(WSDL2Constants.MEP_URI_OUT_ONLY) ||
                    mep.equals(WSDL2Constants.MEP_URI_OUT_OPTIONAL_IN))) { // If this ConfigurationContext is used for sending messages out, do not change the stats
                return InvocationResponse.CONTINUE;
            }
            // Process operation request count
            Parameter inOpCounter =
                axisOperation.getParameter(StatisticsConstants.IN_OPERATION_COUNTER);
            if (inOpCounter != null) {
                ((AtomicInteger) inOpCounter.getValue()).incrementAndGet();
            } else {
                log.error(StatisticsConstants.IN_OPERATION_COUNTER +
                          " has not been set for operation " +
                          axisService.getName() + "." + axisOperation.getName());
                return InvocationResponse.CONTINUE;
            }

            // Process operation response count
            Parameter outOpCounter =
                axisOperation.getParameter(StatisticsConstants.OUT_OPERATION_COUNTER);
            if (outOpCounter != null) {
                ((AtomicInteger) outOpCounter.getValue()).incrementAndGet();
            } else {
                log.error(StatisticsConstants.OUT_OPERATION_COUNTER +
                          " has not been set for operation " +
                          axisService.getName() + "." + axisOperation.getName());
                return InvocationResponse.CONTINUE;
            }
        }
        updateStatistics(outMsgContext);
    } catch (Throwable e) {
        log.error("Could not call InOutMEPHandler.invoke", e);
     }
    return InvocationResponse.CONTINUE;
}