当前位置: 首页>>代码示例>>Java>>正文


Java PacketError类代码示例

本文整理汇总了Java中org.xmpp.packet.PacketError的典型用法代码示例。如果您正苦于以下问题:Java PacketError类的具体用法?Java PacketError怎么用?Java PacketError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PacketError类属于org.xmpp.packet包,在下文中一共展示了PacketError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleIQ

import org.xmpp.packet.PacketError; //导入依赖的package包/类
@Override
public IQ handleIQ(IQ iq)
{
    IQ reply = IQ.createResultIQ(iq);

    try {
        Log.info("Openfire Meetings handleIQ \n" + iq.toString());
        final Element element = iq.getChildElement();

        JSONObject requestJSON = new JSONObject( element.getText());
        String action = requestJSON.getString("action");

        if ("get_user_properties".equals(action)) getUserProperties(iq.getFrom().getNode(), reply, requestJSON);
        if ("set_user_properties".equals(action)) setUserProperties(iq.getFrom().getNode(), reply, requestJSON);
        if ("get_user_groups".equals(action)) getUserGroups(iq.getFrom().getNode(), reply, requestJSON);
        if ("get_group".equals(action)) getGroup(iq.getFrom().getNode(), reply, requestJSON);
        if ("get_conference_id".equals(action)) getConferenceId(iq.getFrom().getNode(), reply, requestJSON);

        return reply;

    } catch(Exception e) {
        Log.error("Openfire Meetings handleIQ", e);
        reply.setError(new PacketError(PacketError.Condition.internal_server_error, PacketError.Type.modify, e.toString()));
        return reply;
    }
}
 
开发者ID:igniterealtime,项目名称:ofmeet-openfire-plugin,代码行数:27,代码来源:OfMeetIQHandler.java

示例2: setUserProperties

import org.xmpp.packet.PacketError; //导入依赖的package包/类
private void setUserProperties(String username, IQ reply, JSONObject requestJSON)
{
    Element childElement = reply.setChildElement("response", "http://igniterealtime.org/protocol/ofmeet");

    try {
        UserManager userManager = XMPPServer.getInstance().getUserManager();
        User user = userManager.getUser(username);

        if (requestJSON != null)
        {
            Iterator<?> keys = requestJSON.keys();

            while( keys.hasNext() )
            {
                String key = (String)keys.next();
                String value = requestJSON.getString(key);

                user.getProperties().put(key, value);
            }
        }

    } catch (Exception e) {
        reply.setError(new PacketError(PacketError.Condition.not_allowed, PacketError.Type.modify, "User " + username + " " + requestJSON.toString() + " " + e));
        return;
    }
}
 
开发者ID:igniterealtime,项目名称:ofmeet-openfire-plugin,代码行数:27,代码来源:OfMeetIQHandler.java

示例3: handleIQ

import org.xmpp.packet.PacketError; //导入依赖的package包/类
@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException {
	IQ reply = null;

	ClientSession session = sessionManager.getSession(packet.getFrom());
	if (session == null) {
		log.error("未找到Key的Session " + packet.getFrom());
		reply = IQ.createResultIQ(packet);
		reply.setChildElement(packet.getChildElement().createCopy());
		reply.setError(PacketError.Condition.internal_server_error);
		return reply;
	}

	if (session.getStatus() == Session.STATUS_AUTHENTICATED) {
		if (IQ.Type.set.equals(packet.getType())) {
			Element element = packet.getChildElement();
			String uuid = element.elementText("uuid");
			notificationService.deleteNotificationByUUID(uuid);
		}
	}
	return null;
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:23,代码来源:IQDeliverConfirmHandler.java

示例4: route

import org.xmpp.packet.PacketError; //导入依赖的package包/类
/**
 * 路由这个Presence包
 * 
 * @param packet
 */
public void route(Presence packet) {
	if (packet == null) {
		throw new NullPointerException();
	}
	ClientSession session = sessionManager.getSession(packet.getFrom());

	if (session == null || session.getStatus() != Session.STATUS_CONNECTED) {
		handle(packet);
	} else {
		packet.setTo(session.getAddress());
		packet.setFrom((JID) null);
		packet.setError(PacketError.Condition.not_authorized);
		session.process(packet);
	}
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:21,代码来源:PresenceRouter.java

示例5: route

import org.xmpp.packet.PacketError; //导入依赖的package包/类
/**
 * 路由基于命名空间的IQ数据包。
 * 
 * @param packet
 */
public void route(IQ packet) {
	if (packet == null) {
		throw new NullPointerException();
	}
	JID sender = packet.getFrom();
	ClientSession session = sessionManager.getSession(sender);

	if (session == null
			|| session.getStatus() == Session.STATUS_AUTHENTICATED
			|| ("jabber:iq:auth".equals(packet.getChildElement()
					.getNamespaceURI())
					|| "jabber:iq:register".equals(packet.getChildElement()
							.getNamespaceURI()) || "urn:ietf:params:xml:ns:xmpp-bind"
						.equals(packet.getChildElement().getNamespaceURI()))) {
		handle(packet);
	} else {
		IQ reply = IQ.createResultIQ(packet);
		reply.setChildElement(packet.getChildElement().createCopy());
		reply.setError(PacketError.Condition.not_authorized);
		session.process(reply);
	}
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:28,代码来源:IQRouter.java

示例6: sendErrorPacket

import org.xmpp.packet.PacketError; //导入依赖的package包/类
/**
 * 将错误数据包发送给原始发件人
 * 
 * @param originalPacket
 * @param condition
 */
private void sendErrorPacket(IQ originalPacket,
		PacketError.Condition condition) {
	if (IQ.Type.error == originalPacket.getType()) {
		log.error("不能回答一个IQ错误到另一个IQ错误: " + originalPacket);
		return;
	}
	IQ reply = IQ.createResultIQ(originalPacket);
	reply.setChildElement(originalPacket.getChildElement().createCopy());
	reply.setError(condition);
	try {
		PacketDeliverer.deliver(reply);
	} catch (Exception e) {
		// Ignore
	}
}
 
开发者ID:lijian17,项目名称:androidpn-server,代码行数:22,代码来源:IQRouter.java

示例7: sendErrorResponse

import org.xmpp.packet.PacketError; //导入依赖的package包/类
/**
 * Send an error response to the passed incoming request. Throws
 * IllegalArgumentException if the original packet is also an error, or is of
 * the IQ result type.
 *
 * According to RFC 3920 (9.3.1), the error packet may contain the original
 * packet. However, this implementation does not include it.
 *
 * @param request packet request, to/from is inverted for response
 * @param error packet error describing error condition
 */
void sendErrorResponse(Packet request, PacketError error) {
  if (request instanceof IQ) {
    IQ.Type type = ((IQ) request).getType();
    if (!(type.equals(IQ.Type.get) ||  type.equals(IQ.Type.set))) {
      throw new IllegalArgumentException("May only return an error to IQ get/set, not: " + type);
    }
  } else if (request instanceof Message) {
    Message message = (Message) request;
    if (message.getType().equals(Message.Type.error)) {
      throw new IllegalArgumentException("Can't return an error to another message error");
    }
  } else {
    throw new IllegalArgumentException("Unexpected Packet subclass, expected Message/IQ: "
        + request.getClass());
  }

  LOG.fine("Sending error condition in response to " + request.getID() + ": "
      + error.getCondition().name());

  // Note that this does not include the original packet; just the ID.
  final Packet response = XmppUtil.createResponsePacket(request);
  response.setError(error);

  transport.sendPacket(response);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:37,代码来源:XmppManager.java

示例8: toPacketError

import org.xmpp.packet.PacketError; //导入依赖的package包/类
/**
 * Convert a FederationError instance to a PacketError. This may return
 * <undefined-condition> if the incoming error can't be understood.
 *
 * @param error the incoming error
 * @return a generated PacketError instance
 * @throws IllegalArgumentException if the OK error code is given
 */
private static PacketError toPacketError(FederationError error) {
  Preconditions.checkArgument(error.getErrorCode() != FederationError.Code.OK);

  String tag = error.getErrorCode().name().toLowerCase().replace('_', '-');
  PacketError.Condition condition;
  try {
    condition = PacketError.Condition.fromXMPP(tag);
  } catch (IllegalArgumentException e) {
    condition = PacketError.Condition.undefined_condition;
    LOG.warning("Did not understand error condition, defaulting to: " + condition.name());
  }
  PacketError result = new PacketError(condition);
  if (error.hasErrorMessage()) {
    // TODO(thorogood): Hide this behind a flag so we don't always broadcast error cases.
    result.setText(error.getErrorMessage(), "en");
  }
  return result;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:27,代码来源:XmppManager.java

示例9: testDiscoItemsFallback

import org.xmpp.packet.PacketError; //导入依赖的package包/类
/**
 * Tests that if a disco items requests fails due to some error, that we still
 * perform a disco info request on fallback JIDs.
 */
public void testDiscoItemsFallback() {
  XmppUtil.fakeUniqueId = DISCO_INFO_ID;
  disco.discoverRemoteJid(REMOTE_DOMAIN, discoCallback);
  assertEquals("Should have sent disco packet", 1, transport.packetsSent);
  checkAndResetStats(1, 0, 0);  // started

  // Generate an error response.
  IQ errorResponse = IQ.createResultIQ((IQ) transport.packets.poll());
  errorResponse.setError(PacketError.Condition.conflict);
  manager.receivePacket(errorResponse);

  // Confirm that two outgoing packets are sent.
  assertEquals(3, transport.packetsSent);

  // Expect a wave request
  Packet wavePacket = transport.packets.poll();
  assertEquals(EXPECTED_DISCO_INFO_GET, wavePacket.toString());

  // Expect packet targeted at TLD
  Packet pubsubPacket = transport.packets.poll();
  assertEquals(REMOTE_DOMAIN, pubsubPacket.getTo().toBareJID());
  checkAndResetStats(0, 0, 0);  // not finished yet
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:28,代码来源:XmppDiscoTest.java

示例10: testUnhandledErrorResponse

import org.xmpp.packet.PacketError; //导入依赖的package包/类
/**
 * Test that an unhandled error (e.g. <forbidden>) is translated to
 * UNDEFINED_CONDITION before being returned to the mocked callback.
 */
public void testUnhandledErrorResponse() {
  IQ packet = new IQ();
  packet.setFrom(server1.jid);
  packet.setID("foo");
  packet.setTo(server2.jid);

  // Disable routing so we can intercept the packet.
  server1.transport.router = null;
  PacketCallback callback = mock(PacketCallback.class);
  server1.manager.send(packet, callback, PACKET_TIMEOUT);

  // Generate an explicit error <forbidden>.
  IQ errorPacket = IQ.createResultIQ(packet);
  errorPacket.setError(PacketError.Condition.forbidden);
  server1.manager.receivePacket(errorPacket);

  // Confirm that <forbidden> is transformed to UNDEFINED_CONDITION.
  ArgumentCaptor<FederationError> returnedError = ArgumentCaptor.forClass(FederationError.class);
  verify(callback).error(returnedError.capture());
  verify(callback, never()).run(any(Packet.class));
  assertEquals(FederationError.Code.UNDEFINED_CONDITION, returnedError.getValue().getErrorCode());
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:27,代码来源:RoundTripTest.java

示例11: testSubmitRequestError

import org.xmpp.packet.PacketError; //导入依赖的package包/类
/**
 * Tests that that a submit request sent out can properly process a resulting
 * error.
 */
public void testSubmitRequestError() {
  disco.testInjectInDomainToJidMap(REMOTE_DOMAIN, REMOTE_JID);

  SubmitResultCallback listener = mock(SubmitResultCallback.class);
  remote.submitRequest(REMOTE_WAVELET, DUMMY_SIGNED_DELTA, listener);

  verifyZeroInteractions(listener);
  assertEquals(1, transport.packetsSent);

  // Validate the outgoing request.
  IQ outgoingRequest = (IQ) transport.packets.poll();
  assertEquals(EXPECTED_SUBMIT_REQUEST, outgoingRequest.toString());

  // Return a confusing error response (<registration-required>).
  IQ errorResponse = IQ.createResultIQ(outgoingRequest);
  errorResponse.setError(PacketError.Condition.registration_required);
  manager.receivePacket(errorResponse);

  // Confirm error is passed through to the callback.
  ArgumentCaptor<FederationError> error = ArgumentCaptor.forClass(FederationError.class);
  verify(listener).onFailure(error.capture());
  verify(listener, never())
      .onSuccess(anyInt(), any(ProtocolHashedVersion.class), anyLong());
  assertEquals(FederationError.Code.UNDEFINED_CONDITION, error.getValue().getErrorCode());
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:30,代码来源:XmppFederationRemoteTest.java

示例12: handleIQ

import org.xmpp.packet.PacketError; //导入依赖的package包/类
/**
 * Handles the IQ packet sent by an owner or admin of the room. Possible actions are:
 * <ul>
 * <li>Return the list of participants</li>
 * <li>Return the list of moderators</li>
 * <li>Return the list of members</li>
 * <li>Return the list of outcasts</li>
 * <li>Change user's affiliation to member</li>
 * <li>Change user's affiliation to outcast</li>
 * <li>Change user's affiliation to none</li>
 * <li>Change occupant's affiliation to moderator</li>
 * <li>Change occupant's affiliation to participant</li>
 * <li>Change occupant's affiliation to visitor</li>
 * <li>Kick occupants from the room</li>
 * </ul>
 *
 * @param packet the IQ packet sent by an owner or admin of the room.
 * @param role the role of the user that sent the request packet.
 * @throws ForbiddenException If the user is not allowed to perform his request.
 * @throws ConflictException If the desired room nickname is already reserved for the room or
 *                           if the room was going to lose all of its owners.
 * @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
 * @throws CannotBeInvitedException If the user being invited as a result of being added to a members-only room still does not have permission
 */
public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException,
        NotAllowedException, CannotBeInvitedException {
    IQ reply = IQ.createResultIQ(packet);
    Element element = packet.getChildElement();

    // Analyze the action to perform based on the included element
    @SuppressWarnings("unchecked")
    List<Element> itemsList = element.elements("item");
    
    if (!itemsList.isEmpty()) {
        handleItemsElement(role, itemsList, reply);
    }
    else {
        // An unknown and possibly incorrect element was included in the query
        // element so answer a BAD_REQUEST error
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.bad_request);
    }
    if (reply.getTo() != null) {
        // Send a reply only if the sender of the original packet was from a real JID. (i.e. not
        // a packet generated locally)
        router.route(reply);
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:49,代码来源:IQAdminHandler.java

示例13: executeGet

import org.xmpp.packet.PacketError; //导入依赖的package包/类
public void executeGet(IQ packet, Workgroup workgroup) {
    IQ reply = IQ.createResultIQ(packet);

    // Retrieve the sound settings.
    String outgoingMessage = workgroup.getProperties().getProperty("outgoingSound");
    String incomingMessage = workgroup.getProperties().getProperty("incomingSound");

    Element soundSetting = reply.setChildElement("sound-settings", "http://jivesoftware.com/protocol/workgroup");
    if (ModelUtil.hasLength(outgoingMessage) && ModelUtil.hasLength(incomingMessage)) {
        soundSetting.addElement("outgoingSound").setText(outgoingMessage);
        soundSetting.addElement("incomingSound").setText(incomingMessage);
    }
    else {
        // Throw error
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(new PacketError(PacketError.Condition.item_not_found));
    }


    workgroup.send(reply);
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:23,代码来源:SoundProvider.java

示例14: process

import org.xmpp.packet.PacketError; //导入依赖的package包/类
public void process(Packet packet) throws UnauthorizedException, PacketException {
    boolean handled = false;
    String host = packet.getTo().getDomain();
    for (Channel channel : transports.values()) {
        if (channel.getName().equalsIgnoreCase(host)) {
            channel.add(packet);
            handled = true;
        }
    }
    if (!handled) {
        JID recipient = packet.getTo();
        JID sender = packet.getFrom();
        packet.setError(PacketError.Condition.remote_server_timeout);
        packet.setFrom(recipient);
        packet.setTo(sender);
        try {
            deliverer.deliver(packet);
        }
        catch (PacketException e) {
            Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
        }
    }
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:24,代码来源:TransportHandler.java

示例15: getNodeConfiguration

import org.xmpp.packet.PacketError; //导入依赖的package包/类
private void getNodeConfiguration(PubSubService service, IQ iq, Element childElement, String nodeID) {
    Node node = service.getNode(nodeID);
    if (node == null) {
        // Node does not exist. Return item-not-found error
        sendErrorPacket(iq, PacketError.Condition.item_not_found, null);
        return;
    }
    if (!node.isAdmin(iq.getFrom())) {
        // Requesting entity is prohibited from configuring this node. Return forbidden error
        sendErrorPacket(iq, PacketError.Condition.forbidden, null);
        return;
    }

    // Return data form containing node configuration to the owner
    IQ reply = IQ.createResultIQ(iq);
    Element replyChildElement = childElement.createCopy();
    reply.setChildElement(replyChildElement);
    replyChildElement.element("configure").add(node.getConfigurationForm().getElement());
    router.route(reply);
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:21,代码来源:PubSubEngine.java


注:本文中的org.xmpp.packet.PacketError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。