use of org.apache.axis.client.Service in project Lucee by lucee.
the class Axis1Client method _call.
private Object _call(PageContext pc, Config secondChanceConfig, String methodName, Struct namedArguments, Object[] arguments) throws PageException, ServiceException, RemoteException {
ApplicationContextSupport acs = (ApplicationContextSupport) pc.getApplicationContext();
javax.wsdl.Service service = getWSDLService();
Service axisService = new Service(parser, service.getQName());
axisService.setMaintainSession(acs.getWSMaintainSession());
TypeMappingUtil.registerDefaults(axisService.getTypeMappingRegistry());
Port port = WSUtil.getSoapPort(service);
Binding binding = port.getBinding();
SymbolTable symbolTable = parser.getSymbolTable();
BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
// get matching operation/method
Iterator<Entry<Operation, Parameters>> itr = bEntry.getParameters().entrySet().iterator();
Operation operation = null;
Entry<Operation, Parameters> e;
Parameters parameters = null;
while (itr.hasNext()) {
e = itr.next();
if (e.getKey().getName().equalsIgnoreCase(methodName)) {
operation = e.getKey();
parameters = e.getValue();
break;
}
}
// no operation found!
if (operation == null || parameters == null) {
// get array of existing methods
Set<Operation> set = bEntry.getParameters().keySet();
Iterator<Operation> it = set.iterator();
Collection.Key[] keys = new Collection.Key[set.size()];
int index = 0;
while (it.hasNext()) {
keys[index++] = KeyImpl.init(it.next().getName());
}
throw new RPCException(ExceptionUtil.similarKeyMessage(keys, methodName, "method/operation", "methods/operations", null, true) + " Webservice: " + wsdlUrl);
}
org.apache.axis.client.Call call = (Call) axisService.createCall(QName.valueOf(port.getName()), QName.valueOf(operation.getName()));
if (!StringUtil.isEmpty(username, true)) {
call.setUsername(username);
call.setPassword(password);
}
org.apache.axis.encoding.TypeMapping tm = call.getTypeMapping();
Vector<String> inNames = new Vector<String>();
Vector<Parameter> inTypes = new Vector<Parameter>();
Vector<String> outNames = new Vector<String>();
Vector<Parameter> outTypes = new Vector<Parameter>();
Parameter p = null;
for (int j = 0; j < parameters.list.size(); j++) {
p = (Parameter) parameters.list.get(j);
map(pc, symbolTable, secondChanceConfig, tm, p.getType());
switch(p.getMode()) {
case Parameter.IN:
inNames.add(p.getQName().getLocalPart());
inTypes.add(p);
break;
case Parameter.OUT:
outNames.add(p.getQName().getLocalPart());
outTypes.add(p);
break;
case Parameter.INOUT:
inNames.add(p.getQName().getLocalPart());
inTypes.add(p);
outNames.add(p.getQName().getLocalPart());
outTypes.add(p);
break;
}
}
// set output type
if (parameters.returnParam != null) {
QName rtnQName = parameters.returnParam.getQName();
// TypeEntry rtnType = parameters.returnParam.getType();
map(pc, symbolTable, secondChanceConfig, tm, parameters.returnParam.getType());
outNames.add(rtnQName.getLocalPart());
outTypes.add(parameters.returnParam);
}
// get timezone
TimeZone tz;
if (pc == null)
tz = ThreadLocalPageContext.getTimeZone(secondChanceConfig);
else
tz = ThreadLocalPageContext.getTimeZone(pc);
// check arguments
Object[] inputs = new Object[inNames.size()];
if (arguments != null) {
if (inNames.size() != arguments.length)
throw new RPCException("Invalid arguments count for operation " + methodName + " (" + arguments.length + " instead of " + inNames.size() + ")");
for (int pos = 0; pos < inNames.size(); pos++) {
p = inTypes.get(pos);
inputs[pos] = getArgumentData(tm, tz, p, arguments[pos]);
}
} else {
UDFUtil.argumentCollection(namedArguments);
if (inNames.size() != namedArguments.size())
throw new RPCException("Invalid arguments count for operation " + methodName + " (" + namedArguments.size() + " instead of " + inNames.size() + ")");
Object arg;
for (int pos = 0; pos < inNames.size(); pos++) {
p = inTypes.get(pos);
arg = namedArguments.get(KeyImpl.init(p.getName()), null);
if (arg == null) {
throw new RPCException("Invalid arguments for operation " + methodName, getErrorDetailForArguments(inNames.toArray(new String[inNames.size()]), CollectionUtil.keysAsString(namedArguments)));
}
inputs[pos] = getArgumentData(tm, tz, p, arg);
}
}
Object ret = null;
// add header
if (headers != null && !headers.isEmpty()) {
Iterator<SOAPHeaderElement> it = headers.iterator();
while (it.hasNext()) {
call.addHeader(it.next());
}
}
try {
ret = invoke(call, inputs);
} catch (AxisFault af) {
boolean rethrow = true;
Throwable cause = af.getCause();
if (cause != null) {
/*
// first check if that missing type is around
String[] notFound=new String[]{"could not find deserializer for type","No deserializer for"};
int index;
if(msg!=null)for(int i=0; i<notFound.length;i++) {
if((index=msg.indexOf(notFound[i]))==-1)continue;;
String raw=msg.substring(index+notFound[i].length()+1).trim();
QName qn = QName.valueOf(raw);
print.e(qn.getLocalPart());
print.e(qn.getNamespaceURI());
Type type = symbolTable.getType(qn);
if(type!=null) {
map(pc,secondChanceConfig,call.getTypeMapping(),type);
ret = invoke(call,inputs);
rethrow=false;
}
}*/
// get the missing types from the SOAP Body, if possible
String msg = cause.getMessage();
// if(StringUtil.indexOfIgnoreCase(msg, "deserializer")!=-1) {
try {
InputSource is = new InputSource(new StringReader(call.getResponseMessage().getSOAPPartAsString()));
Document doc = XMLUtil.parse(is, null, false);
Element body = XMLUtil.getChildWithName("soapenv:Body", doc.getDocumentElement());
Vector types = SOAPUtil.getTypes(body, symbolTable);
map(pc, symbolTable, secondChanceConfig, (org.apache.axis.encoding.TypeMapping) (axisService.getTypeMappingRegistry().getDefaultTypeMapping()), types);
ret = invoke(call, inputs);
rethrow = false;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
// }
}
if (rethrow)
throw af;
}
last = call;
if (outNames.size() <= 1)
return AxisCaster.toLuceeType(null, ret);
// getParamData((org.apache.axis.client.Call)call,parameters.returnParam,ret);
Map outputs = call.getOutputParams();
Struct sct = new StructImpl();
for (int pos = 0; pos < outNames.size(); pos++) {
String name = outNames.get(pos);
// print.ln(name);
Object value = outputs.get(name);
if (value == null && pos == 0) {
sct.setEL(name, AxisCaster.toLuceeType(null, ret));
} else {
sct.setEL(name, AxisCaster.toLuceeType(null, value));
}
}
return sct;
}
use of org.apache.axis.client.Service in project tomee by apache.
the class SeiFactoryImpl method initialize.
void initialize(Object serviceImpl, ClassLoader classLoader) throws ClassNotFoundException {
this.serviceImpl = serviceImpl;
Class serviceEndpointBaseClass = classLoader.loadClass(serviceEndpointClassName);
serviceEndpointClass = enhanceServiceEndpointInterface(serviceEndpointBaseClass, classLoader);
Class[] constructorTypes = new Class[] { classLoader.loadClass(GenericServiceEndpoint.class.getName()) };
this.constructor = FastClass.create(serviceEndpointClass).getConstructor(constructorTypes);
this.handlerInfoChainFactory = new HandlerInfoChainFactory(handlerInfos);
sortedOperationInfos = new OperationInfo[FastClass.create(serviceEndpointClass).getMaxIndex() + 1];
String encodingStyle = "";
for (int i = 0; i < operationInfos.length; i++) {
OperationInfo operationInfo = operationInfos[i];
Signature signature = operationInfo.getSignature();
MethodProxy methodProxy = MethodProxy.find(serviceEndpointClass, signature);
if (methodProxy == null) {
throw new ServerRuntimeException("No method proxy for operationInfo " + signature);
}
int index = methodProxy.getSuperIndex();
sortedOperationInfos[index] = operationInfo;
if (operationInfo.getOperationDesc().getUse() == Use.ENCODED) {
encodingStyle = org.apache.axis.Constants.URI_SOAP11_ENC;
}
}
// register our type descriptors
Service service = ((ServiceImpl) serviceImpl).getService();
AxisEngine axisEngine = service.getEngine();
TypeMappingRegistry typeMappingRegistry = axisEngine.getTypeMappingRegistry();
TypeMapping typeMapping = typeMappingRegistry.getOrMakeTypeMapping(encodingStyle);
typeMapping.register(BigInteger.class, Constants.XSD_UNSIGNEDLONG, new SimpleSerializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG), new SimpleDeserializerFactory(BigInteger.class, Constants.XSD_UNSIGNEDLONG));
typeMapping.register(URI.class, Constants.XSD_ANYURI, new SimpleSerializerFactory(URI.class, Constants.XSD_ANYURI), new SimpleDeserializerFactory(URI.class, Constants.XSD_ANYURI));
// It is essential that the types be registered before the typeInfos create the serializer/deserializers.
for (Iterator iter = typeInfo.iterator(); iter.hasNext(); ) {
TypeInfo info = (TypeInfo) iter.next();
TypeDesc.registerTypeDescForClass(info.getClazz(), info.buildTypeDesc());
}
TypeInfo.register(typeInfo, typeMapping);
}
use of org.apache.axis.client.Service in project tomee by apache.
the class SeiFactoryImpl method createServiceEndpoint.
public Remote createServiceEndpoint() throws ServiceException {
// TODO figure out why this can't be called in readResolve!
// synchronized (this) {
// if (!initialized) {
// initialize();
// initialized = true;
// }
// }
Service service = ((ServiceImpl) serviceImpl).getService();
GenericServiceEndpoint serviceEndpoint = new GenericServiceEndpoint(portQName, service, location);
Callback callback = new ServiceEndpointMethodInterceptor(serviceEndpoint, sortedOperationInfos, credentialsName);
Callback[] callbacks = new Callback[] { NoOp.INSTANCE, callback };
Enhancer.registerCallbacks(serviceEndpointClass, callbacks);
try {
return (Remote) constructor.newInstance(new Object[] { serviceEndpoint });
} catch (InvocationTargetException e) {
throw (ServiceException) new ServiceException("Could not construct service instance", e.getTargetException()).initCause(e);
}
}
use of org.apache.axis.client.Service in project tomee by apache.
the class AxisServiceReference method createServiceInterfaceProxy.
private Object createServiceInterfaceProxy(String serviceInterfaceClassName, Map seiPortNameToFactoryMap, Map seiClassNameToFactoryMap, ClassLoader classLoader) throws NamingException {
boolean initialize = (this.serviceConstructor == null);
if (initialize) {
Class serviceInterface;
try {
serviceInterface = classLoader.loadClass(serviceInterfaceClassName);
} catch (ClassNotFoundException e) {
throw (NamingException) new NamingException("Could not load service interface class " + serviceInterfaceClassName).initCause(e);
}
// create method interceptors
Callback callback = new ServiceMethodInterceptor(seiPortNameToFactoryMap);
this.methodInterceptors = new Callback[] { NoOp.INSTANCE, callback };
// create service class
Enhancer enhancer = new Enhancer();
enhancer.setClassLoader(classLoader);
enhancer.setSuperclass(ServiceImpl.class);
enhancer.setInterfaces(new Class[] { serviceInterface });
enhancer.setCallbackFilter(new NoOverrideCallbackFilter(Service.class));
enhancer.setCallbackTypes(new Class[] { NoOp.class, MethodInterceptor.class });
enhancer.setUseFactory(false);
enhancer.setUseCache(false);
this.enhancedServiceClass = enhancer.createClass();
// get constructor
this.serviceConstructor = FastClass.create(this.enhancedServiceClass).getConstructor(SERVICE_CONSTRUCTOR_TYPES);
}
// associate the method interceptors with the generated service class on the current thread
Enhancer.registerCallbacks(this.enhancedServiceClass, this.methodInterceptors);
Object[] arguments = new Object[] { seiPortNameToFactoryMap, seiClassNameToFactoryMap };
Object serviceInstance = null;
try {
serviceInstance = this.serviceConstructor.newInstance(arguments);
} catch (InvocationTargetException e) {
throw (NamingException) new NamingException("Could not construct service instance").initCause(e.getTargetException());
}
if (initialize) {
for (Iterator iterator = seiPortNameToFactoryMap.values().iterator(); iterator.hasNext(); ) {
SeiFactoryImpl seiFactory = (SeiFactoryImpl) iterator.next();
try {
seiFactory.initialize(serviceInstance, classLoader);
} catch (ClassNotFoundException e) {
throw (NamingException) new NamingException("Could not load service interface class; " + e.getMessage()).initCause(e);
}
}
}
return serviceInstance;
}
use of org.apache.axis.client.Service in project portal by ixinportal.
the class ReceiptConfigService method receiptTest.
// 电票查询票数测试
public Map<String, Object> receiptTest(String idCode) {
Map<String, Object> re = new HashMap<String, Object>();
re.put("retCode", false);
re.put("retMsg", "测试失败");
Call call;
String val = "";
String content = "<REQUEST_COMMON_FPKCCX class='REQUEST_COMMON_FPKCCX'> <NSRSBH>" + idCode + "</NSRSBH> </REQUEST_COMMON_FPKCCX> ";
try {
String xml = getCommonXml("DFXJ1001", new BASE64Encoder().encodeBuffer(content.getBytes("UTF-8")));
String ssl_store = "D:/cer/fapiao_ceshi.truststore";
String ssl_pwd = "654321";
System.setProperty("javax.net.ssl.trustStore", ssl_store);
System.setProperty("javax.net.ssl.keyStorePassword", ssl_pwd);
HostnameVerifier hv = new HostnameVerifier() {
public boolean verify(String urlHostName, SSLSession session) {
System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
Service s = new Service();
call = (Call) s.createCall();
call.setTargetEndpointAddress(new java.net.URL("https://202.104.113.26:8999/fpt_dsqz/services/DZFPService"));
call.setOperation("doService");
Object[] fn01 = { xml };
System.out.println(xml);
val = (String) call.invoke(fn01);
if (StringUtils.isNotEmpty(val)) {
re.put("retCode", true);
re.put("retMsg", "测试成功");
}
System.out.println(val);
} catch (Exception e) {
e.printStackTrace();
}
return re;
}
Aggregations