Java Code Examples for org.apache.cxf.service.model.EndpointInfo

The following examples show how to use org.apache.cxf.service.model.EndpointInfo. These examples are extracted from open source projects. 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 Project: cxf   Source File: PolicyAttachmentTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAppliesToEndpoint() {
    EndpointInfo ei1 = control.createMock(EndpointInfo.class);
    EndpointInfo ei2 = control.createMock(EndpointInfo.class);
    DomainExpression de = control.createMock(DomainExpression.class);
    Collection<DomainExpression> des = Collections.singletonList(de);
    PolicyAttachment pa = new PolicyAttachment();
    pa.setDomainExpressions(des);

    EasyMock.expect(de.appliesTo(ei1)).andReturn(false);
    EasyMock.expect(de.appliesTo(ei2)).andReturn(true);
    control.replay();
    assertFalse(pa.appliesTo(ei1));
    assertTrue(pa.appliesTo(ei2));
    control.verify();
}
 
Example 2
Source Project: steady   Source File: NegotiationUtils.java    License: Apache License 2.0 6 votes vote down vote up
static TokenStore getTokenStore(Message message) {
    EndpointInfo info = message.getExchange().get(Endpoint.class).getEndpointInfo();
    synchronized (info) {
        TokenStore tokenStore = 
            (TokenStore)message.getContextualProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
        if (tokenStore == null) {
            tokenStore = (TokenStore)info.getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
        }
        if (tokenStore == null) {
            TokenStoreFactory tokenStoreFactory = TokenStoreFactory.newInstance();
            String cacheKey = SecurityConstants.TOKEN_STORE_CACHE_INSTANCE;
            if (info.getName() != null) {
                cacheKey += "-" + info.getName().toString().hashCode();
            }
            tokenStore = tokenStoreFactory.newTokenStore(cacheKey, message);
            info.setProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, tokenStore);
        }
        return tokenStore;
    }
}
 
Example 3
Source Project: steady   Source File: KerberosTokenInterceptorProvider.java    License: Apache License 2.0 6 votes vote down vote up
static final TokenStore getTokenStore(Message message) {
    EndpointInfo info = message.getExchange().get(Endpoint.class).getEndpointInfo();
    synchronized (info) {
        TokenStore tokenStore = 
            (TokenStore)message.getContextualProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
        if (tokenStore == null) {
            tokenStore = (TokenStore)info.getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
        }
        if (tokenStore == null) {
            TokenStoreFactory tokenStoreFactory = TokenStoreFactory.newInstance();
            String cacheKey = SecurityConstants.TOKEN_STORE_CACHE_INSTANCE;
            if (info.getName() != null) {
                cacheKey += "-" + info.getName().toString().hashCode();
            }
            tokenStore = tokenStoreFactory.newTokenStore(cacheKey, message);
            info.setProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, tokenStore);
        }
        return tokenStore;
    }
}
 
Example 4
Source Project: steady   Source File: NegotiationUtils.java    License: Apache License 2.0 6 votes vote down vote up
static TokenStore getTokenStore(Message message) {
    EndpointInfo info = message.getExchange().get(Endpoint.class).getEndpointInfo();
    synchronized (info) {
        TokenStore tokenStore = 
            (TokenStore)message.getContextualProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
        if (tokenStore == null) {
            tokenStore = (TokenStore)info.getProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE);
        }
        if (tokenStore == null) {
            TokenStoreFactory tokenStoreFactory = TokenStoreFactory.newInstance();
            String cacheKey = SecurityConstants.TOKEN_STORE_CACHE_INSTANCE;
            if (info.getName() != null) {
                cacheKey += "-" + info.getName().toString().hashCode();
            }
            tokenStore = tokenStoreFactory.newTokenStore(cacheKey, message);
            info.setProperty(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, tokenStore);
        }
        return tokenStore;
    }
}
 
Example 5
Source Project: steady   Source File: PolicyBasedWSS4JInInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
private Crypto getSignatureCrypto(Object s, SoapMessage message) throws WSSecurityException {
    Crypto signCrypto = null;
    if (s instanceof Crypto) {
        signCrypto = (Crypto)s;
    } else if (s != null) {
        URL propsURL = getPropertiesFileURL(s, message);
        String propsKey = s.toString();
        if (propsURL != null) {
            propsKey = propsURL.getPath();
        }
        Properties props = getProps(s, propsKey, propsURL, message);
        signCrypto = CryptoFactory.getInstance(props);
        
        EndpointInfo info = message.getExchange().get(Endpoint.class).getEndpointInfo();
        synchronized (info) {
            info.setProperty(SecurityConstants.SIGNATURE_CRYPTO, signCrypto);
        }
    }
    return signCrypto;
}
 
Example 6
Source Project: cxf   Source File: ClientImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create a Client that uses a specific EndpointImpl.
 * @param bus
 * @param svc
 * @param port
 * @param endpointImplFactory
 */
public ClientImpl(Bus bus, Service svc, QName port,
                  EndpointImplFactory endpointImplFactory) {
    this.bus = bus;
    outFaultObserver = new ClientOutFaultObserver(bus);
    EndpointInfo epfo = findEndpoint(svc, port);

    try {
        if (endpointImplFactory != null) {
            getConduitSelector().setEndpoint(endpointImplFactory.newEndpointImpl(bus, svc, epfo));
        } else {
            getConduitSelector().setEndpoint(new EndpointImpl(bus, svc, epfo));
        }
    } catch (EndpointException epex) {
        throw new IllegalStateException("Unable to create endpoint: " + epex.getMessage(), epex);
    }
    notifyLifecycleManager();
}
 
Example 7
Source Project: steady   Source File: PolicyBasedWSS4JInInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
private Crypto getSignatureCrypto(Object s, SoapMessage message) throws WSSecurityException {
    Crypto signCrypto = null;
    if (s instanceof Crypto) {
        signCrypto = (Crypto)s;
    } else if (s != null) {
        URL propsURL = getPropertiesFileURL(s, message);
        String propsKey = s.toString();
        if (propsURL != null) {
            propsKey = propsURL.getPath();
        }
        Properties props = getProps(s, propsKey, propsURL, message);
        signCrypto = CryptoFactory.getInstance(props);
        
        EndpointInfo info = message.getExchange().get(Endpoint.class).getEndpointInfo();
        synchronized (info) {
            info.setProperty(SecurityConstants.SIGNATURE_CRYPTO, signCrypto);
        }
    }
    return signCrypto;
}
 
Example 8
Source Project: cxf   Source File: MEXUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static List<Element> getWSDLs(Server server) {
    Message message = PhaseInterceptorChain.getCurrentMessage();
    message.put(WSDLGetUtils.AUTO_REWRITE_ADDRESS_ALL, true);
    String base = (String)message.get(Message.REQUEST_URL);
    String ctxUri = (String)message.get(Message.PATH_INFO);

    WSDLGetUtils utils = new WSDLGetUtils();
    EndpointInfo info = server.getEndpoint().getEndpointInfo();
    List<Element> ret = new LinkedList<>();
    for (String id : utils.getWSDLIds(message, base, ctxUri, info)) {
        Map<String, String> params = new HashMap<>();
        params.put("wsdl", id);
        ret.add(utils.getDocument(message, base,
                                  params, ctxUri,
                                  info).getDocumentElement());

    }
    return ret;
}
 
Example 9
Source Project: cxf   Source File: HolderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testClient() throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(ADDRESS);

    Destination d = localTransport.getDestination(ei, bus);
    d.setMessageObserver(new MessageReplayObserver("/org/apache/cxf/jaxws/holder/echoResponse.xml"));

    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.getClientFactoryBean().setServiceClass(HolderService.class);
    factory.getClientFactoryBean().setBus(getBus());
    factory.getClientFactoryBean().setAddress(ADDRESS);

    HolderService h = (HolderService)factory.create();
    Holder<String> holder = new Holder<>();
    assertEquals("one", h.echo("one", "two", holder));
    assertEquals("two", holder.value);
}
 
Example 10
Source Project: cxf   Source File: WebSocketTransportFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Destination getDestination(EndpointInfo endpointInfo, Bus bus) throws IOException {
    if (endpointInfo == null) {
        throw new IllegalArgumentException("EndpointInfo cannot be null");
    }
    synchronized (registry) {
        AbstractHTTPDestination d = registry.getDestinationForPath(endpointInfo.getAddress());
        if (d == null) {
            d = factory.createDestination(endpointInfo, bus, registry);
            if (d == null) {
                String error = "No destination available. The CXF websocket transport needs either the "
                    + "Jetty WebSocket or Atmosphere dependencies to be available";
                throw new IOException(error);
            }
            registry.addDestination(d);
            configure(bus, d);
            d.finalizeConfig();
        }
        return d;
    }
}
 
Example 11
Source Project: steady   Source File: PolicyBasedWSS4JInInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
private Crypto getEncryptionCrypto(Object e, SoapMessage message) throws WSSecurityException {
    Crypto encrCrypto = null;
    if (e instanceof Crypto) {
        encrCrypto = (Crypto)e;
    } else if (e != null) {
        URL propsURL = getPropertiesFileURL(e, message);
        String propsKey = e.toString();
        if (propsURL != null) {
            propsKey = propsURL.getPath();
        }
        Properties props = getProps(e, propsKey, propsURL, message);
        encrCrypto = CryptoFactory.getInstance(props);
        
        EndpointInfo info = message.getExchange().get(Endpoint.class).getEndpointInfo();
        synchronized (info) {
            info.setProperty(SecurityConstants.ENCRYPT_CRYPTO, encrCrypto);
        }
    }
    return encrCrypto;
}
 
Example 12
Source Project: cxf   Source File: PolicyEngineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEndpointPolicyWithEqualPolicies() throws Exception {
    engine = new PolicyEngineImpl();
    EndpointInfo ei = createMockEndpointInfo();
    ServiceInfo si = control.createMock(ServiceInfo.class);
    ei.setService(si);
    si.getExtensor(Policy.class);
    EasyMock.expectLastCall().andReturn(null).times(2);
    EndpointPolicyImpl epi = control.createMock(EndpointPolicyImpl.class);
    control.replay();
    engine.setServerEndpointPolicy(ei, epi);
    engine.setClientEndpointPolicy(ei, epi);

    assertSame(epi, engine.getClientEndpointPolicy(ei, (Conduit)null, msg));
    assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination)null, msg));

    control.reset();
    ei.setService(si);
    Policy p = new Policy();
    si.getExtensor(Policy.class);
    EasyMock.expectLastCall().andReturn(p).times(2);
    epi.getPolicy();
    EasyMock.expectLastCall().andReturn(p).times(2);
    control.replay();
    assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination)null, msg));
}
 
Example 13
Source Project: fuchsia   Source File: ProtobufQueryHandler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @see org.apache.cxf.transports.http.QueryHandler#writeResponse(String,.
 * String, org.apache.cxf.service.model.EndpointInfo,
 * java.io.OutputStream)
 */
@SuppressWarnings("unchecked")
public void writeResponse(String fullQueryString, String ctx,
                          EndpointInfo endpoint, OutputStream os) {
    try {
        Class<? extends Message> messageClass = endpoint.getProperty(
                ProtobufServerFactoryBean.PROTOBUF_MESSAGE_CLASS,
                Class.class);
        PrintStream out = new PrintStream(os);
        Descriptor wrapperMessage = ((Descriptor) messageClass.getMethod(
                "getDescriptor").invoke(null));
        new ProtoGenerator().generateProtoFromDescriptor(wrapperMessage
                .getFile(), out, wrapperMessage);
        out.flush();
    } catch (Exception x) {
        throw new RuntimeException(x);
    }
}
 
Example 14
Source Project: cxf   Source File: EndpointPolicyImplTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInitializePolicy() {
    EndpointInfo ei = control.createMock(EndpointInfo.class);
    PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class);
    ServiceInfo si = control.createMock(ServiceInfo.class);
    EasyMock.expect(ei.getService()).andReturn(si);
    Policy sp = control.createMock(Policy.class);
    EasyMock.expect(engine.getAggregatedServicePolicy(si, null)).andReturn(sp);
    Policy ep = control.createMock(Policy.class);
    EasyMock.expect(engine.getAggregatedEndpointPolicy(ei, null)).andReturn(ep);
    Policy merged = control.createMock(Policy.class);
    EasyMock.expect(sp.merge(ep)).andReturn(merged);
    EasyMock.expect(merged.normalize(null, true)).andReturn(merged);

    control.replay();
    EndpointPolicyImpl epi = new EndpointPolicyImpl(ei, engine, true, null);
    epi.initializePolicy(null);
    assertSame(merged, epi.getPolicy());
    control.verify();
}
 
Example 15
Source Project: cxf   Source File: PolicyEngineImpl.java    License: Apache License 2.0 6 votes vote down vote up
public EffectivePolicy getEffectiveServerRequestPolicy(EndpointInfo ei,
                                                       BindingOperationInfo boi,
                                                       Message m) {
    EffectivePolicy effectivePolicy = (EffectivePolicy)boi.getProperty(POLICY_INFO_REQUEST_SERVER);
    if (effectivePolicy == null) {
        synchronized (ei) {
            effectivePolicy = (EffectivePolicy)boi.getProperty(POLICY_INFO_REQUEST_SERVER);
            if (null == effectivePolicy) {
                EffectivePolicyImpl epi = createOutPolicyInfo();
                epi.initialise(ei, boi, this, false, true, m);
                if (m != null) {
                    boi.setProperty(POLICY_INFO_REQUEST_SERVER, epi);
                }
                effectivePolicy = epi;
            }
        }
    }
    return effectivePolicy;
}
 
Example 16
Source Project: cxf   Source File: RMEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
Object getUsingAddressing(EndpointInfo endpointInfo) {
    if (null == endpointInfo) {
        return null;
    }
    Object ua = null;
    List<ExtensibilityElement> exts = endpointInfo.getExtensors(ExtensibilityElement.class);
    ua = getUsingAddressing(exts);
    if (null != ua) {
        return ua;
    }
    exts = endpointInfo.getBinding() != null ? endpointInfo.getBinding()
        .getExtensors(ExtensibilityElement.class) : null;
    ua = getUsingAddressing(exts);
    if (null != ua) {
        return ua;
    }
    exts = endpointInfo.getService() != null ? endpointInfo.getService()
        .getExtensors(ExtensibilityElement.class) : null;
    ua = getUsingAddressing(exts);
    if (null != ua) {
        return ua;
    }
    return ua;
}
 
Example 17
Source Project: cxf   Source File: PolicyEngineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEffectiveServerResponsePolicy() throws Exception {
    Method m = PolicyEngineImpl.class.getDeclaredMethod("createOutPolicyInfo", new Class[] {});
    engine = EasyMock.createMockBuilder(PolicyEngineImpl.class)
        .addMockedMethod(m).createMock(control);
    engine.init();
    EndpointInfo ei = createMockEndpointInfo();
    BindingOperationInfo boi = createMockBindingOperationInfo();
    AssertingDestination destination = control.createMock(AssertingDestination.class);
    EffectivePolicyImpl epi = control.createMock(EffectivePolicyImpl.class);
    EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi);
    epi.initialise(ei, boi, engine, destination, false, false, null);
    EasyMock.expectLastCall();
    control.replay();
    assertSame(epi, engine.getEffectiveServerResponsePolicy(ei, boi, destination, null, msg));
    assertSame(epi, engine.getEffectiveServerResponsePolicy(ei, boi, destination, null, msg));
    control.verify();
}
 
Example 18
Source Project: cxf   Source File: WSPolicyFeature.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Server server, Bus bus) {
    Endpoint endpoint = server.getEndpoint();
    Policy p = initializeEndpointPolicy(endpoint, bus);
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    EndpointInfo ei = endpoint.getEndpointInfo();
    EndpointPolicy ep = pe.getServerEndpointPolicy(ei, null, null);
    pe.setServerEndpointPolicy(ei, ep.updatePolicy(p, createMessage(endpoint, bus)));

    // Add policy to the service model (and consequently to the WSDL)
    // FIXME - ideally this should probably be moved up to where the policies are applied to the
    // endpoint, rather than this late.  As a consequence of its location, you have to declare a
    // ws policy feature on every endpoint in order to get any policy attachments into the
    // wsdl.  Alternatively add to the WSDLServiceBuilder somehow.
    ServiceModelPolicyUpdater pu = new ServiceModelPolicyUpdater(ei);
    for (PolicyProvider pp : ((PolicyEngineImpl) pe).getPolicyProviders()) {
        if (pp instanceof ExternalAttachmentProvider) {
            pu.addPolicyAttachments(((ExternalAttachmentProvider) pp).getAttachments());
        }
    }
}
 
Example 19
Source Project: cxf   Source File: NettyHttpTransportFactory.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Conduit getConduit(EndpointInfo endpointInfo, EndpointReferenceType target, Bus bus)
    throws IOException {

    HTTPConduit conduit = null;
    // need to updated the endpointInfo
    endpointInfo.setAddress(getAddress(endpointInfo));

    conduit = factory.createConduit(bus, endpointInfo, target);

    // Spring configure the conduit.
    String address = conduit.getAddress();
    if (address != null && address.indexOf('?') != -1) {
        address = address.substring(0, address.indexOf('?'));
    }
    HTTPConduitConfigurer c1 = bus.getExtension(HTTPConduitConfigurer.class);
    if (c1 != null) {
        c1.configure(conduit.getBeanName(), address, conduit);
    }
    configure(bus, conduit, conduit.getBeanName(), address);
    conduit.finalizeConfig();
    return conduit;
}
 
Example 20
Source Project: cxf   Source File: ColocOutInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
protected Server isColocated(List<Server> servers, Endpoint endpoint, BindingOperationInfo boi) {
    if (servers != null) {
        Service senderService = endpoint.getService();
        EndpointInfo senderEI = endpoint.getEndpointInfo();
        for (Server s : servers) {
            Endpoint receiverEndpoint = s.getEndpoint();
            Service receiverService = receiverEndpoint.getService();
            EndpointInfo receiverEI = receiverEndpoint.getEndpointInfo();
            if (receiverService.getName().equals(senderService.getName())
                && receiverEI.getName().equals(senderEI.getName())) {
                //Check For Operation Match.
                BindingOperationInfo receiverOI = receiverEI.getBinding().getOperation(boi.getName());
                if (receiverOI != null
                    && isCompatibleOperationInfo(boi, receiverOI)) {
                    return s;
                }
            }
        }
    }

    return null;
}
 
Example 21
Source Project: cxf   Source File: RMEndpointTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUsingAddressing() {
    EndpointInfo ei = null;
    control.replay();
    assertNull(rme.getUsingAddressing(ei));
    control.verify();

    control.reset();
    ExtensibilityElement ua = control.createMock(ExtensibilityElement.class);
    ei = control.createMock(EndpointInfo.class);
    List<ExtensibilityElement> noExts = new ArrayList<>();
    List<ExtensibilityElement> exts = new ArrayList<>();
    exts.add(ua);
    EasyMock.expect(ei.getExtensors(ExtensibilityElement.class)).andReturn(noExts);
    BindingInfo bi = control.createMock(BindingInfo.class);
    EasyMock.expect(ei.getBinding()).andReturn(bi).times(2);
    EasyMock.expect(bi.getExtensors(ExtensibilityElement.class)).andReturn(noExts);
    ServiceInfo si = control.createMock(ServiceInfo.class);
    EasyMock.expect(ei.getService()).andReturn(si).times(2);
    EasyMock.expect(si.getExtensors(ExtensibilityElement.class)).andReturn(exts);
    EasyMock.expect(ua.getElementType()).andReturn(Names.WSAW_USING_ADDRESSING_QNAME);
    control.replay();
    assertSame(ua, rme.getUsingAddressing(ei));
}
 
Example 22
Source Project: cxf   Source File: JavaToWSDLProcessor.java    License: Apache License 2.0 6 votes vote down vote up
private void customize(ServiceInfo service) {
    if (context.containsKey(ToolConstants.CFG_TNS)) {
        String ns = (String)context.get(ToolConstants.CFG_TNS);
        service.setTargetNamespace(ns);
    }

    if (context.containsKey(ToolConstants.CFG_PORT)) {
        String portName = (String)context.get(ToolConstants.CFG_PORT);
        EndpointInfo einfo = service.getEndpoints().iterator().next();
        QName qn = new QName(einfo.getName().getNamespaceURI(), portName);
        einfo.setName(qn);
    }

    if (context.containsKey(ToolConstants.CFG_SERVICENAME)) {
        String svName = getServiceName();
        service.setName(new QName(service.getName().getNamespaceURI(), svName));
    }
    EndpointInfo endpointInfo = service.getEndpoints().iterator().next();
    String address = ToolConstants.DEFAULT_ADDRESS + "/" + endpointInfo.getName().getLocalPart();
    if (context.get(ToolConstants.CFG_ADDRESS) != null) {
        address = (String)context.get(ToolConstants.CFG_ADDRESS);
    }
    endpointInfo.setAddress(address);
    context.put(ToolConstants.CFG_ADDRESS, address);

}
 
Example 23
public AtmosphereWebSocketUndertowDestination(Bus bus, DestinationRegistry registry, EndpointInfo ei,
                                              UndertowHTTPServerEngineFactory serverEngineFactory)
                                                  throws IOException {
    super(bus, registry, ei, serverEngineFactory);
    framework = new AtmosphereFramework(false, true);
    framework.setUseNativeImplementation(false);
    framework.addInitParameter(ApplicationConfig.PROPERTY_NATIVE_COMETSUPPORT, "true");
    framework.addInitParameter(ApplicationConfig.PROPERTY_SESSION_SUPPORT, "true");
    framework.addInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT, "true");
    framework.addInitParameter(ApplicationConfig.WEBSOCKET_PROTOCOL_EXECUTION, "true");
    // workaround for atmosphere's jsr356 initialization requiring servletConfig
    framework.addInitParameter(ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356, "true");
    AtmosphereUtils.addInterceptors(framework, bus);
    framework.addAtmosphereHandler("/", new DestinationHandler());
    framework.init();
    executor = bus.getExtension(WorkQueueManager.class).getAutomaticWorkQueue();
}
 
Example 24
Source Project: cxf   Source File: PolicyEngineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEffectiveServerRequestPolicyInfo() throws Exception {
    Method m = PolicyEngineImpl.class.getDeclaredMethod("createOutPolicyInfo", new Class[] {});
    engine = EasyMock.createMockBuilder(PolicyEngineImpl.class)
        .addMockedMethod(m).createMock(control);
    engine.init();
    EndpointInfo ei = createMockEndpointInfo();
    BindingOperationInfo boi = createMockBindingOperationInfo();
    EffectivePolicyImpl epi = control.createMock(EffectivePolicyImpl.class);
    EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi);
    epi.initialise(ei, boi, engine, false, true, msg);
    EasyMock.expectLastCall();
    control.replay();
    assertSame(epi, engine.getEffectiveServerRequestPolicy(ei, boi, msg));
    assertSame(epi, engine.getEffectiveServerRequestPolicy(ei, boi, msg));
    control.verify();
}
 
Example 25
Source Project: cxf   Source File: WSDLGetUtils.java    License: Apache License 2.0 6 votes vote down vote up
public Map<String, String> getSchemaLocations(Message message,
                                              String base,
                                              String ctxUri,
                                              EndpointInfo endpointInfo) {
    Map<String, String> params = new HashMap<>();
    params.put("wsdl", "");
    getDocument(message, base,
                params, ctxUri,
                endpointInfo);

    Map<String, SchemaReference> mp = CastUtils.cast((Map<?, ?>)endpointInfo.getService()
                                                     .getProperty(SCHEMAS_KEY));

    Map<String, String> schemas = new HashMap<>();
    for (Map.Entry<String, SchemaReference> ent : mp.entrySet()) {
        params.clear();
        params.put("xsd", ent.getKey());
        Document doc = getDocument(message, base, params, ctxUri, endpointInfo);
        schemas.put(doc.getDocumentElement().getAttribute("targetNamespace"),
                    buildUrl(base, ctxUri, "xsd=" + ent.getKey()));
    }
    return schemas;
}
 
Example 26
Source Project: cxf   Source File: LocalTransportFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
private void testInvocation(boolean isDirectDispatch) throws Exception {
    // Need to create a DefaultBus
    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);
    d.setMessageObserver(new EchoObserver());

    // Set up a listener for the response
    Conduit conduit = factory.getConduit(ei, bus);
    TestMessageObserver obs = new TestMessageObserver();
    conduit.setMessageObserver(obs);

    MessageImpl m = new MessageImpl();
    if (isDirectDispatch) {
        m.put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
    }
    m.setDestination(d);
    Exchange ex = new ExchangeImpl();
    ex.put(Bus.class, bus);
    m.setExchange(ex);
    conduit.prepare(m);

    OutputStream out = m.getContent(OutputStream.class);

    StringBuilder builder = new StringBuilder();
    for (int x = 0; x < 1000; x++) {
        builder.append("hello");
    }
    out.write(builder.toString().getBytes());
    out.close();
    conduit.close(m);

    assertEquals(builder.toString(), obs.getResponseStream().toString());
}
 
Example 27
Source Project: cxf   Source File: JMSEndpointTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testJaxWsProps() throws Exception {
    EndpointInfo ei = new EndpointInfo();
    ei.setProperty(JMSEndpoint.JAXWS_PROPERTY_PREFIX + "durableSubscriptionName", TEST_VALUE);
    JMSEndpoint endpoint = new JMSEndpoint(ei, "jms:queue:Foo.Bar");
    assertEquals(endpoint.getDurableSubscriptionName(), TEST_VALUE);
}
 
Example 28
Source Project: cxf   Source File: PolicyEngineTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSetEffectiveClientRequestPolicy() throws Exception {
    engine = new PolicyEngineImpl();
    EndpointInfo ei = createMockEndpointInfo();
    BindingOperationInfo boi = createMockBindingOperationInfo();
    EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
    control.replay();
    engine.setEffectiveClientRequestPolicy(ei, boi, effectivePolicy);
    assertSame(effectivePolicy,
               engine.getEffectiveClientRequestPolicy(ei, boi, (Conduit)null, msg));
    control.verify();
}
 
Example 29
Source Project: cxf   Source File: HTTPConduitURLEasyMockTest.java    License: Apache License 2.0 5 votes vote down vote up
HTTPTestConduit(
    Bus                      associatedBus,
    EndpointInfo             endpoint,
    EndpointReferenceType    epr,
    HttpsURLConnectionFactory testFactory
) throws IOException {
    super(associatedBus, endpoint, epr);
    connectionFactory = testFactory;
}
 
Example 30
Source Project: cxf   Source File: WSDLGetUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the published endpoint url from the working information set.
 *
 * @param def a wsdl as class objects
 * @param epurl the request URL
 * @param endpointInfo information for a web service 'port' inside of a service
 * @return String
 */
public String getPublishableEndpointUrl(Definition def,
                                        String epurl,
                                        EndpointInfo endpointInfo) {

    if (endpointInfo.getProperty(PUBLISHED_ENDPOINT_URL) != null) {
        epurl = String.valueOf(
            endpointInfo.getProperty(PUBLISHED_ENDPOINT_URL));
        updatePublishedEndpointUrl(epurl, def, endpointInfo.getName());
    }
    return epurl;
}