alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Apache CXF example source code file (TwoWayJMSImplBase.java)

This example Apache CXF source code file (TwoWayJMSImplBase.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Apache CXF tags/keywords

annotation, asynchandler, badrecordlit, badrecordlitfault, badrecordlitfault, errorcode, future, future, jmsmessageheaderstype, jmsmessageheaderstype, nosuchcodelitfault, pausefortwosecs, response, response, string, threading, threads, xml

The Apache CXF TwoWayJMSImplBase.java source code

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * 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 org.apache.cxf.systest.jms;

import java.util.concurrent.Future;

import javax.annotation.Resource;
import javax.xml.ws.AsyncHandler;
import javax.xml.ws.Response;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;

import org.apache.cxf.hello_world_jms.BadRecordLitFault;
import org.apache.cxf.hello_world_jms.HelloWorldPortType;
import org.apache.cxf.hello_world_jms.NoSuchCodeLitFault;
import org.apache.cxf.hello_world_jms.types.BadRecordLit;
import org.apache.cxf.hello_world_jms.types.ErrorCode;
import org.apache.cxf.hello_world_jms.types.NoSuchCodeLit;
import org.apache.cxf.hello_world_jms.types.TestRpcLitFaultResponse;
import org.apache.cxf.transport.jms.JMSConstants;
import org.apache.cxf.transport.jms.JMSMessageHeadersType;
import org.apache.cxf.transport.jms.JMSPropertyType;

public class TwoWayJMSImplBase implements HelloWorldPortType {

    @Resource
    protected WebServiceContext wsContext;
    public String greetMe(String me) {
        if (me.startsWith("PauseForTwoSecs")) {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                //ignore
            }
            me = me.substring("PauseForTwoSecs".length()).trim();
        }
        
        MessageContext mc = wsContext.getMessageContext();
        JMSMessageHeadersType headers =
            (JMSMessageHeadersType) mc.get(JMSConstants.JMS_SERVER_REQUEST_HEADERS);
        System.out.println("get the message headers JMSCorrelationID: " + headers.getJMSCorrelationID());
        System.out.println("Reached here :" + me);
        
        // set reply header custom property
        JMSPropertyType testProperty = new JMSPropertyType();
        testProperty.setName("Test_Prop");
        testProperty.setValue("some return value "  + me);
        
        System.out.println("found property in request headers at index: " 
                           + headers.getProperty().indexOf(testProperty));
        
        JMSMessageHeadersType responseHeaders =
            (JMSMessageHeadersType) mc.get(JMSConstants.JMS_SERVER_RESPONSE_HEADERS);
        responseHeaders.getProperty().add(testProperty);
        
        return "Hello " + me;
    }

    public String sayHi() {        
        return "Bonjour";
    }
    
    public void greetMeOneWay(String requestType) {
        System.out.println("*********  greetMeOneWay: " + requestType);
    }
    
    public TestRpcLitFaultResponse testRpcLitFault(String faultType) 
        throws BadRecordLitFault, NoSuchCodeLitFault {
        BadRecordLit badRecord = new BadRecordLit();
        badRecord.setReason("BadRecordLitFault");
        if (faultType.equals(BadRecordLitFault.class.getSimpleName())) {
            throw new BadRecordLitFault("TestBadRecordLit", badRecord);
        }
        if (faultType.equals(NoSuchCodeLitFault.class.getSimpleName())) {
            ErrorCode ec = new ErrorCode();
            ec.setMajor((short)1);
            ec.setMinor((short)1);
            NoSuchCodeLit nscl = new NoSuchCodeLit();
            nscl.setCode(ec);
            throw new NoSuchCodeLitFault("TestNoSuchCodeLit", nscl);
        }
        
        return new TestRpcLitFaultResponse();
    }

    public Response<String> greetMeAsync(String stringParam0) {
        // TODO Auto-generated method stub
        return null;
    }

    public Future<?> greetMeAsync(String stringParam0, AsyncHandler asyncHandler) {
        // TODO Auto-generated method stub
        return null;
    }

    public Response<String> sayHiAsync() {
        // TODO Auto-generated method stub
        return null;
    }

    public Future<?> sayHiAsync(AsyncHandler asyncHandler) {
        // TODO Auto-generated method stub
        return null;
    }

    public Response<TestRpcLitFaultResponse> testRpcLitFaultAsync(String in) {
        // TODO Auto-generated method stub
        return null;
    }

    public Future<?> testRpcLitFaultAsync(String in, AsyncHandler asyncHandler) {
        // TODO Auto-generated method stub
        return null;
    }

}

Other Apache CXF examples (source code examples)

Here is a short list of links related to this Apache CXF TwoWayJMSImplBase.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.