📄 aleclient.java
字号:
/* * Copyright (c) 2005-2006, logicAlloy, Inc. All Rights Reserved. * * Licensed under the Sleepycat License (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.opensource.org/licenses/sleepycat.php * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.logicalloy.ale.client;import com.logicalloy.ale.*;import epcglobalAleWsdl1.*;import epcglobalAleXsd1.ECReports;import epcglobalAleXsd1.ECSpec;import org.apache.log4j.Logger;import org.codehaus.xfire.client.Client;import org.codehaus.xfire.client.XFireProxy;import org.codehaus.xfire.transport.http.HttpTransport;import java.lang.reflect.Proxy;import java.util.Arrays;import java.util.List;/** * This class is used to access the logicalloy ALE system. This is not compatable with other ALE implementations * as this class handles loging in and performs automatic sessionHeader management. * * Use this class by creating and instance and passing the endpoint URL of the ALE instance you wish to connect to. * You MUST first call 'login' before subsequent calls (except for getALEID, getStandardVersion, and getVendorVersion). * * @author Edward Blazer (edward.blazer@logicalloy.com) */public class ALEClient { private static final Logger logger = Logger.getLogger(ALEClient.class); private ALEServicePortType aleService; private SessionHeaderDocument sh = SessionHeaderDocument.Factory.newInstance(); private LoginResult lr; private boolean isLoggedIn; public ALEClient(String endPoint) { logger.trace("ALEClient :: enter"); ALEServiceClient service = new ALEServiceClient(); aleService = service.getALEServicePort(endPoint); Client client = ((XFireProxy)Proxy.getInvocationHandler(aleService)).getClient(); client.setProperty("mtom-enabled", "true"); client.setProperty(HttpTransport.CHUNKING_ENABLED, "true"); logger.trace("ALEClient :: exit"); } public boolean login(String username, String password) throws SecurityExceptionResponse, ImplementationExceptionResponse { logger.trace("login :: enter"); LoginDocument ld = LoginDocument.Factory.newInstance(); Login l = ld.addNewLogin(); l.setUsername(username); l.setPassword(password); LoginResultDocument lrd = aleService.login(ld); lr = lrd.getLoginResult(); isLoggedIn = lr.getSuccess(); if (isLoggedIn) { //sh = SessionHeaderDocument.Factory.newInstance(); sh.addNewSessionHeader().setSessionId(lr.getSessionId()); } logger.trace("login :: exit"); return isLoggedIn; } public LoginResult getLoginResult() { logger.trace("getLoginResult :: enter/exit"); return lr; } public boolean isLoggedIn() { logger.trace("isLoggedIn :: enter/exit"); return isLoggedIn; } public void define(String specName, ECSpec spec) throws DuplicateNameExceptionResponse, ImplementationExceptionResponse, SecurityExceptionResponse, ECSpecValidationExceptionResponse { logger.trace("define :: enter"); DefineDocument doc = DefineDocument.Factory.newInstance(); Define d = doc.addNewDefine(); d.setSpecName(specName); d.setSpec(spec); aleService.define(doc, sh); logger.trace("define :: exit"); } public ECReports poll(String specName) throws ImplementationExceptionResponse, SecurityExceptionResponse, NoSuchNameExceptionResponse { logger.trace("poll :: enter"); PollDocument doc = PollDocument.Factory.newInstance(); Poll p = doc.addNewPoll(); p.setSpecName(specName); ECReports reports = aleService.poll(doc, sh).getPollResult(); logger.trace("poll :: exit"); return reports; } public ECReports immediate(ECSpec spec) throws ImplementationExceptionResponse, SecurityExceptionResponse, ECSpecValidationExceptionResponse { logger.trace("immediate :: enter"); ImmediateDocument doc = ImmediateDocument.Factory.newInstance(); Immediate i = doc.addNewImmediate(); i.setSpec(spec); ImmediateResultDocument ird = aleService.immediate(doc, sh); ECReports reports = ird.getImmediateResult(); logger.trace("immediate :: exit"); return reports; } public void undefine(String specName) throws ImplementationExceptionResponse, SecurityExceptionResponse, NoSuchNameExceptionResponse { logger.trace("undefine :: enter"); UndefineDocument doc = UndefineDocument.Factory.newInstance(); Undefine u = doc.addNewUndefine(); u.setSpecName(specName); aleService.undefine(doc, sh); logger.trace("undefine :: exit"); } public ECSpec getECSpec(String specName) throws ImplementationExceptionResponse, SecurityExceptionResponse, NoSuchNameExceptionResponse { logger.trace("getECSpec :: enter"); GetECSpecDocument doc = GetECSpecDocument.Factory.newInstance(); GetECSpec g = doc.addNewGetECSpec(); g.setSpecName(specName); ECSpec spec = aleService.getECSpec(doc, sh).getGetECSpecResult(); logger.trace("getECSpec :: exit"); return spec; } public void subscribe(String specName, String notificationURI) throws DuplicateSubscriptionExceptionResponse, ImplementationExceptionResponse, SecurityExceptionResponse, InvalidURIExceptionResponse, NoSuchNameExceptionResponse { logger.trace("subscribe :: enter"); SubscribeDocument doc = SubscribeDocument.Factory.newInstance(); Subscribe s = doc.addNewSubscribe(); s.setNotificationURI(notificationURI); s.setSpecName(specName); aleService.subscribe(doc, sh); logger.trace("subscribe :: exit"); } public void unsubscribe(String specName, String notificationURI) throws NoSuchSubscriberExceptionResponse, ImplementationExceptionResponse, SecurityExceptionResponse, InvalidURIExceptionResponse, NoSuchNameExceptionResponse { logger.trace("unsubscribe :: enter"); UnsubscribeDocument doc = UnsubscribeDocument.Factory.newInstance(); Unsubscribe u = doc.addNewUnsubscribe(); u.setNotificationURI(notificationURI); u.setSpecName(specName); aleService.unsubscribe(doc, sh); logger.trace("unsubscribe :: exit"); } public List<String> getSubscribers(String specName) throws ImplementationExceptionResponse, SecurityExceptionResponse, NoSuchNameExceptionResponse { logger.trace("getSubscribers :: enter"); GetSubscribersDocument doc = GetSubscribersDocument.Factory.newInstance(); GetSubscribers g = doc.addNewGetSubscribers(); g.setSpecName(specName); ArrayOfString aos = aleService.getSubscribers(doc, sh).getGetSubscribersResult(); List<String> subscribers = Arrays.asList(aos.getStringArray()); logger.trace("getSubscribers :: exit"); return subscribers; } public List<String> getECSpecNames() throws ImplementationExceptionResponse, SecurityExceptionResponse { logger.trace("getECSpecNames :: enter"); GetECSpecNamesDocument doc = GetECSpecNamesDocument.Factory.newInstance(); doc.addNewGetECSpecNames(); ArrayOfString aos = aleService.getECSpecNames(doc, sh).getGetECSpecNamesResult(); List<String> names = Arrays.asList(aos.getStringArray()); logger.trace("getECSpecNames :: exit"); return names; } public String getStandardVersion() throws ImplementationExceptionResponse { logger.trace("getStandardVersion :: enter/exit"); GetStandardVersionDocument doc = GetStandardVersionDocument.Factory.newInstance(); doc.addNewGetStandardVersion(); return aleService.getStandardVersion(doc).getGetStandardVersionResult(); } public String getVendorVersion() throws ImplementationExceptionResponse { logger.trace("getVendorVersion :: enter/exit"); GetVendorVersionDocument doc = GetVendorVersionDocument.Factory.newInstance(); doc.addNewGetVendorVersion(); return aleService.getVendorVersion(doc).getGetVendorVersionResult(); } public String getALEID() throws ImplementationExceptionResponse { logger.trace("getALEID :: enter/exit"); GetALEIDDocument doc = GetALEIDDocument.Factory.newInstance(); doc.addNewGetALEID(); return aleService.getALEID(doc).getGetALEIDResult(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -