none
Unable to get the message from Cloud to Java Application via Topic

    Question

  • Hi,
      Currently we are getting the message from Cloud via Service Bus Key in
    our Java Application.
      However as per the process, Microsoft Cloud cannot share the Service Bus
    Key and they can only provide Topic Key.

      So we tried to get the message through the Topic Key however we are
    getting the below error.

    Regards,

    Mani.

    Thursday, March 16, 2017 1:05 PM

All replies

  • Could you share the error message?

    • Marked as answer by MManik Friday, March 17, 2017 3:53 PM
    • Unmarked as answer by MManik Friday, March 17, 2017 3:53 PM
    Friday, March 17, 2017 11:30 AM
    Moderator
  • Nayana,

    Please find the error log and error message

    [2/27/17 21:00:18:050 IST] 0000003c ServiceBusCon W com.microsoft.windowsazure.services.serviceBus.implementation.ServiceBusExceptionProcessor processCatch com.sun.jersey.api.client.ClientHandlerException: com.microsoft.windowsazure.services.core.ServiceException: WRAP server returned error acquiring access_token
    Response Body: Error:Code:401:SubCode:T0:Detail:ACS50012: Authentication failed.:TraceID:0b3a23c4-f221-4244-a832-a9ff7f7ac751:TimeStamp:2017-02-27 15:30:17Z
                                     com.sun.jersey.api.client.ClientHandlerException: com.microsoft.windowsazure.services.core.ServiceException: WRAP server returned error acquiring access_token
    Response Body: Error:Code:401:SubCode:T0:Detail:ACS50012: Authentication failed.:TraceID:0b3a23c4-f221-4244-a832-a9ff7f7ac751:TimeStamp:2017-02-27 15:30:17Z
                    at com.microsoft.windowsazure.services.serviceBus.implementation.WrapFilter.getWrapToken(WrapFilter.java:55)
                    at com.microsoft.windowsazure.services.serviceBus.implementation.WrapFilter.handle(WrapFilter.java:35)
                    at com.microsoft.windowsazure.services.core.UserAgentFilter.handle(UserAgentFilter.java:62)
                    at com.sun.jersey.api.client.Client.handle(Client.java:648)
                    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
                    at com.sun.jersey.api.client.WebResource.post(WebResource.java:251)
                    at com.microsoft.windowsazure.services.serviceBus.implementation.ServiceBusRestProxy.receiveMessage(ServiceBusRestProxy.java:181)
                    at com.microsoft.windowsazure.services.serviceBus.implementation.ServiceBusRestProxy.receiveSubscriptionMessage(ServiceBusRestProxy.java:255)
                    at com.microsoft.windowsazure.services.serviceBus.implementation.ServiceBusExceptionProcessor.receiveSubscriptionMessage(ServiceBusExceptionProcessor.java:150)

                    at com.ibm.ejs.container.MessageEndpointHandler.invokeMdbMethod(MessageEndpointHandler.java:1163)
                    at com.ibm.ejs.container.MessageEndpointHandler.invoke(MessageEndpointHandler.java:842)
                    at com.sun.proxy.$Proxy201.onMessage(Unknown Source)
                    at com.ibm.ws.sib.api.jmsra.impl.JmsJcaEndpointInvokerImpl.invokeEndpoint(JmsJcaEndpointInvokerImpl.java:233)
                    at com.ibm.ws.sib.ra.inbound.impl.SibRaDispatcher.dispatch(SibRaDispatcher.java:901)
                    at com.ibm.ws.sib.ra.inbound.impl.SibRaSingleProcessListener$SibRaWork.run(SibRaSingleProcessListener.java:552)
                    at com.ibm.ejs.j2c.work.WorkProxy$RunWork.run(WorkProxy.java:257)
                    at java.security.AccessController.doPrivileged(AccessController.java:298)
                    at javax.security.auth.Subject.doAs(Subject.java:495)
                    at com.ibm.websphere.security.auth.WSSubject.doAs(WSSubject.java:132)
                    at com.ibm.ejs.j2c.work.WorkProxy$RunWork.run(WorkProxy.java:260)
                    at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:63)
                    at com.ibm.ejs.j2c.work.WorkProxy.run(WorkProxy.java:606)
                    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1700)
    Caused by: com.microsoft.windowsazure.services.core.ServiceException: WRAP server returned error acquiring access_token
    Response Body: Error:Code:401:SubCode:T0:Detail:ACS50012: Authentication failed.:TraceID:0b3a23c4-f221-4244-a832-a9ff7f7ac751:TimeStamp:2017-02-27 15:30:17Z
                    at com.microsoft.windowsazure.services.serviceBus.implementation.WrapRestProxy.wrapAccessToken(WrapRestProxy.java:56)
                    at com.microsoft.windowsazure.services.serviceBus.implementation.WrapTokenManager.getAccessToken(WrapTokenManager.java:88)
                    at com.microsoft.windowsazure.services.serviceBus.implementation.WrapFilter.getWrapToken(WrapFilter.java:51)
                    ... 25 more
    Caused by: com.sun.jersey.api.client.UniformInterfaceException: POST https://namespace-sb.accesscontrol.windows.net/WRAPv0.9 returned  a response status of 401 Unauthorized
                    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
                    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
                    at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:568)
                    at com.microsoft.windowsazure.services.serviceBus.implementation.WrapRestProxy.wrapAccessToken(WrapRestProxy.java:51)
                    ... 27 more

                      
    Friday, March 17, 2017 4:01 PM
  • Hi Mani,

    What do you mean by Topic key? You mean entity SAS?

    Can you also point the Java client you are using?

    Thanks

    Friday, March 17, 2017 4:11 PM
  • yes, it is entity SAS.

    we don't have any Java client in our Java application.

    Mani.

    Monday, March 20, 2017 9:56 AM
  • Service Bus Java client doesn't support entity level SAS. We are actively working on a new client for queues and topics. This will support entity level SAS authentication. In the meantime can you code with namespace level SAS?
    Tuesday, March 21, 2017 8:38 PM
  • It is working with namespace level SAS however going forward, the hosting team(who is creating the service bus and Topic) will not provide the namespace level SAS and they will give only Entity SAS due to security reasons.

    Kindly let me know to proceed further on this.

    Regards,

    Mani.

    Wednesday, March 22, 2017 1:33 PM
  • Do you need to go with Java? The fact is that, current Java client is outdated, that is why we don't have support for some key features on the client.

    I am accessing couple people from Messaging team to find out about your options.

    Wednesday, March 22, 2017 5:00 PM
  • we need to go Java. Kindly let me know is there any way to find the solution on this incident.

    Thursday, March 23, 2017 4:01 PM
  • Can you show me the code where you are setting SAS keys after hiding the actual key? I would like to repro this issue.
    Thursday, March 23, 2017 4:49 PM
  • I have added the code(class) in below . Kindly let me know if any thing needed .

    import

    java.io.BufferedReader;


    import

    java.io.IOException;


    import

    java.io.InputStream;


    import

    java.io.InputStreamReader;


    import

    java.security.Security;


    import

    java.util.HashMap;


    import

    java.util.Map;


    import

    com.microsoft.windowsazure.services.core.Configuration;


    import

    com.microsoft.windowsazure.services.core.ServiceException;


    import

    com.microsoft.windowsazure.services.serviceBus.ServiceBusConfiguration;


    import

    com.microsoft.windowsazure.services.serviceBus.ServiceBusContract;


    import

    com.microsoft.windowsazure.services.serviceBus.ServiceBusService;


    import

    com.microsoft.windowsazure.services.serviceBus.models.BrokeredMessage;


    import

    com.microsoft.windowsazure.services.serviceBus.models.ReceiveMessageOptions;


    import

    com.microsoft.windowsazure.services.serviceBus.models.ReceiveMode;


    import

    com.microsoft.windowsazure.services.serviceBus.models.ReceiveSubscriptionMessageResult;

     


    public

    classCloudMessageToJava

    {

    staticMap<String, Object> map= newHashMap<String,Object>();

    staticString namespace= null;

    staticString serviceBusOwner= null;

    staticString serviceBusKey= null;

    publicstaticvoidmain(String args[]) throwsException

    {

    ServiceBusContract service = getService();

    String Msg = retriveMsgFromTopic(service,".....", ".....") ; // I have hided the info. First dots represents  subscription name and second dots represents Topic name


    System.out.println(" Cloud Message is ===>"+Msg);

    }


    private

    staticServiceBusContract getService() {

    System.getProperties().put("https.proxyHost","....");

    System.getProperties().put("https.proxyPort", "...");

    Security.setProperty("ssl.SocketFactory.provider","com.ibm.jsse2.SSLSocketFactoryImpl");

    Security.setProperty("ssl.ServerSocketFactory.provider","com.ibm.jsse2.SSLServerSocketFactoryImpl");


    /*

    // I have hided the info. First dots represents ServicBus name and second dots represents ServiceBus Key. With this configuration we are able to connect

    Configuration config = ServiceBusConfiguration.configureWithWrapAuthentication("....", "owner", "....", ".servicebus.windows.net","-sb.accesscontrol.windows.net/WRAPv0.9"); 

    */


     

    Configuration config = ServiceBusConfiguration

    .configureWithWrapAuthentication("....", "owner",

    "....", ".servicebus.windows.net",

    "-sb.accesscontrol.windows.net/WRAPv0.9");  // I have hided the info. First dots represents  Topic name and second dots represents Topic Key (SAS Key)


     

    ServiceBusContract service = ServiceBusService.create(config);

    returnservice;

    }


    public

    staticString retriveMsgFromTopic(ServiceBusContract service,

    String subscriptionName, String topicName) {

    String msg = "No message found in given subscription.";

    try{

    ReceiveMessageOptions opts = ReceiveMessageOptions.DEFAULT;

    opts.setReceiveMode(ReceiveMode.PEEK_LOCK);

    //  opts.setReceiveMode(ReceiveMode.RECEIVE_AND_DELETE);


    inttime = 1;

    while(true) {

    ReceiveSubscriptionMessageResult resultSubMsg = service

    .receiveSubscriptionMessage(topicName, subscriptionName,opts);

    BrokeredMessage message = resultSubMsg.getValue();

    if(message != null&& message.getMessageId() != null) {

    System.out.println("MessageID: " + message.getMessageId());

    InputStream is = message.getBody();

    String result = getStringFromInputStream(is);

    msg = result;

    System.out.println();

    System.out.println("Custom Property: ");

    map=message.getProperties();

    for(Map.Entry<String, Object> map : message

    .getProperties().entrySet()) {

    System.out.println(map.getKey() + " "


    + map.getValue().toString());

    }

    System.out.println("Deleting this message.");

    service.deleteMessage(message);

    break;

    }

    System.out.println("Iteration Count:" + time);

    time++;

    if(time == 2)

    break;

    }

    } catch(ServiceException e) {

    e.printStackTrace();

    System.out.print("ServiceException encountered: " + e);

    msg = e.getMessage();

    } catch(Exception e) {

    e.printStackTrace();

    System.out.print("Generic exception encountered: " + e);

    e.printStackTrace();

    msg = e.getMessage();

    }

    returnmsg;

    }


    //convert InputStream to String


    privatestaticString getStringFromInputStream(InputStream is) {

    BufferedReader br = null;

    StringBuilder sb = newStringBuilder();

    String line;

    try{

    br = newBufferedReader(newInputStreamReader(is));

    while((line = br.readLine()) != null) {

    sb.append(line);

    }

    } catch(IOException e) {

    e.printStackTrace();

    } finally{

    if(br != null) {

    try{

    br.close();

    } catch(IOException e) {

    e.printStackTrace();

    }

    }

    }

    returnsb.toString();

    }

    }

     

    Friday, March 24, 2017 10:42 AM
  • First dot should be the Service Bus namespace. Can you check that please?

    Configuration config = ServiceBusConfiguration
    
    .configureWithWrapAuthentication("....", "owner",
    
    "....",  ".servicebus.windows.net",
    
    "-sb.accesscontrol.windows.net/WRAPv0.9");  // I have hided the info. First dots represents  Topic name and second dots represents Topic Key (SAS Key)
    

    Friday, March 24, 2017 4:45 PM