org.apache.cxf.message.MessageContentsList Java Examples

The following examples show how to use org.apache.cxf.message.MessageContentsList. 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: JAXRSInvoker.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Object handleFault(Fault ex, Message inMessage,
                           ClassResourceInfo cri, Method methodToInvoke) {
    String errorMessage = ex.getMessage();
    if (errorMessage != null && cri != null
        && errorMessage.contains(PROXY_INVOCATION_ERROR_FRAGMENT)) {
        org.apache.cxf.common.i18n.Message errorM =
            new org.apache.cxf.common.i18n.Message("PROXY_INVOCATION_FAILURE",
                                                   BUNDLE,
                                                   methodToInvoke,
                                                   cri.getServiceClass().getName());
        LOG.severe(errorM.toString());
    }
    Response excResponse =
        JAXRSUtils.convertFaultToResponse(ex.getCause() == null ? ex : ex.getCause(), inMessage);
    if (excResponse == null) {
        inMessage.getExchange().put(Message.PROPOGATE_EXCEPTION,
                                    ExceptionUtils.propogateException(inMessage));
        throw ex;
    }
    return new MessageContentsList(excResponse);
}
 
Example #3
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 #4
Source File: AbstractXmlSecOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    if (message.getExchange().get(Throwable.class) != null) {
        return;
    }
    try {
        Document doc = getDomDocument(message);
        if (doc == null) {
            return;
        }
        Document finalDoc = processDocument(message, doc);

        message.setContent(List.class,
            new MessageContentsList(new DOMSource(finalDoc)));
    } catch (Exception ex) {
        StringWriter sw = new StringWriter();
        ex.printStackTrace(new PrintWriter(sw));
        LOG.warning(sw.toString());
        throw new Fault(new RuntimeException(ex.getMessage() + ", stacktrace: " + sw.toString()));
    }
}
 
Example #5
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 #6
Source File: ClientRequestContextImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void doSetEntity(Object entity) {
    Object actualEntity = InjectionUtils.getEntity(entity);
    m.setContent(List.class, actualEntity == null ? new MessageContentsList()
        : new MessageContentsList(actualEntity));
    Type type = null;
    if (entity != null) {
        if (GenericEntity.class.isAssignableFrom(entity.getClass())) {
            type = ((GenericEntity<?>)entity).getType();
        } else {
            type = entity.getClass();
        }
        m.put(Type.class, type);
        m.remove("org.apache.cxf.empty.request");
    }

}
 
Example #7
Source File: JAXWSMethodInvokerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testFaultHeadersCopy() throws Throwable {
    ExceptionService serviceObject = new ExceptionService();
    Method serviceMethod = ExceptionService.class.getMethod("invoke", new Class[]{});

    Exchange ex = new ExchangeImpl();
    prepareInMessage(ex, true);
    Message msg = new MessageImpl();
    SoapMessage outMessage = new SoapMessage(msg);
    ex.setOutMessage(outMessage);

    JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);

    try {
        jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
        fail("Expected fault");
    } catch (Fault fault) {
        Message outMsg = ex.getOutMessage();
        assertNotNull(outMsg);
        @SuppressWarnings("unchecked")
        List<Header> headers = (List<Header>)outMsg.get(Header.HEADER_LIST);
        assertEquals(1, headers.size());
        assertEquals(TEST_HEADER_NAME, headers.get(0).getName());
    }
}
 
Example #8
Source File: JAXWSMethodInvokerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testFaultAvoidHeadersCopy() throws Throwable {
    ExceptionService serviceObject = new ExceptionService();
    Method serviceMethod = ExceptionService.class.getMethod("invoke", new Class[]{});

    Exchange ex = new ExchangeImpl();
    prepareInMessage(ex, false);


    JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
    try {
        jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
        fail("Expected fault");
    } catch (Fault fault) {
        Message outMsg = ex.getOutMessage();
        assertNull(outMsg);
    }
}
 
Example #9
Source File: JAXWSMethodInvokerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuspendedException() throws Throwable {
    Exception originalException = new RuntimeException();
    ContinuationService serviceObject =
        new ContinuationService(originalException);
    Method serviceMethod = ContinuationService.class.getMethod("invoke", new Class[]{});

    Exchange ex = new ExchangeImpl();
    Message inMessage = new MessageImpl();
    ex.setInMessage(inMessage);
    inMessage.setExchange(ex);
    inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);

    JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
    try {
        jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[]{}));
        fail("Suspended invocation swallowed");
    } catch (SuspendedInvocationException suspendedEx) {
        assertSame(suspendedEx, serviceObject.getSuspendedException());
        assertSame(originalException, suspendedEx.getRuntimeException());
    }
}
 
Example #10
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 #11
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 #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: DocLiteralInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void getPara(DepthXMLStreamReader xmlReader,
                     DataReader<XMLStreamReader> dr,
                     MessageContentsList parameters,
                     Iterator<MessagePartInfo> itr,
                     Message message) {

    boolean hasNext = true;
    while (itr.hasNext()) {
        MessagePartInfo part = itr.next();
        if (hasNext) {
            hasNext = StaxUtils.toNextElement(xmlReader);
        }
        Object obj = null;
        if (hasNext) {
            QName rname = xmlReader.getName();
            while (part != null
                && !rname.equals(part.getConcreteName())) {
                if (part.getXmlSchema() instanceof XmlSchemaElement) {
                    //TODO - should check minOccurs=0 and throw validation exception
                    //thing if the part needs to be here
                    parameters.put(part, null);
                }

                if (itr.hasNext()) {
                    part = itr.next();
                } else {
                    part = null;
                }
            }
            if (part == null) {
                return;
            }
            if (rname.equals(part.getConcreteName())) {
                obj = dr.read(part, xmlReader);
            }
        }
        parameters.put(part, obj);
    }
}
 
Example #14
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 #15
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 #16
Source File: StaxDataBindingInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    if (isGET(message) && message.getContent(List.class) != null) {
        LOG.fine("StaxDataBindingInterceptor skipped in HTTP GET method");
        return;
    }

    DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
    DataReader<XMLStreamReader> dr = getDataReader(message);
    MessageContentsList parameters = new MessageContentsList();

    Exchange exchange = message.getExchange();
    BindingOperationInfo bop = exchange.getBindingOperationInfo();

    //if body is empty and we have BindingOperationInfo, we do not need to match
    //operation anymore, just return
    if (!StaxUtils.toNextElement(xmlReader) && bop != null) {
        // body may be empty for partial response to decoupled request
        return;
    }

    if (bop == null) {
        Endpoint ep = exchange.getEndpoint();
        bop = ep.getBinding().getBindingInfo().getOperations().iterator().next();
    }

    message.getExchange().put(BindingOperationInfo.class, bop);

    if (isRequestor(message)) {
        parameters.put(bop.getOutput().getMessageParts().get(0), dr.read(xmlReader));
    } else {
        parameters.put(bop.getInput().getMessageParts().get(0), dr.read(xmlReader));
    }


    if (!parameters.isEmpty()) {
        message.setContent(List.class, parameters);
    }
}
 
Example #17
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 #18
Source File: CustomInvoker.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Object invoke(Exchange exchange, Object service, Method method, List<Object> arguments) {
	if (method.getName().equals("login")) {
		MessageContentsList mcl = (MessageContentsList) super.invoke(exchange, service, method, arguments);
		String token = (String) mcl.get(0);
		exchange.getSession().put("token", token);
		return mcl;
	} else {
		return super.invoke(exchange, service, method, arguments);
	}
}
 
Example #19
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 #20
Source File: RPCOutInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUp();
    ServiceInfo si = getMockedServiceModel(this.getClass()
                                           .getResource("/wsdl_soap/hello_world_rpc_lit.wsdl")
            .toString());
    BindingInfo bi = si.getBinding(new QName(TNS, "Greeter_SOAPBinding_RPCLit"));
    BindingOperationInfo boi = bi.getOperation(new QName(TNS, OPNAME));
    boi.getOperationInfo().getOutput().getMessagePartByIndex(0).setIndex(0);
    soapMessage.getExchange().put(BindingOperationInfo.class, boi);

    control.reset();
    Service service = control.createMock(Service.class);
    EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
    JAXBDataBinding dataBinding = new JAXBDataBinding(MyComplexStruct.class);
    service.getDataBinding();
    EasyMock.expectLastCall().andReturn(dataBinding).anyTimes();
    service.getServiceInfos();
    List<ServiceInfo> list = Arrays.asList(si);
    EasyMock.expectLastCall().andReturn(list).anyTimes();

    soapMessage.getExchange().put(Service.class, service);
    soapMessage.getExchange().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
    control.replay();

    MyComplexStruct mcs = new MyComplexStruct();
    mcs.setElem1("elem1");
    mcs.setElem2("elem2");
    mcs.setElem3(45);
    MessageContentsList param = new MessageContentsList();
    param.add(mcs);
    soapMessage.setContent(List.class, param);
}
 
Example #21
Source File: ColocUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void convertSourceToObject(Message message) {
    List<Object> content = CastUtils.cast(message.getContent(List.class));
    if (content == null || content.isEmpty()) {
        // nothing to convert
        return;
    }
    // only supporting the wrapped style for now  (one pojo <-> one source)
    Source source = (Source)content.get(0);
    DataReader<XMLStreamReader> reader =
        message.getExchange().getService().getDataBinding().createReader(XMLStreamReader.class);
    MessagePartInfo mpi = getMessageInfo(message).getMessagePart(0);
    XMLStreamReader streamReader = null;
    Object wrappedObject = null;
    try {
        streamReader = StaxUtils.createXMLStreamReader(source);
        wrappedObject = reader.read(mpi, streamReader);
    } finally {
        try {
            StaxUtils.close(streamReader);
        } catch (XMLStreamException e) {
            // Ignore
        }
    }
    MessageContentsList parameters = new MessageContentsList();
    parameters.put(mpi, wrappedObject);

    message.setContent(List.class, parameters);
}
 
Example #22
Source File: ServantTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Message createTestCloseSequenceMessage(String sidstr) {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    exchange.setInMessage(message);

    message.put(Message.REQUESTOR_ROLE, Boolean.FALSE);

    AddressingProperties maps = new AddressingProperties();
    String msgId = "urn:uuid:12345-" + Math.random();
    AttributedURIType id = ContextUtils.getAttributedURI(msgId);
    maps.setMessageID(id);

    maps.setAction(ContextUtils.getAttributedURI(RM10Constants.INSTANCE.getTerminateSequenceAction()));
    maps.setTo(ContextUtils.getAttributedURI(SERVICE_URL));

    maps.setReplyTo(RMUtils.createReference(DECOUPLED_URL));

    message.put(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND, maps);

    CloseSequenceType cs = new CloseSequenceType();
    org.apache.cxf.ws.rm.v200702.Identifier sid = new  org.apache.cxf.ws.rm.v200702.Identifier();
    sid.setValue(sidstr);
    cs.setIdentifier(sid);
    MessageContentsList contents = new MessageContentsList();
    contents.add(cs);
    message.setContent(List.class, contents);

    RMContextUtils.setProtocolVariation(message, ProtocolVariation.RM11WSA200508);

    return message;
}
 
Example #23
Source File: ServantTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Message createTestCreateSequenceMessage(Expires expires, OfferType offer) {
        Message message = new MessageImpl();
        Exchange exchange = new ExchangeImpl();
        exchange.setInMessage(message);
//        exchange.setOutMessage(new MessageImpl());

        message.put(Message.REQUESTOR_ROLE, Boolean.FALSE);

        AddressingProperties maps = new AddressingProperties();
        String msgId = "urn:uuid:12345-" + Math.random();
        AttributedURIType id = ContextUtils.getAttributedURI(msgId);
        maps.setMessageID(id);

        maps.setAction(ContextUtils.getAttributedURI(RM10Constants.INSTANCE.getCreateSequenceAction()));
        maps.setTo(ContextUtils.getAttributedURI(SERVICE_URL));

        maps.setReplyTo(RMUtils.createReference(DECOUPLED_URL));

        message.put(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND, maps);

        CreateSequenceType cs = new CreateSequenceType();
        cs.setAcksTo(org.apache.cxf.ws.addressing.VersionTransformer
            .convert(RMUtils.createReference(DECOUPLED_URL)));

        cs.setExpires(expires);
        cs.setOffer(offer);

        MessageContentsList contents = new MessageContentsList();
        contents.add(cs);
        message.setContent(List.class, contents);

        RMContextUtils.setProtocolVariation(message, ProtocolVariation.RM10WSA200408);

        return message;
    }
 
Example #24
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 #25
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 #26
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 #27
Source File: CustomJAXRSInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public Object invoke(Exchange exchange, Object requestParams, Object resourceObject) {

    OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
    Method m = ori.getMethodToInvoke();
    Class<?> realClass = ClassHelper.getRealClass(exchange.getBus(), resourceObject);

    Principal p = new SecurityContextImpl(exchange.getInMessage()).getUserPrincipal();
    if (realClass == SecureBookStore.class && "getThatBook".equals(m.getName())
        && "baddy".equals(p.getName())) {
        return new MessageContentsList(Response.status(Response.Status.FORBIDDEN).build());
    }

    return super.invoke(exchange, requestParams, resourceObject);
}
 
Example #28
Source File: MessageModeInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void doDataSource(final Message message) {
    MessageContentsList list = (MessageContentsList)message.getContent(List.class);
    //reconstitute all the parts into a Mime data source
    if (message.getAttachments() != null && !message.getAttachments().isEmpty()
        && list != null
        && !list.isEmpty() && list.get(0) instanceof DataSource) {
        list.set(0, new MultiPartDataSource(message, (DataSource)list.get(0)));
    }
}
 
Example #29
Source File: JAXRSInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Message createOutMessage(Message inMessage, Response r) {
    Endpoint e = inMessage.getExchange().getEndpoint();
    Message mout = e.getBinding().createMessage();
    mout.setContent(List.class, new MessageContentsList(r));
    mout.setExchange(inMessage.getExchange());
    mout.setInterceptorChain(
         OutgoingChainInterceptor.getOutInterceptorChain(inMessage.getExchange()));
    inMessage.getExchange().setOutMessage(mout);
    if (r.getStatus() >= Response.Status.BAD_REQUEST.getStatusCode()) {
        inMessage.getExchange().put("cxf.io.cacheinput", Boolean.FALSE);
    }
    return mout;
}
 
Example #30
Source File: JAXRSInvoker.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Object handleAsyncResponse(Exchange exchange, AsyncResponseImpl ar) {
    Object asyncObj = ar.getResponseObject();
    if (asyncObj instanceof Throwable) {
        final Throwable throwable = (Throwable)asyncObj;
        Throwable cause = throwable;

        if (throwable instanceof CompletionException) {
            cause = throwable.getCause();
        }

        return handleAsyncFault(exchange, ar, (cause != null) ? cause : throwable);
    }
    setResponseContentTypeIfNeeded(exchange.getInMessage(), asyncObj);
    return new MessageContentsList(asyncObj);
}