Java源码示例:javax.xml.ws.LogicalMessage
示例1
private boolean checkServerOutBindStopHandler(boolean outbound, T ctx) {
if (outbound) {
LogicalMessage msg = ctx.getMessage();
Object obj = msg.getPayload(jaxbCtx);
if (obj instanceof PingResponse) {
// only check if we need call for the server response handler false
PingResponse origResp = (PingResponse)obj;
for (String handler : origResp.getHandlersInfo()) {
if (handler.indexOf("server") == 0 && handler.indexOf(getHandlerId()) > 0
&& handler.indexOf("stop") > 0) {
return true;
}
}
}
}
return false;
}
示例2
public final boolean handleMessage(LogicalMessageContext messageContext) {
//System.out.println("LogicalMessageHandler handleMessage called");
try {
// get the LogicalMessage from our context
LogicalMessage msg = messageContext.getMessage();
// check the payload, if its an AddNumbers request, we'll intervene
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Object payload = msg.getPayload(jaxbContext);
Object value = payload;
if (payload instanceof JAXBElement) {
value = ((JAXBElement<?>)payload).getValue();
}
if (value instanceof AddNumbers) {
AddNumbers req = (AddNumbers)value;
int a = req.getArg0();
req.setArg0(a * 10);
msg.setPayload(payload, jaxbContext);
}
return true;
} catch (JAXBException ex) {
throw new ProtocolException(ex);
}
}
示例3
private boolean handlePingMessage(boolean outbound, T ctx) {
LogicalMessage msg = ctx.getMessage();
addHandlerId(msg, ctx, outbound);
if (checkServerOutBindStopHandler(outbound, ctx)) {
return false;
}
return getHandleMessageRet();
}
示例4
private void addHandlerId(LogicalMessage msg, T ctx, boolean outbound) {
Object obj = msg.getPayload(jaxbCtx);
if (obj instanceof PingResponse) {
PingResponse origResp = (PingResponse)obj;
PingResponse newResp = new PingResponse();
newResp.getHandlersInfo().addAll(origResp.getHandlersInfo());
newResp.getHandlersInfo().add(getHandlerId());
msg.setPayload(newResp, jaxbCtx);
} else if (obj instanceof Ping || obj instanceof PingWithArgs) {
getHandlerInfoList(ctx).add(getHandlerId());
}
}
示例5
public boolean handleMessage(LogicalMessageContext ctx) {
LogicalMessage msg = ctx.getMessage();
Source payload = msg.getPayload();
assertNotNull(payload);
return true;
}
示例6
public LogicalMessage getMessage() {
if(lm == null)
lm = new LogicalMessageImpl(defaultJaxbContext, packet);
return lm;
}
示例7
public LogicalMessage getMessage() {
if(lm == null)
lm = new LogicalMessageImpl(defaultJaxbContext, packet);
return lm;
}
示例8
public LogicalMessage getMessage() {
if(lm == null)
lm = new LogicalMessageImpl(defaultJaxbContext, packet);
return lm;
}
示例9
public LogicalMessage getMessage() {
if(lm == null)
lm = new LogicalMessageImpl(defaultJaxbContext, packet);
return lm;
}
示例10
public LogicalMessage getMessage() {
if(lm == null)
lm = new LogicalMessageImpl(defaultJaxbContext, packet);
return lm;
}
示例11
public LogicalMessage getMessage() {
if(lm == null)
lm = new LogicalMessageImpl(defaultJaxbContext, packet);
return lm;
}
示例12
public LogicalMessage getMessage() {
if(lm == null)
lm = new LogicalMessageImpl(defaultJaxbContext, packet);
return lm;
}
示例13
public LogicalMessage getMessage() {
if(lm == null)
lm = new LogicalMessageImpl(defaultJaxbContext, packet);
return lm;
}
示例14
public final boolean handleMessage(LogicalMessageContext messageContext) {
System.out.println("LogicalMessageHandler handleMessage called");
try {
boolean outbound = (Boolean)messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
// get the LogicalMessage from our context
//
LogicalMessage msg = messageContext.getMessage();
// check the payload, if its an AddNumbers request, we'll intervene
//
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Object payload = msg.getPayload(jaxbContext);
if (payload instanceof JAXBElement) {
payload = ((JAXBElement<?>)payload).getValue();
}
if (payload instanceof AddNumbers) {
AddNumbers req = (AddNumbers)payload;
// now, if the arguments are small, let's do the calculation here
//
int a = req.getArg0();
int b = req.getArg1();
if (isSmall(a) && isSmall(b)) {
int answer = a + b;
//System.out.printf("SmallNumberHandler addNumbers(%d, %d) == %d\n", a, b, answer);
// ok, we've done the calculation, so build the
// response and set it as the payload of the message
AddNumbersResponse resp = new AddNumbersResponse();
resp.setReturn(answer);
msg.setPayload(new ObjectFactory().createAddNumbersResponse(resp),
jaxbContext);
Source src = msg.getPayload();
msg.setPayload(src);
payload = msg.getPayload(jaxbContext);
if (payload instanceof JAXBElement) {
payload = ((JAXBElement<?>)payload).getValue();
}
AddNumbersResponse resp2 = (AddNumbersResponse)payload;
if (resp2 == resp) {
throw new WebServiceException("Shouldn't be the same object");
}
// finally, return false, indicating that request
// processing stops here and our answer will be
// returned to the client
return false;
}
}
}
return true;
} catch (JAXBException ex) {
throw new ProtocolException(ex);
}
}
示例15
public final boolean handleMessage(LogicalMessageContext messageContext) {
//System.out.println("LogicalMessageHandler handleMessage called");
try {
boolean outbound = (Boolean)messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
// get the LogicalMessage from our context
LogicalMessage msg = messageContext.getMessage();
// check the payload, if its an AddNumbers request, we'll intervene
JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
Object payload = msg.getPayload(jaxbContext);
if (payload instanceof JAXBElement) {
payload = ((JAXBElement<?>)payload).getValue();
}
if (payload instanceof AddNumbers) {
AddNumbers req = (AddNumbers)payload;
// now, if the arguments are small, let's do the calculation here
int a = req.getArg0();
int b = req.getArg1();
if (isSmall(a) && isSmall(b)) {
int answer = a + b;
//System.out.printf("SmallNumberHandler addNumbers(%d, %d) == %d\n", a, b, answer);
// ok, we've done the calculation, so build the
// response and set it as the payload of the message
AddNumbersResponse resp = new AddNumbersResponse();
resp.setReturn(answer);
msg.setPayload(new ObjectFactory().createAddNumbersResponse(resp),
jaxbContext);
Source src = msg.getPayload();
msg.setPayload(src);
payload = msg.getPayload(jaxbContext);
if (payload instanceof JAXBElement) {
payload = ((JAXBElement<?>)payload).getValue();
}
AddNumbersResponse resp2 = (AddNumbersResponse)payload;
if (resp2 == resp) {
throw new WebServiceException("Shouldn't be the same object");
}
// finally, return false, indicating that request
// processing stops here and our answer will be
// returned to the client
return false;
}
}
}
return true;
} catch (JAXBException ex) {
throw new ProtocolException(ex);
}
}
示例16
private boolean handlePingWithArgsMessage(boolean outbound, T ctx) {
LogicalMessage msg = ctx.getMessage();
Object payload = msg.getPayload(jaxbCtx);
addHandlerId(ctx.getMessage(), ctx, outbound);
boolean ret = true;
if (payload instanceof PingWithArgs) {
String arg = ((PingWithArgs)payload).getHandlersCommand();
StringTokenizer strtok = new StringTokenizer(arg, " ");
String hid = "";
String direction = "";
String command = "";
if (strtok.countTokens() >= 3) {
hid = strtok.nextToken();
direction = strtok.nextToken();
command = strtok.nextToken();
}
if (!getHandlerId().equals(hid)) {
return true;
}
if ("stop".equals(command)) {
if (!outbound && "inbound".equals(direction)) {
PingResponse resp = new PingResponse();
resp.getHandlersInfo().addAll(getHandlerInfoList(ctx));
msg.setPayload(resp, jaxbCtx);
ret = false;
} else if (outbound && "outbound".equals(direction)) {
ret = false;
}
} else if ("throw".equals(command)) {
String exceptionType = null;
String exceptionText = "HandleMessage throws exception";
if (strtok.hasMoreTokens()) {
exceptionType = strtok.nextToken();
}
if (strtok.hasMoreTokens()) {
exceptionText = strtok.nextToken();
}
if (exceptionType != null && !outbound && "inbound".equals(direction)) {
if ("RuntimeException".equals(exceptionType)) {
throw new RuntimeException(exceptionText);
} else if ("ProtocolException".equals(exceptionType)) {
throw new ProtocolException(exceptionText);
}
} else if (exceptionType != null && outbound && "outbound".equals(direction)) {
if ("RuntimeException".equals(exceptionType)) {
throw new RuntimeException(exceptionText);
} else if ("ProtocolException".equals(exceptionType)) {
throw new ProtocolException(exceptionText);
}
}
}
}
return ret;
}
示例17
@Test
public void testSOAPHandlerHandleMessageReturnTrueClient() throws Exception {
TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
public boolean handleMessage(LogicalMessageContext ctx) {
super.handleMessage(ctx);
try {
Boolean outbound = (Boolean)ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
LogicalMessage msg = ctx.getMessage();
Source source = msg.getPayload();
assertNotNull(source);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
};
TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
TestSOAPHandler soapHandler2 = new TestSOAPHandler(false);
addHandlersToChain((BindingProvider)handlerTest, handler1, handler2, soapHandler1, soapHandler2);
List<String> resp = handlerTest.ping();
assertNotNull(resp);
assertEquals("handle message was not invoked", 2, handler1.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 2, handler2.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 2, soapHandler1.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 2, soapHandler2.getHandleMessageInvoked());
assertEquals("close must be called", 1, handler1.getCloseInvoked());
assertEquals("close must be called", 1, handler2.getCloseInvoked());
assertEquals("close must be called", 1, soapHandler1.getCloseInvoked());
assertEquals("close must be called", 1, soapHandler2.getCloseInvoked());
assertTrue(soapHandler2.getInvokeOrderOfClose()
< soapHandler1.getInvokeOrderOfClose());
assertTrue(soapHandler1.getInvokeOrderOfClose()
< handler2.getInvokeOrderOfClose());
assertTrue(handler2.getInvokeOrderOfClose()
< handler1.getInvokeOrderOfClose());
// the server has encoded into the response the order in
// which the handlers have been invoked, parse it and make
// sure everything is ok expected order for inbound interceptors
String[] handlerNames = {"soapHandler4", "soapHandler3", "handler2", "handler1", "servant",
"handler1", "handler2", "soapHandler3", "soapHandler4"};
assertEquals(handlerNames.length, resp.size());
Iterator<String> iter = resp.iterator();
for (String expected : handlerNames) {
assertEquals(expected, iter.next());
}
}
示例18
public LogicalMessage getMessage() {
return new LogicalMessageImpl(this);
}
示例19
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例20
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例21
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例22
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例23
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例24
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例25
/** Gets the message from this message context
*
* @return The contained message; returns {@code null} if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例26
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例27
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例28
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();
示例29
/** Gets the message from this message context
*
* @return The contained message; returns <code>null</code> if no
* message is present in this message context
**/
public LogicalMessage getMessage();