Java 类javax.xml.rpc.Call 实例源码

项目:parabuild-ci    文件:DynamicInvoker.java   
/**
 * Method getParamData
 *
 * @param c
 * @param arg
 */
private Object getParamData(org.apache.axis.client.Call c, Parameter p, String arg) throws Exception {
    // Get the QName representing the parameter type
    QName paramType = org.apache.axis.wsdl.toJava.Utils.getXSIType(p);

    TypeEntry type = p.getType();
    if (type instanceof BaseType && ((BaseType) type).isBaseType()) {
        DeserializerFactory factory = c.getTypeMapping().getDeserializer(paramType);
        Deserializer deserializer = factory.getDeserializerAs(Constants.AXIS_SAX);
        if (deserializer instanceof SimpleDeserializer) {
            return ((SimpleDeserializer)deserializer).makeValue(arg);
        }
    }
    throw new RuntimeException("not know how to convert '" + arg
                               + "' into " + c);
}
项目:class-guard    文件:JaxRpcPortClientInterceptor.java   
/**
 * Perform a JAX-RPC dynamic call for the given AOP method invocation.
 * Delegates to {@link #prepareJaxRpcCall} and
 * {@link #postProcessJaxRpcCall} for setting up the call object.
 * <p>The default implementation uses method name as JAX-RPC operation name
 * and method arguments as arguments for the JAX-RPC call. Can be
 * overridden in subclasses for custom operation names and/or arguments.
 * @param invocation the current AOP MethodInvocation that should
 * be converted to a JAX-RPC call
 * @param service the JAX-RPC Service to use for the call
 * @return the return value of the invocation, if any
 * @throws Throwable the exception thrown by the invocation, if any
 * @see #prepareJaxRpcCall
 * @see #postProcessJaxRpcCall
 */
protected Object performJaxRpcCall(MethodInvocation invocation, Service service) throws Throwable {
    Method method = invocation.getMethod();
    QName portQName = this.portQName;

    // Create JAX-RPC call object, using the method name as operation name.
    // Synchronized because of non-thread-safe Axis implementation!
    Call call = null;
    synchronized (service) {
        call = service.createCall(portQName, method.getName());
    }

    // Apply properties to JAX-RPC stub.
    prepareJaxRpcCall(call);

    // Allow for custom post-processing in subclasses.
    postProcessJaxRpcCall(call, invocation);

    // Perform actual invocation.
    return call.invoke(invocation.getArguments());
}
项目:class-guard    文件:JaxRpcPortClientInterceptor.java   
/**
 * Prepare the given JAX-RPC call, applying properties to it. Called by {@link #invoke}.
 * <p>Just applied when actually using JAX-RPC dynamic calls, i.e. if no compliant
 * port interface was specified. Else, a JAX-RPC port stub will be used.
 * @param call the current JAX-RPC call object
 * @see #setUsername
 * @see #setPassword
 * @see #setEndpointAddress
 * @see #setMaintainSession
 * @see #setCustomProperties
 * @see #setPortInterface
 * @see #preparePortStub
 */
protected void prepareJaxRpcCall(Call call) {
    String username = getUsername();
    if (username != null) {
        call.setProperty(Call.USERNAME_PROPERTY, username);
    }
    String password = getPassword();
    if (password != null) {
        call.setProperty(Call.PASSWORD_PROPERTY, password);
    }
    String endpointAddress = getEndpointAddress();
    if (endpointAddress != null) {
        call.setTargetEndpointAddress(endpointAddress);
    }
    if (isMaintainSession()) {
        call.setProperty(Call.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
    }
    if (this.customPropertyMap != null) {
        for (Map.Entry<String, Object> entry : this.customPropertyMap.entrySet()) {
            call.setProperty(entry.getKey(), entry.getValue());
        }
    }
}
项目:class-guard    文件:JaxRpcSupportTests.java   
public void testJaxRpcPortProxyFactoryBeanWithDynamicCallsAndProperties() throws Exception {
    JaxRpcPortProxyFactoryBean factory = new JaxRpcPortProxyFactoryBean();
    factory.setServiceFactoryClass(CallMockServiceFactory.class);
    factory.setNamespaceUri("myNamespace");
    factory.setServiceName("myService1");
    factory.setPortName("myPort");
    factory.setUsername("user");
    factory.setPassword("pw");
    factory.setEndpointAddress("ea");
    factory.setMaintainSession(true);
    factory.setServiceInterface(IBusinessBean.class);
    factory.afterPropertiesSet();
    assertNull(factory.getPortStub());

    assertTrue(factory.getObject() instanceof IBusinessBean);
    IBusinessBean proxy = (IBusinessBean) factory.getObject();
    proxy.setName("myName");

    verify(CallMockServiceFactory.call1).setProperty(Call.USERNAME_PROPERTY, "user");
    verify(CallMockServiceFactory.call1).setProperty(Call.PASSWORD_PROPERTY, "pw");
    verify(CallMockServiceFactory.call1).setTargetEndpointAddress("ea");
    verify(CallMockServiceFactory.call1).setProperty(Call.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
}
项目:parabuild-ci    文件:EmployeeClient.java   
public static void main(String[] args) throws Exception {
    Options opts = new Options(args);
    String uri = "http://faults.samples";
    String serviceName = "EmployeeInfoService";
    ServiceFactory serviceFactory = ServiceFactory.newInstance();
    Service service = serviceFactory.createService(new QName(uri, serviceName));

    TypeMappingRegistry registry = service.getTypeMappingRegistry();
    TypeMapping map = registry.getDefaultTypeMapping();

    QName employeeQName = new QName("http://faults.samples", "Employee");
    map.register(Employee.class, employeeQName, new BeanSerializerFactory(Employee.class, employeeQName), new BeanDeserializerFactory(Employee.class, employeeQName));

    QName faultQName = new QName("http://faults.samples", "NoSuchEmployeeFault");
    map.register(NoSuchEmployeeFault.class, faultQName, new BeanSerializerFactory(NoSuchEmployeeFault.class, faultQName), new BeanDeserializerFactory(NoSuchEmployeeFault.class, faultQName));

    Call call = service.createCall();
    call.setTargetEndpointAddress(new URL(opts.getURL()).toString());
    call.setProperty(Call.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
    call.setProperty(Call.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://faults.samples");
    call.setOperationName( new QName(uri, "getEmployee") );

    String[] args2 = opts.getRemainingArgs();
    System.out.println("Trying :" + args2[0]);
    Employee emp = (Employee) call.invoke(new Object[]{ args2[0] });
    System.out.println("Got :" + emp.getEmployeeID());
}
项目:parabuild-ci    文件:GetInfo.java   
public static void main(String args[]) throws Exception {
    Options opts = new Options(args);

    args = opts.getRemainingArgs();

    if (args == null || args.length % 2 != 0) {
        System.err.println("Usage: GetInfo <symbol> <datatype>");
        System.exit(1);
    }

    String  symbol  = args[0];
    Service service = ServiceFactory.newInstance().createService(null);
    Call    call    = service.createCall();

    call.setTargetEndpointAddress(opts.getURL());
    call.setOperationName(new QName("urn:cominfo", "getInfo"));
    call.addParameter("symbol", XMLType.XSD_STRING, ParameterMode.IN);
    call.addParameter("info", XMLType.XSD_STRING, ParameterMode.IN);
    call.setReturnType(XMLType.XSD_STRING);
    if(opts.getUser()!=null)
        call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
    if(opts.getPassword()!=null)
        call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());

    String res = (String) call.invoke(new Object[] {args[0], args[1]});

    System.out.println(symbol + ": " + res);
}
项目:parabuild-ci    文件:GetQuote1.java   
/**
 * This method does the same thing that getQuote1 does, but in
 * addition it reuses the Call object to make another call.
 */
public float getQuote3(String args[]) throws Exception {
    Options opts = new Options(args);

    args = opts.getRemainingArgs();

    if (args == null) {
        System.err.println("Usage: GetQuote <symbol>");
        System.exit(1);
    }

    /* Define the service QName and port QName */
    /*******************************************/
    QName servQN = new QName("urn:xmltoday-delayed-quotes",
            "GetQuoteService");
    QName portQN = new QName("urn:xmltoday-delayed-quotes", "GetQuote");

    /* Now use those QNames as pointers into the WSDL doc */
    /******************************************************/
    Service service = ServiceFactory.newInstance().createService(
            new URL("file:samples/stock/GetQuote.wsdl"), servQN);
    Call call = service.createCall(portQN, "getQuote");

    /* Strange - but allows the user to change just certain portions of */
    /* the URL we're gonna use to invoke the service.  Useful when you  */
    /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
    /********************************************************************/
    opts.setDefaultURL(call.getTargetEndpointAddress());
    call.setTargetEndpointAddress(opts.getURL());

    /* Define some service specific properties */
    /*******************************************/
    call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
    call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());

    /* Get symbol and invoke the service */
    /*************************************/
    Object result = call.invoke(new Object[] {symbol = args[0]});

    /* Reuse the Call object for a different call */
    /**********************************************/
    call.setOperationName(new QName("urn:xmltoday-delayed-quotes", "test"));
    call.removeAllParameters();
    call.setReturnType(XMLType.XSD_STRING);

    System.out.println(call.invoke(new Object[]{}));
    return ((Float) result).floatValue();
}
项目:class-guard    文件:JaxRpcSupportTests.java   
@Override
protected void initMocks() throws Exception {
    call1 = mock(Call.class);
    call2 = mock(Call.class);
    given(service1.createCall(new QName("myNamespace", "myPort"), "setName")).willReturn(call2, call1);
    given(call2.invoke(new Object[] { "exception" })).willThrow(new RemoteException());
}
项目:tomee    文件:ServiceImpl.java   
public Call[] getCalls(QName portName) throws ServiceException {

        if (portName == null) throw new ServiceException("Portname cannot be null");

        SeiFactory factory = (SeiFactory) portToImplementationMap.get(portName.getLocalPart());
        if (factory == null) throw new ServiceException("No port for portname: " + portName);

        OperationInfo[] operationInfos = factory.getOperationInfos();
        javax.xml.rpc.Call[] array = new javax.xml.rpc.Call[operationInfos.length];
        for (int i = 0; i < operationInfos.length; i++) {
            OperationInfo operation = operationInfos[i];
            array[i] = delegate.createCall(factory.getPortQName(), operation.getOperationName());
        }
        return array;
    }
项目:parabuild-ci    文件:GetQuote1.java   
/**
 * This will use the WSDL to prefill all of the info needed to make
 * the call.  All that's left is filling in the args to invoke().
 */
public float getQuote1(String args[]) throws Exception {
    Options opts = new Options(args);

    args = opts.getRemainingArgs();

    if (args == null) {
        System.err.println("Usage: GetQuote <symbol>");
        System.exit(1);
    }

    /* Define the service QName and port QName */
    /*******************************************/
    QName servQN = new QName("urn:xmltoday-delayed-quotes",
            "GetQuoteService");
    QName portQN = new QName("urn:xmltoday-delayed-quotes", "GetQuote");

    /* Now use those QNames as pointers into the WSDL doc */
    /******************************************************/
    Service service = ServiceFactory.newInstance().createService(
            new URL("file:samples/stock/GetQuote.wsdl"), servQN);
    Call call = service.createCall(portQN, "getQuote");

    /* Strange - but allows the user to change just certain portions of */
    /* the URL we're gonna use to invoke the service.  Useful when you  */
    /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
    /********************************************************************/
    opts.setDefaultURL(call.getTargetEndpointAddress());
    call.setTargetEndpointAddress(opts.getURL());

    /* Define some service specific properties */
    /*******************************************/
    call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
    call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());

    /* Get symbol and invoke the service */
    /*************************************/
    Object result = call.invoke(new Object[] {symbol = args[0]});

    return ((Float) result).floatValue();
}
项目:parabuild-ci    文件:GetQuote1.java   
/**
 * This will do everything manually (ie. no WSDL).
 */
public float getQuote2(String args[]) throws Exception {
    Options opts = new Options(args);

    args = opts.getRemainingArgs();

    if (args == null) {
        System.err.println("Usage: GetQuote <symbol>");
        System.exit(1);
    }

    /* Create default/empty Service and Call object */
    /************************************************/
    Service service = ServiceFactory.newInstance().createService(null);
    Call call = service.createCall();

    /* Strange - but allows the user to change just certain portions of */
    /* the URL we're gonna use to invoke the service.  Useful when you  */
    /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
    /********************************************************************/
    opts.setDefaultURL("http://localhost:8080/axis/servlet/AxisServlet");

    /* Set all of the stuff that would normally come from WSDL */
    /***********************************************************/
    call.setTargetEndpointAddress(opts.getURL());
    call.setProperty(Call.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    call.setProperty(Call.SOAPACTION_URI_PROPERTY, "getQuote");
    call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY,
            "http://schemas.xmlsoap.org/soap/encoding/");
    call.setOperationName(new QName("urn:xmltoday-delayed-quotes", "getQuote"));
    call.addParameter("symbol", XMLType.XSD_STRING, ParameterMode.IN);
    call.setReturnType(XMLType.XSD_FLOAT);

    /* Define some service specific properties */
    /*******************************************/
    call.setProperty(Call.USERNAME_PROPERTY, opts.getUser());
    call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword());

    /* Get symbol and invoke the service */
    /*************************************/
    Object result = call.invoke(new Object[] {symbol = args[0]});

    return ((Float) result).floatValue();
}
项目:class-guard    文件:JaxRpcSupportTests.java   
@Override
protected void initMocks() throws Exception {
    call1 = mock(Call.class);
    given(service1.createCall(new QName("myNamespace", "myPort"), "setName")).willReturn(call1);
}
项目:wso2-wss4j    文件:WSS4JHandler.java   
public String getPassword(Object msgContext) {
    return (String) ((MessageContext)msgContext).getProperty(Call.PASSWORD_PROPERTY);
}
项目:wso2-wss4j    文件:WSS4JHandler.java   
public void setPassword(Object msgContext, String password) {
    ((MessageContext)msgContext).setProperty(Call.PASSWORD_PROPERTY, password);
}
项目:tomee    文件:ServiceImpl.java   
public Call createCall(QName qName) throws ServiceException {
    return delegate.createCall(qName);
}
项目:tomee    文件:ServiceImpl.java   
public Call createCall(QName qName, QName qName1) throws ServiceException {
    return delegate.createCall(qName, qName1);
}
项目:tomee    文件:ServiceImpl.java   
public Call createCall(QName qName, String s) throws ServiceException {
    return delegate.createCall(qName, s);
}
项目:tomee    文件:ServiceImpl.java   
public Call createCall() throws ServiceException {
    return delegate.createCall();
}
项目:class-guard    文件:JaxRpcPortClientInterceptor.java   
/**
 * Post-process the given JAX-RPC call. Called by {@link #invoke}.
 * <p>The default implementation is empty.
 * <p>Just applied when actually using JAX-RPC dynamic calls, i.e. if no compliant
 * port interface was specified. Else, a JAX-RPC port stub will be used.
 * @param call the current JAX-RPC call object
 * (can be cast to an implementation-specific class if necessary)
 * @param invocation the current AOP MethodInvocation that the call was
 * created for (can be used to check method name, method parameters
 * and/or passed-in arguments)
 * @see #setPortInterface
 * @see #postProcessPortStub
 */
protected void postProcessJaxRpcCall(Call call, MethodInvocation invocation) {
}