Java Code Examples for org.apache.cxf.message.MessageContentsList#getContentsList()

The following examples show how to use org.apache.cxf.message.MessageContentsList#getContentsList() . 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: WSS4JEetOutInterceptor.java    From eet-client with MIT License 6 votes vote down vote up
@Override
public void handleMessage(SoapMessage message) throws Fault {
	super.handleMessage(message);

	MessageContentsList contents = MessageContentsList.getContentsList(message);
	if (contents != null && contents.size() == 1) {
		Object requestObj = contents.get(0);
		if (requestObj instanceof TrzbaType) {
			TrzbaType request = (TrzbaType) requestObj;
			TrzbaHlavickaType header = request.getHlavicka();

			// validation is required if getOvereni is unspecified or false.
			boolean required = header == null || !Boolean.TRUE.equals(header.getOvereni());
			message.getExchange().put(WSS4JEetInInterceptor.PROP_SIGNATURE_REQUIRED, required);
		}
	}

}
 
Example 2
Source File: SamlFormOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected Form getRequestForm(Message message) {
    Object ct = message.get(Message.CONTENT_TYPE);
    if (ct == null || !MediaType.APPLICATION_FORM_URLENCODED.equalsIgnoreCase(ct.toString())) {
        return null;
    }
    MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs != null && objs.size() == 1) {
        Object obj = objs.get(0);
        if (obj instanceof Form) {
            return (Form)obj;
        } else if (obj instanceof MultivaluedMap) {
            return new Form((MultivaluedMap<String, String>)obj);
        }
    }
    return null;
}
 
Example 3
Source File: AbstractClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void handleMessage(Message outMessage) throws Fault {
    MessageContentsList objs = MessageContentsList.getContentsList(outMessage);
    if (objs == null || objs.isEmpty()) {
        return;
    }

    OutputStream os = outMessage.getContent(OutputStream.class);
    if (os == null) {
        XMLStreamWriter writer = outMessage.getContent(XMLStreamWriter.class);
        if (writer == null) {
            return;
        }
    }

    Object body = objs.get(0);
    Annotation[] customAnns = (Annotation[])outMessage.get(Annotation.class.getName());
    Type t = outMessage.get(Type.class);
    doWriteBody(outMessage, body, t, customAnns, os);
}
 
Example 4
Source File: AbstractValidationInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void handleMessage(Message message) {
    final Object theServiceObject = getServiceObject(message);
    if (theServiceObject == null) {
        return;
    }

    final Method method = getServiceMethod(message);
    if (method == null) {
        return;
    }
    
    ValidateOnExecution validateOnExec = method.getAnnotation(ValidateOnExecution.class);
    if (validateOnExec != null) {
        ExecutableType[] execTypes = validateOnExec.type();
        if (execTypes.length == 1 && execTypes[0] == ExecutableType.NONE) {
            return;
        }
    }


    final List< Object > arguments = MessageContentsList.getContentsList(message);

    handleValidation(message, theServiceObject, method, arguments);

}
 
Example 5
Source File: CustomHandler.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void handleMessage(final Message message) throws Fault {
    if (isResponseAlreadyHandled(message)) {
        return;
    }
    final MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return;
    }

    final Object responseObj = objs.get(0);
    if (Response.class.isInstance(responseObj)) {
        final Response response = Response.class.cast(responseObj);
        if (is404(message, response)) {
            switchResponse(message);
        }
    } else {
        final Object exchangeStatus = message.getExchange().get(Message.RESPONSE_CODE);
        final int status = exchangeStatus != null ? Integer.class.cast(exchangeStatus) : HttpsURLConnection.HTTP_OK;
        if (status == HttpsURLConnection.HTTP_NOT_FOUND) {
            switchResponse(message);
        }
    }
}
 
Example 6
Source File: SignatureFaultInterceptor.java    From eet-client with MIT License 5 votes vote down vote up
@Override
public void handleMessage(SoapMessage message) throws Fault {
	if (message.getExchange().containsKey(WSS4JEetInInterceptor.PROP_SIGNATURE_ERROR)) {
		MessageContentsList contents = MessageContentsList.getContentsList(message);
		OdpovedType response = (OdpovedType) contents.get(0);
		OdpovedChybaType error = response.getChyba();

		if (error == null || error.getKod() == ERR_CODE_NO_ERROR) {
			throw (Fault) message.getExchange().get(WSS4JEetInInterceptor.PROP_SIGNATURE_ERROR);
		}
	}
}
 
Example 7
Source File: ValidationInterceptor.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message message) throws Fault {
    final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
    if (operationResource == null) {
        log.info("OperationResourceInfo is not available, skipping validation");
        return;
    }

    final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
    if (classResource == null) {
        log.info("ClassResourceInfo is not available, skipping validation");
        return;
    }

    final ResourceProvider resourceProvider = classResource.getResourceProvider();
    if (resourceProvider == null) {
        log.info("ResourceProvider is not available, skipping validation");
        return;
    }

    final List<Object> arguments = MessageContentsList.getContentsList(message);
    final Method method = operationResource.getAnnotatedMethod();
    final Object instance = resourceProvider.getInstance(message);
    if (method != null && arguments != null) {
        //validate the parameters(arguments) over the invoked method
        validate(method, arguments.toArray(), instance);

        //validate the fields of each argument
        for (Object arg : arguments) {
            if (arg != null)
                validate(arg);
        }
    }

}
 
Example 8
Source File: ValidationInterceptor.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message message) throws Fault {
    final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
    if (operationResource == null) {
        log.info("OperationResourceInfo is not available, skipping validation");
        return;
    }

    final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
    if (classResource == null) {
        log.info("ClassResourceInfo is not available, skipping validation");
        return;
    }

    final ResourceProvider resourceProvider = classResource.getResourceProvider();
    if (resourceProvider == null) {
        log.info("ResourceProvider is not available, skipping validation");
        return;
    }

    final List<Object> arguments = MessageContentsList.getContentsList(message);
    final Method method = operationResource.getAnnotatedMethod();
    final Object instance = resourceProvider.getInstance(message);
    if (method != null && arguments != null) {
        //validate the parameters(arguments) over the invoked method
        validate(method, arguments.toArray(), instance);

        //validate the fields of each argument
        for (Object arg : arguments) {
            if (arg != null)
                validate(arg);
        }
    }

}
 
Example 9
Source File: ValidationInInterceptor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {

        final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
        if (operationResource == null) {
            log.info("OperationResourceInfo is not available, skipping validation");
            return;
        }

        final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
        if (classResource == null) {
            log.info("ClassResourceInfo is not available, skipping validation");
            return;
        }

        final ResourceProvider resourceProvider = classResource.getResourceProvider();
        if (resourceProvider == null) {
            log.info("ResourceProvider is not available, skipping validation");
            return;
        }

        final List<Object> arguments = MessageContentsList.getContentsList(message);
        final Method method = operationResource.getAnnotatedMethod();
        final Object instance = resourceProvider.getInstance(message);
        if (method != null && arguments != null) {
            //validate the parameters(arguments) over the invoked method
            validate(method, arguments.toArray(), instance);

            //validate the fields of each argument
            for (Object arg : arguments) {
                if (arg != null)
                    validate(arg);
            }
        }
    }
 
Example 10
Source File: AbstractXmlSecOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Object getRequestBody(Message message) {
    MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return null;
    }
    return objs.get(0);
}
 
Example 11
Source File: ClientRequestContextImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Object getMessageContent() {
    MessageContentsList objs = MessageContentsList.getContentsList(m);
    if (objs == null || objs.isEmpty()) {
        return null;
    }
    return objs.get(0);
}
 
Example 12
Source File: HTTPConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean isChunkingSupported(Message message, String httpMethod) {
    if (HTTP_POST_METHOD.equals(httpMethod)) {
        return true;
    } else if (!HTTP_GET_METHOD.equals(httpMethod)) {
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        if (objs != null && !objs.isEmpty()) {
            Object obj = objs.get(0);
            return obj.getClass() != String.class
                || (obj.getClass() == String.class && ((String)obj).length() > 0);
        }
    }
    return false;
}
 
Example 13
Source File: BareOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    Exchange exchange = message.getExchange();
    BindingOperationInfo operation = exchange.getBindingOperationInfo();

    if (operation == null) {
        return;
    }

    MessageContentsList objs = MessageContentsList.getContentsList(message);
    if (objs == null || objs.isEmpty()) {
        return;
    }

    List<MessagePartInfo> parts = null;
    BindingMessageInfo bmsg = null;
    boolean client = isRequestor(message);

    if (!client) {
        if (operation.getOutput() != null) {
            bmsg = operation.getOutput();
            parts = bmsg.getMessageParts();
        } else {
            // partial response to oneway
            return;
        }
    } else {
        bmsg = operation.getInput();
        parts = bmsg.getMessageParts();
    }

    writeParts(message, exchange, operation, objs, parts);
}
 
Example 14
Source File: WrapperClassOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();

    MessageInfo messageInfo = message.get(MessageInfo.class);
    if (messageInfo == null || bop == null || !bop.isUnwrapped()) {
        return;
    }

    BindingOperationInfo newbop = bop.getWrappedOperation();
    MessageInfo wrappedMsgInfo;
    if (Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE))) {
        wrappedMsgInfo = newbop.getInput().getMessageInfo();
    } else {
        wrappedMsgInfo = newbop.getOutput().getMessageInfo();
    }

    Class<?> wrapped = null;
    if (wrappedMsgInfo.getMessagePartsNumber() > 0) {
        wrapped = wrappedMsgInfo.getFirstMessagePart().getTypeClass();
    }

    if (wrapped != null) {
        MessagePartInfo firstMessagePart = wrappedMsgInfo.getFirstMessagePart();
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        WrapperHelper helper = firstMessagePart.getProperty("WRAPPER_CLASS", WrapperHelper.class);
        if (helper == null) {
            helper = getWrapperHelper(message, messageInfo, wrappedMsgInfo, wrapped, firstMessagePart);
        }
        if (helper == null) {
            return;
        }

        try {
            MessageContentsList newObjs = new MessageContentsList();
            if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)
                && helper instanceof AbstractWrapperHelper) {
                ((AbstractWrapperHelper)helper).setValidate(true);
            }
            Object o2 = helper.createWrapperObject(objs);
            newObjs.put(firstMessagePart, o2);

            for (MessagePartInfo p : messageInfo.getMessageParts()) {
                if (Boolean.TRUE.equals(p.getProperty(ReflectionServiceFactoryBean.HEADER))) {
                    MessagePartInfo mpi = wrappedMsgInfo.getMessagePart(p.getName());
                    if (objs.hasValue(p)) {
                        newObjs.put(mpi, objs.get(p));
                    }
                }
            }

            message.setContent(List.class, newObjs);
        } catch (Fault f) {
            throw f;
        } catch (Exception e) {
            throw new Fault(e);
        }

        // we've now wrapped the object, so use the wrapped binding op
        ex.put(BindingOperationInfo.class, newbop);

        if (messageInfo == bop.getOperationInfo().getInput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getInput());
            message.put(BindingMessageInfo.class, newbop.getInput());
        } else if (messageInfo == bop.getOperationInfo().getOutput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getOutput());
            message.put(BindingMessageInfo.class, newbop.getOutput());
        }
    }
}