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

The following examples show how to use org.apache.axis2.context.MessageContext#setProperty() . 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: ResponseTimeCalculator.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private static void updateCurrentInvocationStatistic(MessageContext messageContext,
                                                     long responseTime) throws AxisFault {
    messageContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_INVOCATION_RESPONSE_TIME,responseTime);

    if (messageContext.getAxisOperation() != null) {
        Parameter operationResponseTimeParam = new Parameter();
        operationResponseTimeParam.setName(StatisticsConstants.OPERATION_RESPONSE_TIME);
        operationResponseTimeParam.setValue(responseTime);
        messageContext.getAxisOperation().addParameter(operationResponseTimeParam);
    }

    if (messageContext.getAxisService() != null) {
        Parameter serviceResponseTimeParam = new Parameter();
        serviceResponseTimeParam.setName(StatisticsConstants.SERVICE_RESPONSE_TIME);
        serviceResponseTimeParam.setValue(responseTime);
        messageContext.getAxisService().addParameter(serviceResponseTimeParam);
    }
}
 
Example 2
Source File: DBInOnlyMessageReceiver.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Invokes the business logic invocation on the service implementation
 * class
 *
 * @param msgContext
 *            the incoming message context
 * @throws AxisFault
 *             on invalid method (wrong signature) or behavior (return
 *             null)
 */
public void invokeBusinessLogic(MessageContext msgContext) throws AxisFault {
	try {
		if (log.isDebugEnabled()) {
			log.debug("Request received to DSS:  Data Service - " + msgContext.getServiceContext().getName() +
			          ", Operation - " + msgContext.getSoapAction() + ", Request body - " +
			          msgContext.getEnvelope().getText() + ", ThreadID - " + Thread.currentThread().getId());
		}
                       DataServiceProcessor.dispatch(msgContext);
                       msgContext.setProperty(DBConstants.TENANT_IN_ONLY_MESSAGE, Boolean.TRUE);
               } catch (Exception e) {
		log.error("Error in in-only message receiver", e);
		msgContext.setProperty(Constants.FAULT_NAME, DBConstants.DS_FAULT_NAME);
		throw DBUtils.createAxisFault(e);
	} finally {
		if (log.isDebugEnabled()) {
			log.debug("Request processing completed from DSS: Data Service - " +
			          msgContext.getServiceContext().getName() + ", Operation - " + msgContext.getSoapAction() +
			          ", ThreadID - " + Thread.currentThread().getId());
		}
	}
}
 
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: IntegratorStatefulHandler.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Finds axis Service and the Operation for DSS requests
 *
 * @param msgContext request message context
 * @throws AxisFault if any exception occurs while finding axis service or operation
 */
private static void dispatchAndVerify(MessageContext msgContext) throws AxisFault {
    requestDispatcher.invoke(msgContext);
    AxisService axisService = msgContext.getAxisService();
    if (axisService != null) {
        httpLocationBasedDispatcher.invoke(msgContext);
        if (msgContext.getAxisOperation() == null) {
            requestURIOperationDispatcher.invoke(msgContext);
        }

        AxisOperation axisOperation;
        if ((axisOperation = msgContext.getAxisOperation()) != null) {
            AxisEndpoint axisEndpoint =
                    (AxisEndpoint) msgContext.getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
            if (axisEndpoint != null) {
                AxisBindingOperation axisBindingOperation = (AxisBindingOperation) axisEndpoint
                        .getBinding().getChild(axisOperation.getName());
                msgContext.setProperty(Constants.AXIS_BINDING_OPERATION, axisBindingOperation);
            }
            msgContext.setAxisOperation(axisOperation);
        }
    }
}
 
Example 5
Source File: MsgContextHandler.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * This method gets the JWT token from the transport header, and extracts the user name from the JWT and
 * sets it to the message context.
 *
 * @param arg0
 */
public InvocationResponse invoke(MessageContext arg0) throws AxisFault {
    HttpServletRequest obj = (HttpServletRequest) arg0.
            getProperty(HTTP_SERVLET_REQUEST);

    if (obj != null) {
        //Get the "username" from the header.
        String username = obj.getHeader(USERNAME);
        arg0.setProperty(USERNAME, username);

        log.debug("********************** Username from msgcontext - "+arg0.getProperty(USERNAME));
    }
    return InvocationResponse.CONTINUE;
}
 
Example 6
Source File: TopicMapService.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
public void setOutputType(String outputType){
    if(outputType!=null){
        try{
            MessageContext outMsgCtx = MessageContext.getCurrentMessageContext().getOperationContext().getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
            outMsgCtx.setProperty(Constants.Configuration.MESSAGE_TYPE, outputType);
        }catch(Exception e){e.printStackTrace();}
    }
}
 
Example 7
Source File: InOutMEPHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 *  This method is used to update current request statistic , this statistics useful for bam to define SLAs using CEP
 *          RequestCount =1
 *         ResponseCount = 1
 *         FaultCount = 0
 * @param outMsgContext
 */
private void updateCurrentInvocationGlobalStatistics(MessageContext outMsgContext) throws AxisFault {

    //Set request count 1
    outMsgContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_REQUEST_COUNTER,1);

    //Set response count 1
    outMsgContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_RESPONSE_COUNTER,1);

    //Set fault count 0
    outMsgContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_FAULT_COUNTER,0);
}
 
Example 8
Source File: InOnlyMEPHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * This method is used to update current request statistic
 *
 * @param msgContext
 */
private void updateCurrentInvocationGlobalStatistics(MessageContext msgContext) {
    //Set request count 1
    msgContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_REQUEST_COUNTER,1);

    //Set response count 0
    msgContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_RESPONSE_COUNTER,0);

    //Set fault count 0
    msgContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_FAULT_COUNTER,0);

}
 
Example 9
Source File: LoadbalanceFailoverClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
protected void setSessionID(MessageContext axis2MessageContext, String value) {

        if (value == null) {
            return;
        }
        Map map = (Map) axis2MessageContext.getProperty(HTTPConstants.HTTP_HEADERS);
        if (map == null) {
            map = new HashMap();
            axis2MessageContext.setProperty(HTTPConstants.HTTP_HEADERS, map);
        }
        map.put(COOKIE, value);
    }
 
Example 10
Source File: LoadBalanceSessionFullClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
protected void setSessionID(MessageContext axis2MessageContext, String value) {

        if (value == null) {
            return;
        }
        Map map = (Map) axis2MessageContext.getProperty(HTTPConstants.HTTP_HEADERS);
        if (map == null) {
            map = new HashMap();
            axis2MessageContext.setProperty(HTTPConstants.HTTP_HEADERS, map);
        }
        map.put(COOKIE, value);
    }
 
Example 11
Source File: MsgContextHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method gets the JWT token from the transport header, and extracts the user name from the JWT and
 * sets it to the message context.
 *
 * @param arg0
 */
public InvocationResponse invoke(MessageContext arg0) throws AxisFault {
    HttpServletRequest obj = (HttpServletRequest) arg0.
            getProperty(HTTP_SERVLET_REQUEST);

    if (obj != null) {
        //Get the "username" from the header.
        String username = obj.getHeader(USERNAME);
        arg0.setProperty(USERNAME, username);

        log.debug("********************** Username from msgcontext - " + arg0.getProperty(USERNAME));
    }
    return InvocationResponse.CONTINUE;
}
 
Example 12
Source File: RabbitMQInjectHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the message builder to use, set the message payload to the message context and
 * inject the message.
 *
 * @param properties  the AMQP basic properties
 * @param body        the message body
 * @param inboundName Inbound Name
 * @return delivery status of the message
 */
public boolean onMessage(AMQP.BasicProperties properties, byte[] body, String inboundName) {
    org.apache.synapse.MessageContext msgCtx = createMessageContext();
    try {
        MessageContext axis2MsgCtx = ((org.apache.synapse.core.axis2.Axis2MessageContext) msgCtx)
                .getAxis2MessageContext();
        RabbitMQUtils.buildMessage(properties, body, axis2MsgCtx);
        axis2MsgCtx.setProperty(MessageContext.TRANSPORT_HEADERS, RabbitMQUtils.getTransportHeaders(properties));

        if (seq != null) {
            if (log.isDebugEnabled()) {
                log.debug("injecting message to sequence : " + injectingSeq);
            }
            seq.setErrorHandler(onErrorSeq);
            msgCtx.setProperty(SynapseConstants.IS_INBOUND, true);
            msgCtx.setProperty(SynapseConstants.INBOUND_ENDPOINT_NAME, inboundName);
            msgCtx.setProperty(SynapseConstants.ARTIFACT_NAME,
                               SynapseConstants.FAIL_SAFE_MODE_INBOUND_ENDPOINT + inboundName);
            synapseEnvironment.injectInbound(msgCtx, seq, sequential);
        } else {
            log.error("Sequence: " + injectingSeq + " not found");
        }

        Object rollbackProperty = msgCtx.getProperty(RabbitMQConstants.SET_ROLLBACK_ONLY);
        if ((rollbackProperty instanceof Boolean && ((Boolean) rollbackProperty)) ||
            (rollbackProperty instanceof String && Boolean.parseBoolean((String) rollbackProperty))) {
            return false;
        }

    } catch (AxisFault axisFault) {
        log.error("Error when trying to read incoming message ...", axisFault);
        return false;
    }
    return true;
}
 
Example 13
Source File: FileInjectHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Create the initial message context for the file
 */
private org.apache.synapse.MessageContext createMessageContext() {

    org.apache.synapse.MessageContext msgCtx = synapseEnvironment.createMessageContext();
    MessageContext axis2MsgCtx = ((org.apache.synapse.core.axis2.Axis2MessageContext) msgCtx)
            .getAxis2MessageContext();
    axis2MsgCtx.setServerSide(true);
    axis2MsgCtx.setMessageID(UUIDGenerator.getUUID());
    axis2MsgCtx.setProperty(MessageContext.TRANSPORT_HEADERS, transportHeaders);
    msgCtx.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, true);
    return msgCtx;
}
 
Example 14
Source File: LoadbalanceFailoverClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
protected void setSessionID(MessageContext axis2MessageContext, String value) {

        if (value == null) {
            return;
        }
        Map map = (Map) axis2MessageContext.getProperty(HTTPConstants.HTTP_HEADERS);
        if (map == null) {
            map = new HashMap();
            axis2MessageContext.setProperty(HTTPConstants.HTTP_HEADERS, map);
        }
        map.put(COOKIE, value);
    }
 
Example 15
Source File: LoadbalanceFailoverClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
protected void setSessionID(MessageContext axis2MessageContext, String value) {

        if (value == null) {
            return;
        }
        Map map = (Map) axis2MessageContext.getProperty(HTTPConstants.HTTP_HEADERS);
        if (map == null) {
            map = new HashMap();
            axis2MessageContext.setProperty(HTTPConstants.HTTP_HEADERS, map);
        }
        map.put(COOKIE, value);
    }
 
Example 16
Source File: GRPCInjectHandler.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private void initiateSequenceAndInjectPayload(StreamObserver responseObserver,
                                              Event receivedEvent,
                                              org.apache.synapse.MessageContext msgCtx) throws AxisFault {
    String msgPayload = receivedEvent.getPayload();
    String sequenceName = receivedEvent.getHeadersMap().get(InboundGRPCConstants.HEADER_MAP_SEQUENCE_PARAMETER_NAME);
    SequenceMediator seq;
    if (sequenceName != null) {
        if (log.isDebugEnabled()) {
            log.debug(sequenceName + " sequence, received via gRPC headers.");
        }
        seq = (SequenceMediator) synapseEnvironment.getSynapseConfiguration().getSequence(sequenceName);
    } else {
        if (injectingSeq == null || injectingSeq.isEmpty()) {
            log.error("Sequence name is not specified in inbound endpoint or empty.");
            return;
        }
        if (log.isDebugEnabled()) {
            log.debug(injectingSeq + " sequence, received via the inbound endpoint.");
        }
        seq = (SequenceMediator) synapseEnvironment.getSynapseConfiguration().getSequence(injectingSeq);
    }
    msgCtx.setProperty(SynapseConstants.IS_INBOUND, true);
    //validating the sequence
    if (seq != null) {
        if (!seq.isInitialized()) {
            seq.init(synapseEnvironment);
        }
        seq.setErrorHandler(onErrorSeq);
        if (log.isDebugEnabled()) {
            log.debug("injecting received gRPC message to sequence : " + injectingSeq);
        }
        if (!synapseEnvironment.injectInbound(msgCtx, seq, this.sequential)) {
            return;
        }
    } else {
        log.error("Sequence: " + injectingSeq + " not found");
    }
    MessageContext axis2MsgCtx =
            ((org.apache.synapse.core.axis2.Axis2MessageContext) msgCtx).getAxis2MessageContext();
    //setting transport headers
    axis2MsgCtx.setProperty(MessageContext.TRANSPORT_HEADERS, receivedEvent.getHeadersMap());
    String contentType = receivedEvent.getHeadersMap().
            get(InboundGRPCConstants.HEADER_MAP_CONTENT_TYPE_PARAMETER_NAME);
    if (log.isDebugEnabled()) {
        log.debug(contentType + " Content-Type, received via the gRPC headers.");
    }
    // Determine the message builder to use
    if (contentType != null) {
        if (InboundGRPCConstants.CONTENT_TYPE_JSON.equalsIgnoreCase(contentType)) {
            contentType = InboundGRPCConstants.CONTENT_TYPE_JSON_MIME_TYPE;
        } else if (InboundGRPCConstants.CONTENT_TYPE_XML.equalsIgnoreCase(contentType)) {
            contentType = InboundGRPCConstants.CONTENT_TYPE_XML_MIME_TYPE;
        } else if (InboundGRPCConstants.CONTENT_TYPE_TEXT.equalsIgnoreCase(contentType)) {
            contentType = InboundGRPCConstants.CONTENT_TYPE_TEXT_MIME_TYPE;
        } else {
            log.error("Error occurred when processing gRPC message. " + contentType +
                    " type found in gRPC header is not supported");
            responseObserver.onError(
                    new Throwable("Error occurred when processing gRPC message. " + contentType +
                            " type found in gRPC header is not supported"));
            return;
        }
    } else {
        log.error("Invalid content type found in gRPC header. JSON, XML and text is supported");
        responseObserver.onError(
                new Throwable("Invalid content type found in gRPC header. JSON, XML and text is supported"));
        return;
    }

    Builder builder = BuilderUtil.getBuilderFromSelector(contentType, axis2MsgCtx);
    OMElement documentElement;
    // set the message payload to the message context
    InputStream in = null;
    try {
        in = new AutoCloseInputStream(new ByteArrayInputStream(msgPayload.getBytes()));
        documentElement = builder.processDocument(in, contentType, axis2MsgCtx);
    } catch (AxisFault ex) {
        // Handle message building error
        log.error("Error while building the message", ex);
        return;
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                log.error("Exception occurred when closing InputStream when reading messagePayload.", e);
            }
        }
    }
    // Inject the message to the sequence.
    msgCtx.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
 
Example 17
Source File: DBInOutMessageReceiver.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
/**
 * Invokes the business logic invocation on the service implementation class
 * 
 * @param msgContext
 *            the incoming message context
 * @param newMsgContext
 *            the response message context
 * @throws AxisFault
 *             on invalid method (wrong signature) or behavior (return null)
 */
public void invokeBusinessLogic(MessageContext msgContext,
		MessageContext newMsgContext) throws AxisFault {
	try {
		if (log.isDebugEnabled()) {
			log.debug("Request received to DSS:  Data Service - " + msgContext.getServiceContext().getName() +
			          ", Operation - " + msgContext.getSoapAction() + ", Request body - " +
			          msgContext.getEnvelope().getText() + ", ThreadID - " + Thread.currentThread().getId());
		}
		boolean isAcceptJson = false;
		Map transportHeaders = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
		if (transportHeaders != null) {
			String acceptHeader = (String) transportHeaders.get(HTTPConstants.HEADER_ACCEPT);
			if (acceptHeader != null) {
				int index = acceptHeader.indexOf(";");
				if (index > 0) {
					acceptHeader = acceptHeader.substring(0, index);
				}
				String[] strings = acceptHeader.split(",");
				for (String string : strings) {
					String accept = string.trim();
					AxisConfiguration configuration = msgContext.getConfigurationContext().getAxisConfiguration();
					if (HTTPConstants.MEDIA_TYPE_APPLICATION_JSON.equals(accept)
							&& configuration.getMessageFormatter(accept) != null) {
						isAcceptJson = true;
						break;
					}
				}
			}
		}
		OMElement result = DataServiceProcessor.dispatch(msgContext);
		SOAPFactory fac = getSOAPFactory(msgContext);
		SOAPEnvelope envelope = fac.getDefaultEnvelope();
		if (result != null) {
			envelope.getBody().addChild(result);
		}
		newMsgContext.setEnvelope(envelope);
		if (isAcceptJson) {
			newMsgContext.setProperty(Constants.Configuration.MESSAGE_TYPE,
					HTTPConstants.MEDIA_TYPE_APPLICATION_JSON);
		}
	} catch (Exception e) {
		log.error("Error in in-out message receiver", e);
		msgContext.setProperty(Constants.FAULT_NAME, DBConstants.DS_FAULT_NAME);
		throw DBUtils.createAxisFault(e);
	} finally {
		if (log.isDebugEnabled()) {
			String response;
			if (msgContext.getProperty(Constants.FAULT_NAME) != null &&
			    msgContext.getProperty(Constants.FAULT_NAME).equals(DBConstants.DS_FAULT_NAME)) {
				response = "Error in Response";
			} else {
				response = newMsgContext.getEnvelope().getText();
			}
			log.debug("Response send from DSS:  Data Service - " + msgContext.getServiceContext().getName() +
			          ", Operation - " + msgContext.getSoapAction() + ", Response body - " + response +
			          ", ThreadID - " + Thread.currentThread().getId());
		}
	}
}
 
Example 18
Source File: TracingMessageInObservationHandler.java    From carbon-commons with Apache License 2.0 4 votes vote down vote up
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
    msgContext.setProperty(TracerConstants.TEMP_IN_ENVELOPE,
                           msgContext.getEnvelope().cloneOMElement());
    return InvocationResponse.CONTINUE;
}
 
Example 19
Source File: FaultHandler.java    From carbon-commons with Apache License 2.0 3 votes vote down vote up
/**
 *  This method is used to update current request statistic , this statistics useful for bam to define SLAs using CEP
 *          RequestCount =1
 *         ResponseCount = 0
 *         FaultCount = 1
 * @param msgContext
 */
private void updateCurrentInvocationGlobalStatistics(MessageContext msgContext) throws AxisFault{

    //Set request count 1
    msgContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_REQUEST_COUNTER,1);

    //Set response count 0
    msgContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_RESPONSE_COUNTER,0);

    //Set fault count 1
    msgContext.setProperty(StatisticsConstants.GLOBAL_CURRENT_FAULT_COUNTER,1);

}
 
Example 20
Source File: InboundHttpServerWorker.java    From micro-integrator with Apache License 2.0 2 votes vote down vote up
/**
 * Set Inbound Related Properties for Axis2 Message Context
 *
 * @param axis2Context Axis2 Message Context of incoming request
 */
private void setInboundProperties(MessageContext axis2Context) {
    axis2Context.setProperty(SynapseConstants.IS_INBOUND, true);
}