📄 client.java
字号:
package org.globus.examples.clients.MathService_instance_rp;import javax.xml.namespace.QName;import org.apache.axis.message.addressing.Address;import org.apache.axis.message.addressing.EndpointReferenceType;import org.oasis.wsrf.properties.WSResourcePropertiesServiceAddressingLocator;import org.oasis.wsrf.properties.SetResourceProperties_PortType;import org.oasis.wsrf.properties.SetResourceProperties_Element;import org.oasis.wsrf.properties.GetMultipleResourceProperties_Element;import org.oasis.wsrf.properties.GetMultipleResourcePropertiesResponse;import org.oasis.wsrf.properties.UpdateType;import org.apache.axis.message.MessageElement;import org.oasis.wsrf.properties.GetResourcePropertyResponse;import org.globus.examples.services.core.rp.impl.MathQNames;import org.globus.examples.stubs.MathService_instance_rp.MathPortType;import org.globus.examples.stubs.MathService_instance_rp.service.MathServiceAddressingLocator;public class Client { /* * This method prints out MathService's resource properties by using the * GetResourceProperty operation. */ private void printResourceProperties(MathPortType math) throws Exception { GetResourcePropertyResponse valueRP, lastOpRP, lastLogRP; String value, lastOp, lastLog; valueRP = math.getResourceProperty(MathQNames.RP_VALUE); lastOpRP = math.getResourceProperty(MathQNames.RP_LASTOP); value = valueRP.get_any()[0].getValue(); lastOp = lastOpRP.get_any()[0].getValue(); System.out.println("Value RP: " + value); System.out.println("LastOp RP: " + lastOp); } /* * This method updates resource property "rpQName" in the WS-Resource * pointed at by the endpoint reference "epr" with the new value "value". */ private void updateRP(EndpointReferenceType epr, QName rpQName, String value) throws Exception { /* Get a SetResourceProperties port type */ WSResourcePropertiesServiceAddressingLocator locator = new WSResourcePropertiesServiceAddressingLocator(); SetResourceProperties_PortType port = locator .getSetResourcePropertiesPort(epr); /* We will be invoking SetResourceProperties with a single Update */ UpdateType update = new UpdateType(); MessageElement msg = new MessageElement(rpQName, value); update.set_any(new MessageElement[] { msg }); /* Create request object */ SetResourceProperties_Element request = new SetResourceProperties_Element(); request.setUpdate(update); /* Invoke SetResourceProperties */ port.setResourceProperties(request); } /* * This method prints out MathService's resource properties by using the * GetMultipleResourceProperties operation. */ private void printMultipleResourceProperties(MathPortType math) throws Exception { GetMultipleResourceProperties_Element request; GetMultipleResourcePropertiesResponse response; /* Create request object */ QName[] resourceProperties = new QName[] { MathQNames.RP_VALUE, MathQNames.RP_LASTOP }; request = new GetMultipleResourceProperties_Element(resourceProperties); /* Invoke GetMultipleResourceProperties */ response = math.getMultipleResourceProperties(request); /* Print all the resource properties returned */ for(int i=0; i<response.get_any().length;i++) { String name = response.get_any()[i].getLocalName(); String value = response.get_any()[i].getValue(); System.out.println(name +": " + value); } } public void run(String serviceURI) { MathServiceAddressingLocator locator = new MathServiceAddressingLocator(); try { // Create endpoint reference to service EndpointReferenceType endpoint = new EndpointReferenceType(); endpoint.setAddress(new Address(serviceURI)); MathPortType math = locator.getMathPortTypePort(endpoint); // Get PortType math = locator.getMathPortTypePort(endpoint); // Perform some operations and print out the resource properties printResourceProperties(math); math.add(10); printResourceProperties(math); System.out.println(); updateRP(endpoint, MathQNames.RP_VALUE, "100"); printResourceProperties(math); System.out.println(); printMultipleResourceProperties(math); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { Client client = new Client(); client.run(args[0]); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -