1 /* 2 (C) Copyright IBM Corp. 2007, 2009 3 4 THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE 5 ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE 6 CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT. 7 8 You can obtain a current copy of the Eclipse Public License from 9 http://www.opensource.org/licenses/eclipse-1.0.php 10 11 @author : Endre Bak, IBM, ebak@de.ibm.com 12 * 13 * Change History 14 * Flag Date Prog Description 15 *------------------------------------------------------------------------------- 16 * 1804402 2007-09-28 ebak IPv6 ready SLP 17 * 1892103 2008-02-12 ebak SLP improvements 18 * 1949918 2008-04-08 raman_arora Malformed service URL crashes SLP discovery 19 * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL 20 * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1) 21 * 2531371 2009-02-10 raman_arora Upgrade client to JDK 1.5 (Phase 2) 22 */ 23 24 package org.metricshub.wbem.sblim.slp.internal.msg; 25 26 /*- 27 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 28 * WBEM Java Client 29 * ჻჻჻჻჻჻ 30 * Copyright 2023 - 2025 MetricsHub 31 * ჻჻჻჻჻჻ 32 * Licensed under the Apache License, Version 2.0 (the "License"); 33 * you may not use this file except in compliance with the License. 34 * You may obtain a copy of the License at 35 * 36 * http://www.apache.org/licenses/LICENSE-2.0 37 * 38 * Unless required by applicable law or agreed to in writing, software 39 * distributed under the License is distributed on an "AS IS" BASIS, 40 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 41 * See the License for the specific language governing permissions and 42 * limitations under the License. 43 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 44 */ 45 46 import java.io.IOException; 47 import java.util.ArrayList; 48 import java.util.Iterator; 49 import java.util.List; 50 import org.metricshub.wbem.sblim.slp.ServiceLocationException; 51 import org.metricshub.wbem.sblim.slp.ServiceURL; 52 53 /* 54 * 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Service 56 * Location header (function = SrvRply = 2) | 57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error 58 * Code | URL Entry count | 59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | <URL 60 * Entry 1> ... <URL Entry N> \ 61 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 62 */ 63 /** 64 * ServiceReply message 65 * 66 */ 67 public class ServiceReply extends ReplyMessage { 68 private List<ServiceURL> iURLEntries; 69 70 private List<Exception> iURLExceptions; 71 72 /** 73 * parse 74 * 75 * @param pHdr 76 * @param pInStr 77 * @return SLPMessage 78 * @throws ServiceLocationException 79 * @throws IOException 80 */ 81 public static SLPMessage parse(MsgHeader pHdr, SLPInputStream pInStr) throws ServiceLocationException, IOException { 82 int errorCode = pInStr.read16(); 83 ArrayList<Exception> urlExceptions = new ArrayList<Exception>(); 84 List<ServiceURL> urlEntries = pInStr.readUrlList(urlExceptions); 85 return new ServiceReply(pHdr, errorCode, urlEntries, urlExceptions); 86 } 87 88 /** 89 * Ctor. 90 * 91 * @param pErrorCode 92 * @param pURLEntries 93 * - list of ServiceURLs 94 */ 95 public ServiceReply(int pErrorCode, List<ServiceURL> pURLEntries) { 96 super(SRV_RPLY, pErrorCode); 97 this.iURLEntries = pURLEntries; 98 } 99 100 /** 101 * Ctor. 102 * 103 * @param pLangTag 104 * @param pErrorCode 105 * @param pURLEntries 106 * - list of ServiceURLs 107 * @param pURLExceptions 108 * - list of URL Exceptions 109 */ 110 public ServiceReply(String pLangTag, int pErrorCode, List<ServiceURL> pURLEntries, List<Exception> pURLExceptions) { 111 super(SRV_RPLY, pLangTag, pErrorCode); 112 this.iURLEntries = pURLEntries; 113 this.iURLExceptions = pURLExceptions; 114 } 115 116 /** 117 * Ctor. 118 * 119 * @param pHeader 120 * @param pErrorCode 121 * @param pURLEntries 122 * - list of ServiceURLs 123 * @param pURLExceptions 124 * - list of URL Exceptions 125 */ 126 public ServiceReply(MsgHeader pHeader, int pErrorCode, List<ServiceURL> pURLEntries, List<Exception> pURLExceptions) { 127 super(pHeader, pErrorCode); 128 this.iURLEntries = pURLEntries; 129 this.iURLExceptions = pURLExceptions; 130 } 131 132 /** 133 * getResultIterator 134 * 135 * @return iterator of URL Exception list 136 */ 137 @Override 138 public Iterator<ServiceURL> getResultIterator() { 139 return this.iURLEntries == null ? null : this.iURLEntries.iterator(); 140 } 141 142 /** 143 * getExceptionIterator 144 * 145 * @return iterator of URL Exception list 146 */ 147 @Override 148 public Iterator<Exception> getExceptionIterator() { 149 return this.iURLExceptions == null ? null : this.iURLExceptions.iterator(); 150 } 151 152 /** 153 * getURLEntries 154 * 155 * @return list of ServiceURLs 156 */ 157 public List<ServiceURL> getURLEntries() { 158 return this.iURLEntries; 159 } 160 161 /** 162 * getURLExceptions 163 * 164 * @return list of URL Exceptions 165 */ 166 public List<Exception> getURLExceptions() { 167 return this.iURLExceptions; 168 } 169 170 /** 171 * @param pOption 172 */ 173 @Override 174 protected boolean serializeBody(SLPOutputStream pOutStr, SerializeOption pOption) { 175 return pOutStr.write16(getErrorCode()) && pOutStr.writeURLList(this.iURLEntries); 176 } 177 }