Java Code Examples for org.apache.cxf.service.model.EndpointInfo#setAddress()

The following examples show how to use org.apache.cxf.service.model.EndpointInfo#setAddress() . 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: NettyHttpDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testServerPolicyInServiceModel()
    throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    bus = new ExtensionManagerBus();

    transportFactory = new HTTPTransportFactory();

    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    endpointInfo = new EndpointInfo(serviceInfo, "");
    endpointInfo.setName(new QName("bla", "Port"));
    endpointInfo.addExtensor(policy);

    engine = EasyMock.createMock(NettyHttpServerEngine.class);
    EasyMock.replay();
    endpointInfo.setAddress(NOWHERE + "bar/foo");

    NettyHttpDestination dest =
        new EasyMockJettyHTTPDestination(
                bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    assertEquals(policy, dest.getServer());
}
 
Example 2
Source File: HTTPConduitURLConnectionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * This test verifies that URL used is overridden by having the
 * ENDPOINT_ADDRESS set on the Message.
 */
@Test
public void testConnectionURLOverride() throws Exception {
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.null/bar/foo");
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    conduit.finalizeConfig();

    Message message = getNewMessage();
    message.put(Message.ENDPOINT_ADDRESS, "http://somewhere.different/");

    // Test call
    conduit.prepare(message);

    HttpURLConnection con =
        (HttpURLConnection) message.get("http.connection");
    assertEquals("Unexpected URL address",
            con.getURL().toString(),
            "http://somewhere.different/");
}
 
Example 3
Source File: HTTPConduitTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Verfies one of the tenents of our interface -- the Conduit sets up
 * an OutputStream on the message after a "prepare".
 */
@Test
public void testConduitOutputStream() throws Exception {
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.com/bar/foo");
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    conduit.finalizeConfig();

    Message message = getNewMessage();

    // Test call
    conduit.prepare(message);

    assertNotNull("Conduit should always set output stream.",
                    message.getContent(OutputStream.class));
}
 
Example 4
Source File: AtmosphereWebSocketServletDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCXFDefaultAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (DefaultProtocolInterceptor.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example 5
Source File: UndertowHTTPDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testServerPolicyInServiceModel()
    throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    bus = BusFactory.getDefaultBus(true);

    transportFactory = new HTTPTransportFactory();

    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    endpointInfo = new EndpointInfo(serviceInfo, "");
    endpointInfo.setName(new QName("bla", "Port"));
    endpointInfo.addExtensor(policy);

    engine = EasyMock.createMock(UndertowHTTPServerEngine.class);
    EasyMock.replay();
    endpointInfo.setAddress(NOWHERE + "bar/foo");

    UndertowHTTPDestination dest =
        new EasyMockUndertowHTTPDestination(
                bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    assertEquals(policy, dest.getServer());
}
 
Example 6
Source File: HTTPConduitURLConnectionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * This test verifies that the "prepare" call places an HttpURLConnection on
 * the Message and that its URL matches the endpoint.
 */
@Test
public void testConnectionURL() throws Exception {
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.com/bar/foo");
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    conduit.finalizeConfig();

    Message message = getNewMessage();

    conduit.prepare(message);

    HttpURLConnection con =
        (HttpURLConnection) message.get("http.connection");
    assertEquals("Unexpected URL address",
            con.getURL().toString(),
            ei.getAddress());
}
 
Example 7
Source File: AtmosphereWebSocketJettyDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testUseCustomAtmoosphereInterceptor() throws Exception {
    Bus bus = new ExtensionManagerBus();
    bus.setProperty("atmosphere.interceptors", new CustomInterceptor1());
    DestinationRegistry registry = new HTTPTransportFactory().getRegistry();
    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(ENDPOINT_ADDRESS);
    endpoint.setName(ENDPOINT_NAME);

    AtmosphereWebSocketServletDestination dest =
        new AtmosphereWebSocketServletDestination(bus, registry, endpoint, ENDPOINT_ADDRESS);

    List<AtmosphereInterceptor> ais = dest.getAtmosphereFramework().interceptors();
    int added = 0;
    for (AtmosphereInterceptor a : ais) {
        if (CustomInterceptor1.class.equals(a.getClass())) {
            added++;
            break;
        }
    }
    assertEquals(1, added);
}
 
Example 8
Source File: HTTPTransportFactoryTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDestination() {
    Bus bus = BusFactory.getDefaultBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.com/bar/foo");
    HTTPTransportFactory factory = bus.getExtension(HTTPTransportFactory.class);
    if (factory != null) {
        try {
            factory.getDestination(ei, bus);
            fail("Expect exception here.");
        } catch (IOException ex) {
            assertTrue("We should find some exception related to the HttpDestination",
                   ex.getMessage().indexOf("HttpDestinationFactory") > 0);
        }
    }
}
 
Example 9
Source File: RMEndpointTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateEndpoint() throws NoSuchMethodException, EndpointException {
    Method m = RMEndpoint.class.getDeclaredMethod("getUsingAddressing", new Class[] {EndpointInfo.class});
    Service as = control.createMock(Service.class);
    EndpointInfo aei = new EndpointInfo();
    ae = new EndpointImpl(null, as, aei);
    rme = EasyMock.createMockBuilder(RMEndpoint.class).withConstructor(manager, ae)
        .addMockedMethod(m).createMock(control);
    rme.setAplicationEndpoint(ae);
    rme.setManager(manager);
    SoapBindingInfo bi = control.createMock(SoapBindingInfo.class);
    aei.setBinding(bi);
    SoapVersion sv = Soap11.getInstance();
    EasyMock.expect(bi.getSoapVersion()).andReturn(sv);
    String ns = "http://schemas.xmlsoap.org/wsdl/soap/";
    EasyMock.expect(bi.getBindingId()).andReturn(ns);
    aei.setTransportId(ns);
    String addr = "addr";
    aei.setAddress(addr);
    Object ua = new Object();
    EasyMock.expect(rme.getUsingAddressing(aei)).andReturn(ua);
    control.replay();
    rme.createServices();
    rme.createEndpoints(null);
    Endpoint e = rme.getEndpoint(ProtocolVariation.RM10WSA200408);
    WrappedEndpoint we = (WrappedEndpoint)e;
    assertSame(ae, we.getWrappedEndpoint());
    Service s = rme.getService(ProtocolVariation.RM10WSA200408);
    assertEquals(1, s.getEndpoints().size());
    assertSame(e, s.getEndpoints().get(RM10Constants.PORT_NAME));
}
 
Example 10
Source File: LocalDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Tests if the status code is available after closing the destination so that it can be logged.
 * Note that this test verifies the current approach of setting the status code if it is not set earlier.
 *
 * @throws Exception
 */
@Test
public void testStatusCodeSetAfterClose() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    LocalTransportFactory factory = new LocalTransportFactory();

    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress("http://localhost/test");

    LocalDestination d = (LocalDestination) factory.getDestination(ei, bus);
    MessageImpl m = new MessageImpl();

    Conduit conduit = factory.getConduit(ei, bus);
    m.put(LocalConduit.IN_CONDUIT, conduit);
    Exchange ex = new ExchangeImpl();
    ex.put(Bus.class, bus);
    m.setExchange(ex);

    Integer code = (Integer)m.get(Message.RESPONSE_CODE);
    assertNull(code);

    Conduit backChannel = d.getBackChannel(m);

    backChannel.close(m);

    code = (Integer)m.get(Message.RESPONSE_CODE);
    assertNotNull(code);
    assertEquals(200, code.intValue());
}
 
Example 11
Source File: ServiceUtils.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
public static EndpointInfo createEndpointInfo(Bus bus, ServiceInfo serviceInfo,
                                              BindingInfo bindingInfo, String address) {
    String transportURI = getTransportId(bus, address);
    EndpointInfo endpointInfo = new EndpointInfo(serviceInfo, transportURI);

    if (address != null) {
        endpointInfo.setName(new QName(address));
        endpointInfo.setAddress(address);
    }

    System.out.println("seting binding info:" + bindingInfo);
    endpointInfo.setBinding(bindingInfo);

    return endpointInfo;
}
 
Example 12
Source File: WebSocketTransportFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDestination() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("ws://localhost:8888/bar/foo");
    WebSocketTransportFactory factory = bus.getExtension(WebSocketTransportFactory.class);
    assertNotNull(factory);
    Destination dest = factory.getDestination(ei, bus);
    assertNotNull(dest);
}
 
Example 13
Source File: ApplicationContextTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private EndpointInfo getEndpointInfo(String serviceNS,
                                     String endpointLocal,
                                     String address) {
    ServiceInfo serviceInfo2 = new ServiceInfo();
    serviceInfo2.setName(new QName(serviceNS, "Service"));
    EndpointInfo info2 = new EndpointInfo(serviceInfo2, "");
    info2.setName(new QName("urn:test:ns", endpointLocal));
    info2.setAddress(address);
    return info2;
}
 
Example 14
Source File: JaxWsClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    super.setUpBus();

    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(ADDRESS);

    d = localTransport.getDestination(ei, bus);
}
 
Example 15
Source File: ApplicationContextTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private EndpointInfo getEndpointInfo(String serviceNS,
                                     String endpointLocal,
                                     String address) {
    ServiceInfo serviceInfo2 = new ServiceInfo();
    serviceInfo2.setName(new QName(serviceNS, "Service"));
    EndpointInfo info2 = new EndpointInfo(serviceInfo2, "");
    info2.setName(new QName("urn:test:ns", endpointLocal));
    info2.setAddress(address);
    return info2;
}
 
Example 16
Source File: DispatchTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(ADDRESS);

    d = localTransport.getDestination(ei, bus);
}
 
Example 17
Source File: JAXWSHttpSpiTransportFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void getDestination(String endpointAddress) throws Exception {
    context.setHandler(EasyMock.isA(HttpHandler.class));
    control.replay();

    EndpointInfo endpoint = new EndpointInfo();
    endpoint.setAddress(endpointAddress);

    Destination destination = factory.getDestination(endpoint, bus);
    assertNotNull(destination);
    assertNotNull(destination.getAddress());
    assertNotNull(destination.getAddress().getAddress());
    assertEquals(endpointAddress, destination.getAddress().getAddress().getValue());
    assertEquals(endpointAddress, endpoint.getAddress());
    control.verify();
}
 
Example 18
Source File: RequestPreprocessorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Message mockMessage(String baseAddress,
                            String pathInfo,
                            String query,
                            String method,
                            String methodHeader) {
    Message m = new MessageImpl();
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    m.put("org.apache.cxf.endpoint.private", false);
    Exchange e = new ExchangeImpl();
    m.setExchange(e);
    control.reset();
    Endpoint endp = control.mock(Endpoint.class);
    e.put(Endpoint.class, endp);
    EasyMock.expect(endp.isEmpty()).andReturn(true).anyTimes();
    EasyMock.expect(endp.get(ServerProviderFactory.class.getName())).andReturn(ServerProviderFactory.getInstance())
            .anyTimes();
    ServletDestination d = control.createMock(ServletDestination.class);
    e.setDestination(d);
    EndpointInfo epr = new EndpointInfo();
    epr.setAddress(baseAddress);
    EasyMock.expect(d.getEndpointInfo()).andReturn(epr).anyTimes();
    EasyMock.expect(endp.getEndpointInfo()).andReturn(epr).anyTimes();
    m.put(Message.REQUEST_URI, pathInfo);
    m.put(Message.QUERY_STRING, query);
    m.put(Message.HTTP_REQUEST_METHOD, method);
    Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    if (methodHeader != null) {
        headers.put("X-HTTP-Method-Override", Collections.singletonList(methodHeader));
    }
    m.put(Message.PROTOCOL_HEADERS, headers);
    BindingInfo bi = control.createMock(BindingInfo.class);
    epr.setBinding(bi);
    EasyMock.expect(bi.getProperties()).andReturn(Collections.emptyMap()).anyTimes();

    control.replay();
    return m;
}
 
Example 19
Source File: HTTPConduitTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * This test verfies that the "getTarget() call returns the correct
 * EndpointReferenceType for the given endpoint address.
 */
@Test
public void testGetTarget() throws Exception {
    Bus bus = new ExtensionManagerBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("http://nowhere.com/bar/foo");
    HTTPConduit conduit = new URLConnectionHTTPConduit(bus, ei, null);
    conduit.finalizeConfig();

    EndpointReferenceType target =
        EndpointReferenceUtils.getEndpointReference(
                "http://nowhere.com/bar/foo");

    // Test call
    EndpointReferenceType ref = conduit.getTarget();

    assertNotNull("unexpected null target", ref);
    assertEquals("unexpected target",
                 EndpointReferenceUtils.getAddress(ref),
                 EndpointReferenceUtils.getAddress(target));

    assertEquals("unexpected address",
                 conduit.getAddress(),
                 "http://nowhere.com/bar/foo");
    assertEquals("unexpected on-demand URL",
                 conduit.getURI().getPath(),
                 "/bar/foo");
}
 
Example 20
Source File: MtomServerTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testURLBasedAttachment() throws Exception {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setServiceBean(new EchoService());
    sf.setBus(getStaticBus());
    String address = "http://localhost:" + PORT2 + "/EchoService";
    sf.setAddress(address);
    Map<String, Object> props = new HashMap<>();
    props.put(Message.MTOM_ENABLED, "true");
    sf.setProperties(props);
    Server server = sf.create();
    server.getEndpoint().getService().getDataBinding().setMtomThreshold(0);

    servStatic(getClass().getResource("mtom-policy.xml"),
               "http://localhost:" + PORT2 + "/policy.xsd");

    EndpointInfo ei = new EndpointInfo(null, HTTP_ID);
    ei.setAddress(address);

    ConduitInitiatorManager conduitMgr = getStaticBus().getExtension(ConduitInitiatorManager.class);
    ConduitInitiator conduitInit = conduitMgr.getConduitInitiator("http://schemas.xmlsoap.org/soap/http");
    Conduit conduit = conduitInit.getConduit(ei, getStaticBus());

    TestUtilities.TestMessageObserver obs = new TestUtilities.TestMessageObserver();
    conduit.setMessageObserver(obs);

    Message m = new MessageImpl();
    String ct = "multipart/related; type=\"application/xop+xml\"; "
                + "start=\"<[email protected]>\"; "
                + "start-info=\"text/xml; charset=utf-8\"; "
                + "boundary=\"----=_Part_4_701508.1145579811786\"";

    m.put(Message.CONTENT_TYPE, ct);
    conduit.prepare(m);

    OutputStream os = m.getContent(OutputStream.class);
    InputStream is = testUtilities.getResourceAsStream("request-url-attachment");
    if (is == null) {
        throw new RuntimeException("Could not find resource " + "request");
    }
    try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
        IOUtils.copy(is, bout);
        String s = bout.toString(StandardCharsets.UTF_8.name());
        s = s.replaceAll(":9036/", ":" + PORT2 + "/");

        os.write(s.getBytes(StandardCharsets.UTF_8));
    }
    os.flush();
    is.close();
    os.close();

    byte[] res = obs.getResponseStream().toByteArray();
    MessageImpl resMsg = new MessageImpl();
    resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
    resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
    resMsg.setExchange(new ExchangeImpl());
    AttachmentDeserializer deserializer = new AttachmentDeserializer(resMsg);
    deserializer.initializeAttachments();

    Collection<Attachment> attachments = resMsg.getAttachments();
    assertNotNull(attachments);
    assertEquals(1, attachments.size());

    Attachment inAtt = attachments.iterator().next();
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        IOUtils.copy(inAtt.getDataHandler().getInputStream(), out);
        assertTrue("Wrong size: " + out.size()
                + "\n" + out.toString(),
                out.size() > 970 && out.size() < 1020);
    }
    unregisterServStatic("http://localhost:" + PORT2 + "/policy.xsd");

}