Java Code Examples for org.apache.cxf.ws.addressing.AddressingProperties#setMessageID()

The following examples show how to use org.apache.cxf.ws.addressing.AddressingProperties#setMessageID() . 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: MAPAggregatorImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Assemble the generic MAPs (for both requests and responses).
 *
 * @param message the current message
 * @return AddressingProperties containing the generic MAPs
 */
private AddressingProperties assembleGeneric(Message message) {
    AddressingProperties maps = getMAPs(message, true, true);
    // MessageID
    if (maps.getMessageID() == null) {
        String messageID = ContextUtils.generateUUID();
        maps.setMessageID(ContextUtils.getAttributedURI(messageID));
    }

    // Action
    if (ContextUtils.hasEmptyAction(maps)) {
        maps.setAction(InternalContextUtils.getAction(message));

        if (ContextUtils.hasEmptyAction(maps)
            && ContextUtils.isOutbound(message)) {
            maps.setAction(ContextUtils.getAttributedURI(getActionUri(message, true)));
        }
    }
    return maps;
}
 
Example 2
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test(expected = SoapFault.class)
public void testTwoWayRequestWithReplyToNone() throws Exception {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    exchange.setOutMessage(message);
    message.setExchange(exchange);
    setUpMessageProperty(message,
                         REQUESTOR_ROLE,
                         Boolean.FALSE);
    AddressingProperties maps = new AddressingProperties();
    EndpointReferenceType replyTo = new EndpointReferenceType();
    replyTo.setAddress(ContextUtils.getAttributedURI(Names.WSA_NONE_ADDRESS));
    maps.setReplyTo(replyTo);
    AttributedURIType id =
        ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    maps.setAction(ContextUtils.getAttributedURI(""));
    setUpMessageProperty(message,
                         ADDRESSING_PROPERTIES_OUTBOUND,
                         maps);
    setUpMessageProperty(message,
                         "org.apache.cxf.ws.addressing.map.fault.name",
                         "NoneAddress");

    aggregator.mediate(message, false);
}
 
Example 3
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReplyToWithAnonymousAddressRetained() throws Exception {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.setOutMessage(message);
    setUpMessageProperty(message,
                         REQUESTOR_ROLE,
                         Boolean.TRUE);
    AddressingProperties maps = new AddressingProperties();
    EndpointReferenceType replyTo = new EndpointReferenceType();
    replyTo.setAddress(ContextUtils.getAttributedURI(Names.WSA_ANONYMOUS_ADDRESS));
    maps.setReplyTo(replyTo);
    AttributedURIType id =
        ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    maps.setAction(ContextUtils.getAttributedURI(""));
    setUpMessageProperty(message,
                         CLIENT_ADDRESSING_PROPERTIES,
                         maps);
    aggregator.mediate(message, false);
    AddressingProperties props =
        (AddressingProperties)message.get(JAXWSAConstants.ADDRESSING_PROPERTIES_OUTBOUND);
    assertSame(replyTo, props.getReplyTo());
}
 
Example 4
Source File: Client.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static AddressingProperties createMaps() {
    // get Message Addressing Properties instance
    AddressingProperties maps = new AddressingProperties();

    // set MessageID property
    AttributedURIType messageID = WSA_OBJECT_FACTORY.createAttributedURIType();
    messageID.setValue("urn:uuid:" + System.currentTimeMillis());
    maps.setMessageID(messageID);
    return maps;
}
 
Example 5
Source File: MAPTestBase.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testExplicitMAPs() throws Exception {
    try {
        String msgId = "urn:uuid:12345-" + Math.random();
        Map<String, Object> requestContext =
            ((BindingProvider)greeter).getRequestContext();
        AddressingProperties maps = new AddressingProperties();
        AttributedURIType id =
            ContextUtils.getAttributedURI(msgId);
        maps.setMessageID(id);
        requestContext.put(CLIENT_ADDRESSING_PROPERTIES, maps);
        String greeting = greeter.greetMe("explicit1");
        assertEquals("unexpected response received from service",
                     "Hello explicit1",
                     greeting);
        checkVerification();

        // the previous addition to the request context impacts
        // on all subsequent invocations on this proxy => a duplicate
        // message ID fault is expected
        try {
            greeter.greetMe("explicit2");
            fail("expected ProtocolException on duplicate message ID");
        } catch (ProtocolException pe) {
            assertEquals("expected duplicate message ID failure",
                       "Duplicate Message ID " + msgId, pe.getMessage());
            checkVerification();
        }

        // clearing the message ID ensure a duplicate is not sent
        maps.setMessageID(null);
        //maps.setRelatesTo(ContextUtils.getRelatesTo(id.getValue()));
        greeting = greeter.greetMe("explicit3");
        assertEquals("unexpected response received from service",
                     "Hello explicit3",
                     greeting);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception)ex.getCause();
    }
}
 
Example 6
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 7
Source File: ServantTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Message createTestTerminateSequenceMessage(String sidstr, ProtocolVariation protocol) {
    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);

    TerminateSequenceType ts = new TerminateSequenceType();
    Identifier sid = new Identifier();
    sid.setValue(sidstr);
    ts.setIdentifier(sid);
    Object tst = ProtocolVariation.RM10WSA200408.getWSRMNamespace().equals(protocol.getWSRMNamespace())
        ? ts : ProtocolVariation.RM10WSA200408.getCodec().convertReceivedTerminateSequence(ts);
    MessageContentsList contents = new MessageContentsList();
    contents.add(tst);
    message.setContent(List.class, contents);

    RMContextUtils.setProtocolVariation(message, protocol);

    return message;
}
 
Example 8
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 9
Source File: MAPCodecTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private AddressingProperties getMAPs(boolean requestor, boolean outbound, String uri) {
    AddressingProperties maps = new AddressingProperties();
    boolean exposeAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
    boolean exposeAs200408 = Names200408.WSA_NAMESPACE_NAME.equals(uri);
    boolean exposeAs200403 = Names200403.WSA_NAMESPACE_NAME.equals(uri);

    AttributedURIType id = ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    AttributedURIType to = ContextUtils.getAttributedURI("foobar");
    EndpointReferenceType toEpr = EndpointReferenceUtils.getEndpointReference(to);
    maps.setTo(toEpr);
    EndpointReferenceType replyTo = new EndpointReferenceType();
    String anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS : exposeAs200408
        ? Names200408.WSA_ANONYMOUS_ADDRESS
        : Names200403.WSA_ANONYMOUS_ADDRESS;
    replyTo.setAddress(ContextUtils.getAttributedURI(anonymous));
    maps.setReplyTo(replyTo);
    EndpointReferenceType from = EndpointReferenceUtils.getEndpointReference("snafu");
    maps.setFrom(from);
    EndpointReferenceType faultTo = new EndpointReferenceType();
    anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS : exposeAs200408
        ? Names200408.WSA_ANONYMOUS_ADDRESS
        : Names200403.WSA_ANONYMOUS_ADDRESS;
    faultTo.setAddress(ContextUtils.getAttributedURI(anonymous));
    maps.setFaultTo(faultTo);
    RelatesToType relatesTo = null;
    if (expectRelatesTo) {
        String correlationID = "urn:uuid:67890";
        relatesTo = new RelatesToType();
        relatesTo.setValue(correlationID);
        maps.setRelatesTo(relatesTo);
        if (nonReplyRelationship == null) {
            correlatedExchange = new ExchangeImpl();
            codec.uncorrelatedExchanges.put(correlationID, correlatedExchange);
        } else {
            relatesTo.setRelationshipType(nonReplyRelationship);
        }
    }
    AttributedURIType action = ContextUtils.getAttributedURI("http://foo/bar/SEI/opRequest");
    maps.setAction(action);
    maps.exposeAs(uri);
    expectedNamespaceURI = uri;

    expectedNames = new QName[] {
        new QName(uri, Names.WSA_ACTION_NAME),
        new QName(uri, Names.WSA_MESSAGEID_NAME),
        new QName(uri, Names.WSA_TO_NAME),
        new QName(uri, Names.WSA_REPLYTO_NAME),
        new QName(uri, Names.WSA_RELATESTO_NAME),
        new QName(uri, Names.WSA_FROM_NAME),
        new QName(uri, Names.WSA_FAULTTO_NAME),
    };
    if (exposeAsNative) {
        expectedValues = new Object[] {
            action, id, to, replyTo, relatesTo, from, faultTo
        };
    } else if (exposeAs200408) {
        expectedValues = new Object[] {
            org.apache.cxf.ws.addressing.VersionTransformer.convert(action),
            org.apache.cxf.ws.addressing.VersionTransformer.convert(id),
            org.apache.cxf.ws.addressing.VersionTransformer.convert(to),
            org.apache.cxf.ws.addressing.VersionTransformer.convert(replyTo),
            org.apache.cxf.ws.addressing.VersionTransformer.convert(relatesTo),
            org.apache.cxf.ws.addressing.VersionTransformer.convert(from),
            org.apache.cxf.ws.addressing.VersionTransformer.convert(faultTo),
        };
        if (!outbound) {
            // conversion from 2004/08 to 2005/08 anonymous address
            // occurs transparently in VersionTransformer
            Names200408.EPR_TYPE.cast(expectedValues[3]).getAddress()
                .setValue(Names.WSA_ANONYMOUS_ADDRESS);
            Names200408.EPR_TYPE.cast(expectedValues[5]).getAddress()
                .setValue(Names.WSA_ANONYMOUS_ADDRESS);
        }
    } else if (exposeAs200403) {
        expectedValues = new Object[] {
            org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(action),
            org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(id),
            org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(to),
            org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(replyTo),
            org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(relatesTo),
            org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(from),
            org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(faultTo),
        };
        if (!outbound) {
            // conversion from 2004/03 to 2005/08 anonymous address
            // occurs transparently in VersionTransformer
            Names200403.EPR_TYPE.cast(expectedValues[3]).getAddress()
                .setValue(Names.WSA_ANONYMOUS_ADDRESS);
            Names200403.EPR_TYPE.cast(expectedValues[5]).getAddress()
                .setValue(Names.WSA_ANONYMOUS_ADDRESS);
        }
    } else {
        fail("unexpected namespace URI: " + uri);
    }
    return maps;
}
 
Example 10
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetReplyToUsingBaseAddress() throws Exception {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);

    final String localReplyTo = "/SoapContext/decoupled";
    final String decoupledEndpointBase = "http://localhost:8181/cxf";
    final String replyTo = decoupledEndpointBase + localReplyTo;

    ServiceInfo s = new ServiceInfo();
    Service svc = new ServiceImpl(s);
    EndpointInfo ei = new EndpointInfo();
    InterfaceInfo ii = s.createInterface(new QName("FooInterface"));
    s.setInterface(ii);
    ii.addOperation(new QName("fooOp"));
    SoapBindingInfo b = new SoapBindingInfo(s, "http://schemas.xmlsoap.org/soap/", Soap11.getInstance());
    b.setTransportURI("http://schemas.xmlsoap.org/soap/http");
    ei.setBinding(b);

    ei.setAddress("http://nowhere.com/bar/foo");
    ei.setName(new QName("http://nowhere.com/port", "foo"));
    Bus bus = new ExtensionManagerBus();
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    DestinationFactory df = control.createMock(DestinationFactory.class);
    Destination d = control.createMock(Destination.class);
    bus.setExtension(dfm, DestinationFactoryManager.class);
    EasyMock.expect(dfm.getDestinationFactoryForUri(localReplyTo)).andReturn(df);
    EasyMock.expect(df.getDestination(
        EasyMock.anyObject(EndpointInfo.class), EasyMock.anyObject(Bus.class))).andReturn(d);
    EasyMock.expect(d.getAddress()).andReturn(EndpointReferenceUtils.getEndpointReference(localReplyTo));

    Endpoint ep = new EndpointImpl(bus, svc, ei);
    exchange.put(Endpoint.class, ep);
    exchange.put(Bus.class, bus);
    exchange.setOutMessage(message);
    setUpMessageProperty(message,
                         REQUESTOR_ROLE,
                         Boolean.TRUE);
    message.getContextualProperty(WSAContextUtils.REPLYTO_PROPERTY);
    message.put(WSAContextUtils.REPLYTO_PROPERTY, localReplyTo);
    message.put(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY, decoupledEndpointBase);

    AddressingProperties maps = new AddressingProperties();
    AttributedURIType id =
        ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    maps.setAction(ContextUtils.getAttributedURI(""));
    setUpMessageProperty(message,
                         CLIENT_ADDRESSING_PROPERTIES,
                         maps);
    control.replay();
    aggregator.mediate(message, false);
    AddressingProperties props =
        (AddressingProperties)message.get(JAXWSAConstants.ADDRESSING_PROPERTIES_OUTBOUND);

    assertEquals(replyTo, props.getReplyTo().getAddress().getValue());
    control.verify();
}
 
Example 11
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setUpResponder(Message message,
                            Exchange exchange,
                            SetupResponderArgs args,
                            Endpoint endpoint) throws Exception {

    setUpMessageProperty(message,
                         REQUESTOR_ROLE,
                         Boolean.FALSE);
    AddressingProperties maps = new AddressingProperties();
    EndpointReferenceType replyTo = new EndpointReferenceType();
    replyTo.setAddress(
        ContextUtils.getAttributedURI(args.decoupled
                                      ? "http://localhost:9999/decoupled"
                                      : Names.WSA_ANONYMOUS_ADDRESS));
    maps.setReplyTo(replyTo);
    EndpointReferenceType faultTo = new EndpointReferenceType();
    faultTo.setAddress(
        ContextUtils.getAttributedURI(args.decoupled
                                      ? "http://localhost:9999/fault"
                                      : Names.WSA_ANONYMOUS_ADDRESS));
    maps.setFaultTo(faultTo);

    if (!args.noMessageId) {
        AttributedURIType id =
            ContextUtils.getAttributedURI("urn:uuid:12345");
        maps.setMessageID(id);
    }

    if (args.zeroLengthAction) {
        maps.setAction(ContextUtils.getAttributedURI(""));
    }
    setUpMessageProperty(message,
                         ADDRESSING_PROPERTIES_INBOUND,
                         maps);
    if (!args.outbound) {
        setUpOneway(message, exchange, args.oneway);
        if (args.oneway || args.decoupled) {
            setUpRebase(message, exchange, endpoint);
        }
    }

    if (args.outbound || ((DefaultMessageIdCache) aggregator.getMessageIdCache())
        .getMessageIdSet().size() > 0) {
        if (!args.zeroLengthAction) {
            Method method = SEI.class.getMethod("op", new Class[0]);
            setUpMethod(message, exchange, method);
            setUpMessageProperty(message,
                                 REQUESTOR_ROLE,
                                 Boolean.FALSE);

            if (args.fault) {
                message.setContent(Exception.class, new SoapFault("blah",
                        new Exception(), Fault.FAULT_CODE_SERVER));
                expectedAction = "http://foo/bar/SEI/op/Fault/Exception";
            } else {
                expectedAction = "http://foo/bar/SEI/opResponse";
            }
        }
        setUpMessageProperty(message,
                             REQUESTOR_ROLE,
                             Boolean.FALSE);
        setUpMessageProperty(message,
                             ADDRESSING_PROPERTIES_INBOUND,
                             maps);
        if (args.fault) {
            // REVISIT test double rebase does not occur
            setUpRebase(message, exchange, endpoint);
        }
        expectedTo = args.decoupled
                     ? args.fault
                       ? "http://localhost:9999/fault"
                       : "http://localhost:9999/decoupled"
                     : Names.WSA_ANONYMOUS_ADDRESS;

        if (maps.getMessageID() != null && maps.getMessageID().getValue() != null) {
            expectedRelatesTo = maps.getMessageID().getValue();
        } else {
            expectedRelatesTo = Names.WSA_UNSPECIFIED_RELATIONSHIP;
        }
        // Now verified via verifyMessage()
        //EasyMock.eq(SERVER_ADDRESSING_PROPERTIES_OUTBOUND);
        //EasyMock.reportMatcher(new MAPMatcher());
        //message.put(SERVER_ADDRESSING_PROPERTIES_OUTBOUND,
        //            new AddressingPropertiesImpl());
        //EasyMock.expectLastCall().andReturn(null);
    }
}